diff --git a/src/kits/game/GameSoundDevice.cpp b/src/kits/game/GameSoundDevice.cpp index 717d224440..e345b05198 100644 --- a/src/kits/game/GameSoundDevice.cpp +++ b/src/kits/game/GameSoundDevice.cpp @@ -52,7 +52,7 @@ static BGameSoundDevice* sDevice = NULL; static BLocker sDeviceRefCountLock = BLocker("GameSound device lock"); -BGameSoundDevice * +BGameSoundDevice* GetDefaultDevice() { BAutolock _(sDeviceRefCountLock); @@ -81,8 +81,9 @@ ReleaseDevice() // BGameSoundDevice ------------------------------------------------------- BGameSoundDevice::BGameSoundDevice() - : fIsConnected(false), - fSoundCount(kInitSoundCount) + : + fIsConnected(false), + fSoundCount(kInitSoundCount) { fConnection = new Connection; memset(&fFormat, 0, sizeof(gs_audio_format)); @@ -111,12 +112,13 @@ BGameSoundDevice::~BGameSoundDevice() roster->StopNode(fConnection->producer, 0, true); // synchronous stop - // Ordinarily we'd stop *all* of the nodes in the chain at this point. However, - // one of the nodes is the System Mixer, and stopping the Mixer is a Bad Idea (tm). - // So, we just disconnect from it, and release our references to the nodes that - // we're using. We *are* supposed to do that even for global nodes like the Mixer. + // Ordinarily we'd stop *all* of the nodes in the chain at this point. + // However, one of the nodes is the System Mixer, and stopping the + // Mixer is a Bad Idea (tm). So, we just disconnect from it, and + // 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, - fConnection->consumer.node, fConnection->destination); + fConnection->consumer.node, fConnection->destination); roster->ReleaseNode(fConnection->producer); roster->ReleaseNode(fConnection->consumer); @@ -134,14 +136,14 @@ BGameSoundDevice::InitCheck() const } -const gs_audio_format & +const gs_audio_format& BGameSoundDevice::Format() const { return fFormat; } -const gs_audio_format & +const gs_audio_format& BGameSoundDevice::Format(gs_id sound) const { return fSounds[sound - 1]->Format(); @@ -156,10 +158,8 @@ BGameSoundDevice::SetInitError(status_t error) status_t -BGameSoundDevice::CreateBuffer(gs_id * sound, - const gs_audio_format * format, - const void * data, - int64 frames) +BGameSoundDevice::CreateBuffer(gs_id* sound, const gs_audio_format* format, + const void* data, int64 frames) { if (frames <= 0 || !sound) return B_BAD_VALUE; @@ -179,9 +179,8 @@ BGameSoundDevice::CreateBuffer(gs_id * sound, status_t -BGameSoundDevice::CreateBuffer(gs_id * sound, - const void * object, - const gs_audio_format * format) +BGameSoundDevice::CreateBuffer(gs_id* sound, const void* object, + const gs_audio_format* format) { if (!object || !sound) return B_BAD_VALUE; @@ -218,7 +217,7 @@ BGameSoundDevice::ReleaseBuffer(gs_id sound) status_t -BGameSoundDevice::Buffer(gs_id sound, gs_audio_format* format, void *& data) +BGameSoundDevice::Buffer(gs_id sound, gs_audio_format* format, void*& data) { if (!format || sound <= 0) return B_BAD_VALUE; @@ -276,8 +275,7 @@ BGameSoundDevice::IsPlaying(gs_id sound) status_t -BGameSoundDevice::GetAttributes(gs_id sound, - gs_attribute * attributes, +BGameSoundDevice::GetAttributes(gs_id sound, gs_attribute* attributes, size_t attributeCount) { if (!fSounds[sound - 1]) @@ -288,8 +286,7 @@ BGameSoundDevice::GetAttributes(gs_id sound, status_t -BGameSoundDevice::SetAttributes(gs_id sound, - gs_attribute * attributes, +BGameSoundDevice::SetAttributes(gs_id sound, gs_attribute* attributes, size_t attributeCount) { if (!fSounds[sound - 1]) @@ -306,6 +303,9 @@ BGameSoundDevice::Connect() // create your own audio mixer // 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; int32 mixer_count = 1; // for now, we only care about the first we find. status_t err = roster->GetDormantNodes(&mixer_dormant_info, @@ -314,7 +314,8 @@ BGameSoundDevice::Connect() return err; //fMixer = new media_node; - err = roster->InstantiateDormantNode(mixer_dormant_info, &fConnection->producer); + err = roster->InstantiateDormantNode(mixer_dormant_info, + &fConnection->producer); if (err != B_OK) return err; @@ -325,13 +326,15 @@ BGameSoundDevice::Connect() int32 count = 1; media_input mixerInput; - err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, &count); + err = roster->GetFreeInputsFor(fConnection->consumer, &mixerInput, 1, + &count); if (err != B_OK) return err; count = 1; media_output mixerOutput; - err = roster->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1, &count); + err = roster->GetFreeOutputsFor(fConnection->producer, &mixerOutput, 1, + &count); if (err != B_OK) return err; @@ -344,16 +347,19 @@ BGameSoundDevice::Connect() // set the producer's time source to be the "default" time source, which // the Mixer uses too. 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, - // but if we forget to do this, our mixer might not do anything at all. - BTimeSource* mixerTimeSource = roster->MakeTimeSourceFor(fConnection->producer); + // Start our mixer's time source if need be. Chances are, it won't need to + // be, but if we forget to do this, our mixer might not do anything at all. + BTimeSource* mixerTimeSource = roster->MakeTimeSourceFor( + fConnection->producer); if (!mixerTimeSource) return B_ERROR; 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) { mixerTimeSource->Release(); return err; @@ -375,7 +381,8 @@ BGameSoundDevice::Connect() fConnection->destination = mixerInput.destination; // 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); fIsConnected = true;