all repos — mgba @ 5fde0d8c35c5bc9f8164b62e2af94f8f17578520

mGBA Game Boy Advance Emulator

GBAAudioResampleNN returns how many (destination) samples were read
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jan 2014 00:43:57 -0800
commit

5fde0d8c35c5bc9f8164b62e2af94f8f17578520

parent

a79a592c1e8edabe908e15e77190b8c1fbf8d50e

2 files changed, 7 insertions(+), 4 deletions(-)

jump to
M src/gba/gba-audio.csrc/gba/gba-audio.c

@@ -420,13 +420,14 @@ GBASyncConsumeAudio(audio->p->sync);

return read; } -void GBAAudioResampleNN(struct GBAAudio* audio, float ratio, float* drift, struct GBAStereoSample* output, unsigned nSamples) { +unsigned GBAAudioResampleNN(struct GBAAudio* audio, float ratio, float* drift, struct GBAStereoSample* output, unsigned nSamples) { int32_t left[GBA_AUDIO_SAMPLES]; int32_t right[GBA_AUDIO_SAMPLES]; // toRead is in GBA samples // TODO: Do this with fixed-point math unsigned toRead = ceilf(nSamples / ratio); + unsigned totalRead = 0; while (nSamples) { unsigned currentRead = GBA_AUDIO_SAMPLES; if (currentRead > toRead) {

@@ -441,18 +442,20 @@ while (*drift >= 1.f) {

output->left = left[i]; output->right = right[i]; ++output; + ++totalRead; --nSamples; *drift -= 1.f; if (!nSamples) { - return; + return totalRead; } } } if (read < currentRead) { memset(output, 0, nSamples * sizeof(struct GBAStereoSample)); - return; + break; } } + return totalRead; } static int32_t _updateSquareChannel(struct GBAAudioSquareControl* control, int duty) {
M src/gba/gba-audio.hsrc/gba/gba-audio.h

@@ -234,7 +234,7 @@ void GBAAudioWriteFIFO(struct GBAAudio* audio, int address, uint32_t value);

void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles); unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned nSamples); -void GBAAudioResampleNN(struct GBAAudio*, float ratio, float* drift, struct GBAStereoSample* output, unsigned nSamples); +unsigned GBAAudioResampleNN(struct GBAAudio*, float ratio, float* drift, struct GBAStereoSample* output, unsigned nSamples); struct GBASerializedState; void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);