FileGameSound: fix buffer advance accounting
Change-Id: I15bb2b1e703cad955544a1151adc6a1277b077a8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3467 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
9293eadbda
commit
15de111dcf
@@ -32,17 +32,18 @@ struct _gs_media_tracker {
|
|||||||
|
|
||||||
|
|
||||||
// Local utility functions -----------------------------------------------
|
// Local utility functions -----------------------------------------------
|
||||||
|
template<typename T>
|
||||||
bool
|
bool
|
||||||
FillBuffer(_gs_ramp* ramp, uint8* data, uint8* buffer, size_t* bytes)
|
FillBuffer(_gs_ramp* ramp, T* dest, const T* src, size_t* bytes)
|
||||||
{
|
{
|
||||||
int32 samples = *bytes / sizeof(uint8);
|
size_t samples = *bytes / sizeof(T);
|
||||||
|
|
||||||
for (int32 byte = 0; byte < samples; byte++) {
|
for (size_t sample = 0; sample < samples; sample++) {
|
||||||
float gain = *ramp->value;
|
float gain = *ramp->value;
|
||||||
data[byte] = uint8(float(buffer[byte]) * gain);
|
dest[sample] = T(float(src[sample]) * gain);
|
||||||
|
|
||||||
if (ChangeRamp(ramp)) {
|
if (ChangeRamp(ramp)) {
|
||||||
*bytes = byte * sizeof(uint8);
|
*bytes = sample * sizeof(T);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,71 +52,6 @@ FillBuffer(_gs_ramp* ramp, uint8* data, uint8* buffer, size_t* bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
FillBuffer(_gs_ramp* ramp, int16* data, int16* buffer, size_t* bytes)
|
|
||||||
{
|
|
||||||
int32 samples = *bytes / sizeof(int16);
|
|
||||||
|
|
||||||
for (int32 byte = 0; byte < samples; byte++) {
|
|
||||||
float gain = *ramp->value;
|
|
||||||
data[byte] = int16(float(buffer[byte]) * gain);
|
|
||||||
|
|
||||||
if (ChangeRamp(ramp)) {
|
|
||||||
*bytes = byte * sizeof(int16);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
FillBuffer(_gs_ramp* ramp, int32* data, int32* buffer, size_t* bytes)
|
|
||||||
{
|
|
||||||
size_t byte = 0;
|
|
||||||
bool bytesAreReady = (*bytes > 0);
|
|
||||||
|
|
||||||
while (bytesAreReady) {
|
|
||||||
float gain = *ramp->value;
|
|
||||||
data[byte] = int32(float(buffer[byte]) * gain);
|
|
||||||
|
|
||||||
if (ChangeRamp(ramp)) {
|
|
||||||
*bytes = byte;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte++;
|
|
||||||
bytesAreReady = (byte >= *bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
FillBuffer(_gs_ramp* ramp, float* data, float* buffer, size_t* bytes)
|
|
||||||
{
|
|
||||||
size_t byte = 0;
|
|
||||||
bool bytesAreReady = (*bytes > 0);
|
|
||||||
|
|
||||||
while (bytesAreReady) {
|
|
||||||
float gain = *ramp->value;
|
|
||||||
data[byte] = buffer[byte] * gain;
|
|
||||||
|
|
||||||
if (ChangeRamp(ramp)) {
|
|
||||||
*bytes = byte;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte++;
|
|
||||||
bytesAreReady = (byte >= *bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// BFileGameSound -------------------------------------------------------
|
// BFileGameSound -------------------------------------------------------
|
||||||
BFileGameSound::BFileGameSound(const entry_ref* file, bool looping,
|
BFileGameSound::BFileGameSound(const entry_ref* file, bool looping,
|
||||||
BGameSoundDevice* device)
|
BGameSoundDevice* device)
|
||||||
@@ -273,25 +209,25 @@ BFileGameSound::FillBuffer(void* inBuffer, size_t inByteCount)
|
|||||||
|
|
||||||
switch(Format().format) {
|
switch(Format().format) {
|
||||||
case gs_audio_format::B_GS_U8:
|
case gs_audio_format::B_GS_U8:
|
||||||
rampDone = ::FillBuffer(fPausing,
|
rampDone = ::FillBuffer<uint8>(fPausing,
|
||||||
(uint8*)&buffer[out_offset],
|
(uint8*)&buffer[out_offset],
|
||||||
(uint8*)&fBuffer[fPlayPosition], &bytes);
|
(uint8*)&fBuffer[fPlayPosition], &bytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gs_audio_format::B_GS_S16:
|
case gs_audio_format::B_GS_S16:
|
||||||
rampDone = ::FillBuffer(fPausing,
|
rampDone = ::FillBuffer<int16>(fPausing,
|
||||||
(int16*)&buffer[out_offset],
|
(int16*)&buffer[out_offset],
|
||||||
(int16*)&fBuffer[fPlayPosition], &bytes);
|
(int16*)&fBuffer[fPlayPosition], &bytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gs_audio_format::B_GS_S32:
|
case gs_audio_format::B_GS_S32:
|
||||||
rampDone = ::FillBuffer(fPausing,
|
rampDone = ::FillBuffer<int32>(fPausing,
|
||||||
(int32*)&buffer[out_offset],
|
(int32*)&buffer[out_offset],
|
||||||
(int32*)&fBuffer[fPlayPosition], &bytes);
|
(int32*)&fBuffer[fPlayPosition], &bytes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gs_audio_format::B_GS_F:
|
case gs_audio_format::B_GS_F:
|
||||||
rampDone = ::FillBuffer(fPausing,
|
rampDone = ::FillBuffer<float>(fPausing,
|
||||||
(float*)&buffer[out_offset],
|
(float*)&buffer[out_offset],
|
||||||
(float*)&fBuffer[fPlayPosition], &bytes);
|
(float*)&fBuffer[fPlayPosition], &bytes);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user