GBAAudioResampleNN returns how many (destination) samples were read
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jan 2014 00:43:57 -0800
2 files changed,
7 insertions(+),
4 deletions(-)
M
src/gba/gba-audio.c
→
src/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.h
→
src/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);