mirror of https://github.com/mgba-emu/mgba.git
GBAAudioResampleNN returns how many (destination) samples were read
This commit is contained in:
parent
a79a592c1e
commit
5fde0d8c35
|
@ -420,13 +420,14 @@ unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned
|
||||||
return read;
|
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 left[GBA_AUDIO_SAMPLES];
|
||||||
int32_t right[GBA_AUDIO_SAMPLES];
|
int32_t right[GBA_AUDIO_SAMPLES];
|
||||||
|
|
||||||
// toRead is in GBA samples
|
// toRead is in GBA samples
|
||||||
// TODO: Do this with fixed-point math
|
// TODO: Do this with fixed-point math
|
||||||
unsigned toRead = ceilf(nSamples / ratio);
|
unsigned toRead = ceilf(nSamples / ratio);
|
||||||
|
unsigned totalRead = 0;
|
||||||
while (nSamples) {
|
while (nSamples) {
|
||||||
unsigned currentRead = GBA_AUDIO_SAMPLES;
|
unsigned currentRead = GBA_AUDIO_SAMPLES;
|
||||||
if (currentRead > toRead) {
|
if (currentRead > toRead) {
|
||||||
|
@ -441,18 +442,20 @@ void GBAAudioResampleNN(struct GBAAudio* audio, float ratio, float* drift, struc
|
||||||
output->left = left[i];
|
output->left = left[i];
|
||||||
output->right = right[i];
|
output->right = right[i];
|
||||||
++output;
|
++output;
|
||||||
|
++totalRead;
|
||||||
--nSamples;
|
--nSamples;
|
||||||
*drift -= 1.f;
|
*drift -= 1.f;
|
||||||
if (!nSamples) {
|
if (!nSamples) {
|
||||||
return;
|
return totalRead;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (read < currentRead) {
|
if (read < currentRead) {
|
||||||
memset(output, 0, nSamples * sizeof(struct GBAStereoSample));
|
memset(output, 0, nSamples * sizeof(struct GBAStereoSample));
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return totalRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t _updateSquareChannel(struct GBAAudioSquareControl* control, int duty) {
|
static int32_t _updateSquareChannel(struct GBAAudioSquareControl* control, int duty) {
|
||||||
|
|
|
@ -234,7 +234,7 @@ void GBAAudioWriteFIFO(struct GBAAudio* audio, int address, uint32_t value);
|
||||||
void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles);
|
void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId, int32_t cycles);
|
||||||
|
|
||||||
unsigned GBAAudioCopy(struct GBAAudio* audio, void* left, void* right, unsigned nSamples);
|
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;
|
struct GBASerializedState;
|
||||||
void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);
|
void GBAAudioSerialize(const struct GBAAudio* audio, struct GBASerializedState* state);
|
||||||
|
|
Loading…
Reference in New Issue