Skip to content

Commit 5a665ff

Browse files
committed
Sound (Haiku): add support
1 parent 48bb1ae commit 5a665ff

File tree

1 file changed

+62
-6
lines changed

1 file changed

+62
-6
lines changed

src/detection/sound/sound_haiku.cpp

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,77 @@ extern "C"
22
{
33
#include "sound.h"
44
}
5+
#include <MediaAddOn.h>
6+
#include <MediaNode.h>
57
#include <MediaRoster.h>
8+
#include <ParameterWeb.h>
69

710
const char* ffDetectSound(FF_MAYBE_UNUSED FFlist* devices /* List of FFSoundDevice */)
811
{
912
BMediaRoster* roster = BMediaRoster::Roster();
1013
media_node mediaNode;
14+
live_node_info liveInfo;
15+
dormant_node_info dormantInfo;
16+
status_t status;
1117

12-
roster->GetAudioOutput(&mediaNode);
13-
14-
int32 mediaOutputCount = 0;
15-
roster->GetAllOutputsFor(mediaNode, NULL, 0, &mediaOutputCount);
16-
if (mediaOutputCount == 0)
18+
if (roster->GetAudioOutput(&mediaNode) != B_OK)
1719
return NULL;
1820

1921
// TODO: Implement the rest of the function
22+
FFSoundDevice* device = (FFSoundDevice*)ffListAdd(devices);
23+
if (roster->GetDormantNodeFor(mediaNode, &dormantInfo) == B_OK)
24+
{
25+
ffStrbufInitS(&device->identifier, dormantInfo.name);
26+
}
27+
if (roster->GetLiveNodeInfo(mediaNode, &liveInfo) == B_OK)
28+
{
29+
ffStrbufInitS(&device->name, liveInfo.name);
30+
ffStrbufTrimRightSpace(&device->name);
31+
}
32+
ffStrbufInitF(&device->platformApi, "%s", "MediaKit");
33+
// We'll check the Mixer actually
34+
device->volume = (uint8_t) 100;
35+
device->active = true;
36+
device->main = true;
37+
38+
roster->ReleaseNode(mediaNode);
39+
40+
media_node mixer;
41+
status = roster->GetAudioMixer(&mixer);
42+
if (status != B_OK)
43+
return NULL;
44+
45+
BParameterWeb *web;
46+
status = roster->GetParameterWebFor(mixer, &web);
47+
roster->ReleaseNode(mixer); // the web is all we need :-)
48+
if (status != B_OK)
49+
return NULL;
50+
51+
BContinuousParameter *gain = NULL;
52+
BParameter *mute = NULL;
53+
BParameter *parameter;
54+
for (int32 index = 0; (parameter = web->ParameterAt(index)) != NULL; index++) {
55+
// assume the mute preceeding master gain control
56+
if (!strcmp(parameter->Kind(), B_MUTE))
57+
mute = parameter;
58+
59+
if (!strcmp(parameter->Kind(), B_MASTER_GAIN)) {
60+
// Can not use dynamic_cast due to fno-rtti
61+
//gain = dynamic_cast<BContinuousParameter *>(parameter);
62+
gain = (BContinuousParameter *)(parameter);
63+
break;
64+
}
65+
}
66+
67+
if (gain == NULL)
68+
return NULL;
69+
70+
float volume = 0.0;
71+
bigtime_t when;
72+
size_t size = sizeof(volume);
73+
gain->GetValue(&volume, &size, &when);
74+
75+
device->volume = (uint8_t) (100 * (volume - gain->MinValue()) / (gain->MaxValue() - gain->MinValue()));
2076

21-
return "Not supported on this platform";
77+
return NULL;
2278
}

0 commit comments

Comments
 (0)