Sound (Haiku): add support

This commit is contained in:
François Revol 2025-02-15 03:06:46 +01:00 committed by Carter Li
parent c64854804d
commit 349fdd47e4

View File

@ -2,21 +2,76 @@ extern "C"
{
#include "sound.h"
}
#include <MediaAddOn.h>
#include <MediaNode.h>
#include <MediaRoster.h>
#include <ParameterWeb.h>
const char* ffDetectSound(FF_MAYBE_UNUSED FFlist* devices /* List of FFSoundDevice */)
const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
{
BMediaRoster* roster = BMediaRoster::Roster();
media_node mediaNode;
live_node_info liveInfo;
dormant_node_info dormantInfo;
status_t status;
roster->GetAudioOutput(&mediaNode);
int32 mediaOutputCount = 0;
roster->GetAllOutputsFor(mediaNode, NULL, 0, &mediaOutputCount);
if (mediaOutputCount == 0)
if (roster->GetAudioOutput(&mediaNode) != B_OK)
return NULL;
// TODO: Implement the rest of the function
FFSoundDevice* device = (FFSoundDevice*)ffListAdd(devices);
if (roster->GetDormantNodeFor(mediaNode, &dormantInfo) == B_OK)
{
ffStrbufInitS(&device->identifier, dormantInfo.name);
}
if (roster->GetLiveNodeInfo(mediaNode, &liveInfo) == B_OK)
{
ffStrbufInitS(&device->name, liveInfo.name);
ffStrbufTrimRightSpace(&device->name);
}
ffStrbufInitF(&device->platformApi, "%s", "MediaKit");
// We'll check the Mixer actually
device->volume = (uint8_t) 100;
device->active = true;
device->main = true;
return "Not supported on this platform";
roster->ReleaseNode(mediaNode);
media_node mixer;
status = roster->GetAudioMixer(&mixer);
if (status != B_OK)
return NULL;
BParameterWeb *web;
status = roster->GetParameterWebFor(mixer, &web);
roster->ReleaseNode(mixer); // the web is all we need :-)
if (status != B_OK)
return NULL;
BContinuousParameter *gain = NULL;
BParameter *mute = NULL;
BParameter *parameter;
for (int32 index = 0; (parameter = web->ParameterAt(index)) != NULL; index++) {
// assume the mute preceding master gain control
if (!strcmp(parameter->Kind(), B_MUTE))
mute = parameter;
if (!strcmp(parameter->Kind(), B_MASTER_GAIN)) {
// Can not use dynamic_cast due to fno-rtti
//gain = dynamic_cast<BContinuousParameter *>(parameter);
gain = (BContinuousParameter *)(parameter);
break;
}
}
if (gain == NULL)
return NULL;
float volume = 0.0;
bigtime_t when;
size_t size = sizeof(volume);
gain->GetValue(&volume, &size, &when);
device->volume = (uint8_t) (100 * (volume - gain->MinValue()) / (gain->MaxValue() - gain->MinValue()));
return NULL;
}