Added Todo from #575 and fixed some code guidelines issues.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32601 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -81,7 +81,8 @@ ReleaseDevice()
|
|||||||
|
|
||||||
// BGameSoundDevice -------------------------------------------------------
|
// BGameSoundDevice -------------------------------------------------------
|
||||||
BGameSoundDevice::BGameSoundDevice()
|
BGameSoundDevice::BGameSoundDevice()
|
||||||
: fIsConnected(false),
|
:
|
||||||
|
fIsConnected(false),
|
||||||
fSoundCount(kInitSoundCount)
|
fSoundCount(kInitSoundCount)
|
||||||
{
|
{
|
||||||
fConnection = new Connection;
|
fConnection = new Connection;
|
||||||
@@ -111,10 +112,11 @@ BGameSoundDevice::~BGameSoundDevice()
|
|||||||
roster->StopNode(fConnection->producer, 0, true);
|
roster->StopNode(fConnection->producer, 0, true);
|
||||||
// synchronous stop
|
// synchronous stop
|
||||||
|
|
||||||
// Ordinarily we'd stop *all* of the nodes in the chain at this point. However,
|
// Ordinarily we'd stop *all* of the nodes in the chain at this point.
|
||||||
// one of the nodes is the System Mixer, and stopping the Mixer is a Bad Idea (tm).
|
// However, one of the nodes is the System Mixer, and stopping the
|
||||||
// So, we just disconnect from it, and release our references to the nodes that
|
// Mixer is a Bad Idea (tm). So, we just disconnect from it, and
|
||||||
// we're using. We *are* supposed to do that even for global nodes like the Mixer.
|
// release our references to the nodes that we're using. We *are*
|
||||||
|
// supposed to do that even for global nodes like the Mixer.
|
||||||
roster->Disconnect(fConnection->producer.node, fConnection->source,
|
roster->Disconnect(fConnection->producer.node, fConnection->source,
|
||||||
fConnection->consumer.node, fConnection->destination);
|
fConnection->consumer.node, fConnection->destination);
|
||||||
|
|
||||||
@@ -156,10 +158,8 @@ BGameSoundDevice::SetInitError(status_t error)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::CreateBuffer(gs_id * sound,
|
BGameSoundDevice::CreateBuffer(gs_id* sound, const gs_audio_format* format,
|
||||||
const gs_audio_format * format,
|
const void* data, int64 frames)
|
||||||
const void * data,
|
|
||||||
int64 frames)
|
|
||||||
{
|
{
|
||||||
if (frames <= 0 || !sound)
|
if (frames <= 0 || !sound)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
@@ -179,8 +179,7 @@ BGameSoundDevice::CreateBuffer(gs_id * sound,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::CreateBuffer(gs_id * sound,
|
BGameSoundDevice::CreateBuffer(gs_id* sound, const void* object,
|
||||||
const void * object,
|
|
||||||
const gs_audio_format* format)
|
const gs_audio_format* format)
|
||||||
{
|
{
|
||||||
if (!object || !sound)
|
if (!object || !sound)
|
||||||
@@ -276,8 +275,7 @@ BGameSoundDevice::IsPlaying(gs_id sound)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::GetAttributes(gs_id sound,
|
BGameSoundDevice::GetAttributes(gs_id sound, gs_attribute* attributes,
|
||||||
gs_attribute * attributes,
|
|
||||||
size_t attributeCount)
|
size_t attributeCount)
|
||||||
{
|
{
|
||||||
if (!fSounds[sound - 1])
|
if (!fSounds[sound - 1])
|
||||||
@@ -288,8 +286,7 @@ BGameSoundDevice::GetAttributes(gs_id sound,
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BGameSoundDevice::SetAttributes(gs_id sound,
|
BGameSoundDevice::SetAttributes(gs_id sound, gs_attribute* attributes,
|
||||||
gs_attribute * attributes,
|
|
||||||
size_t attributeCount)
|
size_t attributeCount)
|
||||||
{
|
{
|
||||||
if (!fSounds[sound - 1])
|
if (!fSounds[sound - 1])
|
||||||
@@ -306,6 +303,9 @@ BGameSoundDevice::Connect()
|
|||||||
|
|
||||||
// create your own audio mixer
|
// create your own audio mixer
|
||||||
// TODO: Don't do this!!! See bug #575
|
// TODO: Don't do this!!! See bug #575
|
||||||
|
// from #575.
|
||||||
|
// marcusoverhagen : tries to instantiate a new audio mixer, which is bad.
|
||||||
|
// It should use the system mixer.
|
||||||
dormant_node_info mixer_dormant_info;
|
dormant_node_info mixer_dormant_info;
|
||||||
int32 mixer_count = 1; // for now, we only care about the first we find.
|
int32 mixer_count = 1; // for now, we only care about the first we find.
|
||||||
status_t err = roster->GetDormantNodes(&mixer_dormant_info,
|
status_t err = roster->GetDormantNodes(&mixer_dormant_info,
|
||||||
@@ -314,7 +314,8 @@ BGameSoundDevice::Connect()
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
//fMixer = new media_node;
|
//fMixer = new media_node;
|
||||||
err = roster->InstantiateDormantNode(mixer_dormant_info, &fConnection->producer);
|
err = roster->InstantiateDormantNode(mixer_dormant_info,
|
||||||
|
&fConnection->producer);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -325,13 +326,15 @@ BGameSoundDevice::Connect()
|
|||||||
|
|
||||||
int32 count = 1;
|
int32 count = 1;
|
||||||
media_input mixerInput;
|
media_input mixerInput;
|
||||||
err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count);
|
err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1,
|
||||||
|
&count);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
media_output mixerOutput;
|
media_output mixerOutput;
|
||||||
err = roster->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1, &count);
|
err = roster->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1,
|
||||||
|
&count);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -344,16 +347,19 @@ BGameSoundDevice::Connect()
|
|||||||
// set the producer's time source to be the "default" time source, which
|
// set the producer's time source to be the "default" time source, which
|
||||||
// the Mixer uses too.
|
// the Mixer uses too.
|
||||||
roster->GetTimeSource(&fConnection->timeSource);
|
roster->GetTimeSource(&fConnection->timeSource);
|
||||||
roster->SetTimeSourceFor(fConnection->producer.node, fConnection->timeSource.node);
|
roster->SetTimeSourceFor(fConnection->producer.node,
|
||||||
|
fConnection->timeSource.node);
|
||||||
|
|
||||||
// Start our mixer's time source if need be. Chances are, it won't need to be,
|
// Start our mixer's time source if need be. Chances are, it won't need to
|
||||||
// but if we forget to do this, our mixer might not do anything at all.
|
// be, but if we forget to do this, our mixer might not do anything at all.
|
||||||
BTimeSource* mixerTimeSource = roster->MakeTimeSourceFor(fConnection->producer);
|
BTimeSource* mixerTimeSource = roster->MakeTimeSourceFor(
|
||||||
|
fConnection->producer);
|
||||||
if (!mixerTimeSource)
|
if (!mixerTimeSource)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (!mixerTimeSource->IsRunning()) {
|
if (!mixerTimeSource->IsRunning()) {
|
||||||
status_t err = roster->StartNode(mixerTimeSource->Node(), BTimeSource::RealTime());
|
status_t err = roster->StartNode(mixerTimeSource->Node(),
|
||||||
|
BTimeSource::RealTime());
|
||||||
if (err != B_OK) {
|
if (err != B_OK) {
|
||||||
mixerTimeSource->Release();
|
mixerTimeSource->Release();
|
||||||
return err;
|
return err;
|
||||||
@@ -375,7 +381,8 @@ BGameSoundDevice::Connect()
|
|||||||
fConnection->destination = mixerInput.destination;
|
fConnection->destination = mixerInput.destination;
|
||||||
|
|
||||||
// Set an appropriate run mode for the producer
|
// Set an appropriate run mode for the producer
|
||||||
roster->SetRunModeNode(fConnection->producer, BMediaNode::B_INCREASE_LATENCY);
|
roster->SetRunModeNode(fConnection->producer,
|
||||||
|
BMediaNode::B_INCREASE_LATENCY);
|
||||||
|
|
||||||
media_to_gs_format(&fFormat, &format.u.raw_audio);
|
media_to_gs_format(&fFormat, &format.u.raw_audio);
|
||||||
fIsConnected = true;
|
fIsConnected = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user