diff --git a/src/kits/game/GameSoundBuffer.cpp b/src/kits/game/GameSoundBuffer.cpp index 51f7e45b2f..a99b2a5e6e 100644 --- a/src/kits/game/GameSoundBuffer.cpp +++ b/src/kits/game/GameSoundBuffer.cpp @@ -39,33 +39,39 @@ #include "StreamingGameSound.h" #include "GSUtility.h" + // Sound Buffer Utility functions ---------------------------------------- -inline void ApplyMod(uint8 * data, uint8 * buffer, int64 index, float gain, float * pan) +inline void +ApplyMod(uint8 * data, uint8 * buffer, int64 index, float gain, float * pan) { data[index*2] += uint8(float(buffer[index*2]) * gain * pan[0]); data[index*2+1] += uint8(float(buffer[index*2+1]) * gain * pan[1]); } -inline void ApplyMod(int16 * data, int16 * buffer, int32 index, float gain, float * pan) +inline void +ApplyMod(int16 * data, int16 * buffer, int32 index, float gain, float * pan) { data[index*2] = int16(float(buffer[index*2]) * gain * pan[0]); data[index*2+1] = int16(float(buffer[index*2+1]) * gain * pan[1]); } -inline void ApplyMod(int32 * data, int32 * buffer, int32 index, float gain, float * pan) +inline void +ApplyMod(int32 * data, int32 * buffer, int32 index, float gain, float * pan) { data[index*2] += int32(float(buffer[index*2]) * gain * pan[0]); data[index*2+1] += int32(float(buffer[index*2+1]) * gain * pan[1]); } -inline void ApplyMod(float * data, float * buffer, int32 index, float gain, float * pan) +inline void +ApplyMod(float * data, float * buffer, int32 index, float gain, float * pan) { data[index*2] += buffer[index*2] * gain * pan[0]; data[index*2+1] += buffer[index*2+1] * gain * pan[1]; } + // GameSoundBuffer ------------------------------------------------------- GameSoundBuffer::GameSoundBuffer(const gs_audio_format * format) @@ -352,6 +358,7 @@ GameSoundBuffer::Reset() fPan = 0.0; fPanLeft = 1.0; fPanRight = 1.0; + delete fPanRamp; fPanRamp = NULL; @@ -430,13 +437,14 @@ GameSoundBuffer::StartPlaying() // make sure we give the producer enough time to run buffers through // the node chain, otherwise it'll start up already late bigtime_t latency = 0; - roster->GetLatencyFor(fConnection->producer, &latency); - roster->StartNode(fConnection->producer, source->Now() + latency); + status_t status = roster->GetLatencyFor(fConnection->producer, &latency); + if (status == B_OK) + status = roster->StartNode(fConnection->producer, source->Now() + latency); source->Release(); fIsPlaying = true; - return B_OK; + return status; } diff --git a/src/kits/game/GameSoundDevice.cpp b/src/kits/game/GameSoundDevice.cpp index 34174647e2..abf9158a13 100644 --- a/src/kits/game/GameSoundDevice.cpp +++ b/src/kits/game/GameSoundDevice.cpp @@ -219,7 +219,11 @@ BGameSoundDevice::Buffer(gs_id sound, return B_BAD_VALUE; memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format)); - + + // TODO: This is broken!!! + // here we leak the memory allocated by malloc, since data + // is not a reference nor a pointer to a pointer. + // The caller will never have the chance to access the allocated memory. if (fSounds[sound-1]->Data()) { data = malloc(format->buffer_size); memcpy(data, fSounds[sound-1]->Data(), format->buffer_size); diff --git a/src/kits/game/SimpleGameSound.cpp b/src/kits/game/SimpleGameSound.cpp index 737572f486..2b3c454ca8 100644 --- a/src/kits/game/SimpleGameSound.cpp +++ b/src/kits/game/SimpleGameSound.cpp @@ -31,8 +31,7 @@ BSimpleGameSound::BSimpleGameSound(const entry_ref *inFile, BGameSoundDevice *de BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device) : BGameSound(device) { - if (InitCheck() == B_OK) - { + if (InitCheck() == B_OK) { entry_ref file; if (get_ref_for_path(inFile, &file) != B_OK) @@ -126,6 +125,7 @@ BSimpleGameSound::IsLooping() const return bool(attribute.value); } + status_t BSimpleGameSound::Init(const entry_ref* inFile) { @@ -148,7 +148,8 @@ BSimpleGameSound::Init(const entry_ref* inFile) mformat.type = B_MEDIA_RAW_AUDIO; // mformat.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN; status_t error = audioStream->DecodedFormat(&mformat); - if (error != B_OK) return error; + if (error != B_OK) + return error; memset(&gsformat, 0, sizeof(gs_audio_format)); media_to_gs_format(&gsformat, &mformat.u.raw_audio);