Added a TODO explaining why BGameSoundDevice::Buffer() is broken. Small style changes
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27720 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,34 +39,40 @@
|
|||||||
#include "StreamingGameSound.h"
|
#include "StreamingGameSound.h"
|
||||||
#include "GSUtility.h"
|
#include "GSUtility.h"
|
||||||
|
|
||||||
|
|
||||||
// Sound Buffer Utility functions ----------------------------------------
|
// 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] += uint8(float(buffer[index*2]) * gain * pan[0]);
|
||||||
data[index*2+1] += uint8(float(buffer[index*2+1]) * gain * pan[1]);
|
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] = int16(float(buffer[index*2]) * gain * pan[0]);
|
||||||
data[index*2+1] = int16(float(buffer[index*2+1]) * gain * pan[1]);
|
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] += int32(float(buffer[index*2]) * gain * pan[0]);
|
||||||
data[index*2+1] += int32(float(buffer[index*2+1]) * gain * pan[1]);
|
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] += buffer[index*2] * gain * pan[0];
|
||||||
data[index*2+1] += buffer[index*2+1] * gain * pan[1];
|
data[index*2+1] += buffer[index*2+1] * gain * pan[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GameSoundBuffer -------------------------------------------------------
|
// GameSoundBuffer -------------------------------------------------------
|
||||||
GameSoundBuffer::GameSoundBuffer(const gs_audio_format * format)
|
GameSoundBuffer::GameSoundBuffer(const gs_audio_format * format)
|
||||||
: fLooping(false),
|
: fLooping(false),
|
||||||
@@ -352,6 +358,7 @@ GameSoundBuffer::Reset()
|
|||||||
fPan = 0.0;
|
fPan = 0.0;
|
||||||
fPanLeft = 1.0;
|
fPanLeft = 1.0;
|
||||||
fPanRight = 1.0;
|
fPanRight = 1.0;
|
||||||
|
|
||||||
delete fPanRamp;
|
delete fPanRamp;
|
||||||
fPanRamp = NULL;
|
fPanRamp = NULL;
|
||||||
|
|
||||||
@@ -430,13 +437,14 @@ GameSoundBuffer::StartPlaying()
|
|||||||
// make sure we give the producer enough time to run buffers through
|
// make sure we give the producer enough time to run buffers through
|
||||||
// the node chain, otherwise it'll start up already late
|
// the node chain, otherwise it'll start up already late
|
||||||
bigtime_t latency = 0;
|
bigtime_t latency = 0;
|
||||||
roster->GetLatencyFor(fConnection->producer, &latency);
|
status_t status = roster->GetLatencyFor(fConnection->producer, &latency);
|
||||||
roster->StartNode(fConnection->producer, source->Now() + latency);
|
if (status == B_OK)
|
||||||
|
status = roster->StartNode(fConnection->producer, source->Now() + latency);
|
||||||
source->Release();
|
source->Release();
|
||||||
|
|
||||||
fIsPlaying = true;
|
fIsPlaying = true;
|
||||||
|
|
||||||
return B_OK;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,10 @@ BGameSoundDevice::Buffer(gs_id sound,
|
|||||||
|
|
||||||
memcpy(format, &fSounds[sound-1]->Format(), sizeof(gs_audio_format));
|
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()) {
|
if (fSounds[sound-1]->Data()) {
|
||||||
data = malloc(format->buffer_size);
|
data = malloc(format->buffer_size);
|
||||||
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
memcpy(data, fSounds[sound-1]->Data(), format->buffer_size);
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ BSimpleGameSound::BSimpleGameSound(const entry_ref *inFile, BGameSoundDevice *de
|
|||||||
BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device)
|
BSimpleGameSound::BSimpleGameSound(const char *inFile, BGameSoundDevice *device)
|
||||||
: BGameSound(device)
|
: BGameSound(device)
|
||||||
{
|
{
|
||||||
if (InitCheck() == B_OK)
|
if (InitCheck() == B_OK) {
|
||||||
{
|
|
||||||
entry_ref file;
|
entry_ref file;
|
||||||
|
|
||||||
if (get_ref_for_path(inFile, &file) != B_OK)
|
if (get_ref_for_path(inFile, &file) != B_OK)
|
||||||
@@ -126,6 +125,7 @@ BSimpleGameSound::IsLooping() const
|
|||||||
return bool(attribute.value);
|
return bool(attribute.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BSimpleGameSound::Init(const entry_ref* inFile)
|
BSimpleGameSound::Init(const entry_ref* inFile)
|
||||||
{
|
{
|
||||||
@@ -148,7 +148,8 @@ BSimpleGameSound::Init(const entry_ref* inFile)
|
|||||||
mformat.type = B_MEDIA_RAW_AUDIO;
|
mformat.type = B_MEDIA_RAW_AUDIO;
|
||||||
// mformat.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
// mformat.u.raw_audio.byte_order = (B_HOST_IS_BENDIAN) ? B_MEDIA_BIG_ENDIAN : B_MEDIA_LITTLE_ENDIAN;
|
||||||
status_t error = audioStream->DecodedFormat(&mformat);
|
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));
|
memset(&gsformat, 0, sizeof(gs_audio_format));
|
||||||
media_to_gs_format(&gsformat, &mformat.u.raw_audio);
|
media_to_gs_format(&gsformat, &mformat.u.raw_audio);
|
||||||
|
|||||||
Reference in New Issue
Block a user