mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-04-01 18:56:52 +08:00
Support for various sample formats (#11)
* wip : support for various sample formats * finalize support for various sample formats * adding more tests * update python bindings * add "string" header
This commit is contained in:
@@ -188,48 +188,37 @@ bool GGWave_init(
|
||||
}
|
||||
}
|
||||
|
||||
int sampleSizeBytesIn = 4;
|
||||
int sampleSizeBytesOut = 2;
|
||||
GGWave::SampleFormat sampleFormatIn = GGWAVE_SAMPLE_FORMAT_UNDEFINED;
|
||||
GGWave::SampleFormat sampleFormatOut = GGWAVE_SAMPLE_FORMAT_UNDEFINED;
|
||||
|
||||
switch (g_obtainedSpecIn.format) {
|
||||
case AUDIO_U8:
|
||||
case AUDIO_S8:
|
||||
sampleSizeBytesIn = 1;
|
||||
break;
|
||||
case AUDIO_U16SYS:
|
||||
case AUDIO_S16SYS:
|
||||
sampleSizeBytesIn = 2;
|
||||
break;
|
||||
case AUDIO_S32SYS:
|
||||
case AUDIO_F32SYS:
|
||||
sampleSizeBytesIn = 4;
|
||||
break;
|
||||
case AUDIO_U8: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_U8; break;
|
||||
case AUDIO_S8: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_I8; break;
|
||||
case AUDIO_U16SYS: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_U16; break;
|
||||
case AUDIO_S16SYS: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_I16; break;
|
||||
case AUDIO_S32SYS: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_F32; break;
|
||||
case AUDIO_F32SYS: sampleFormatIn = GGWAVE_SAMPLE_FORMAT_F32; break;
|
||||
}
|
||||
|
||||
switch (g_obtainedSpecOut.format) {
|
||||
case AUDIO_U8:
|
||||
case AUDIO_S8:
|
||||
sampleSizeBytesOut = 1;
|
||||
break;
|
||||
case AUDIO_U16SYS:
|
||||
case AUDIO_S16SYS:
|
||||
sampleSizeBytesOut = 2;
|
||||
break;
|
||||
case AUDIO_S32SYS:
|
||||
case AUDIO_F32SYS:
|
||||
sampleSizeBytesOut = 4;
|
||||
case AUDIO_U8: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_U8; break;
|
||||
case AUDIO_S8: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_I8; break;
|
||||
case AUDIO_U16SYS: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_U16; break;
|
||||
case AUDIO_S16SYS: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_I16; break;
|
||||
case AUDIO_S32SYS: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_F32; break;
|
||||
case AUDIO_F32SYS: sampleFormatOut = GGWAVE_SAMPLE_FORMAT_F32; break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reinit) {
|
||||
if (g_ggWave) delete g_ggWave;
|
||||
|
||||
g_ggWave = new GGWave(
|
||||
g_ggWave = new GGWave({
|
||||
g_obtainedSpecIn.freq,
|
||||
g_obtainedSpecOut.freq,
|
||||
GGWave::kDefaultSamplesPerFrame,
|
||||
sampleSizeBytesIn,
|
||||
sampleSizeBytesOut);
|
||||
sampleFormatIn,
|
||||
sampleFormatOut});
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -246,7 +235,7 @@ bool GGWave_mainLoop() {
|
||||
SDL_QueueAudio(g_devIdOut, data, nBytes);
|
||||
};
|
||||
|
||||
static GGWave::CBDequeueAudio CBDequeueAudio = [&](void * data, uint32_t nMaxBytes) {
|
||||
static GGWave::CBDequeueAudio cbDequeueAudio = [&](void * data, uint32_t nMaxBytes) {
|
||||
return SDL_DequeueAudio(g_devIdIn, data, nMaxBytes);
|
||||
};
|
||||
|
||||
@@ -259,7 +248,7 @@ bool GGWave_mainLoop() {
|
||||
if ((int) SDL_GetQueuedAudioSize(g_devIdOut) < g_ggWave->getSamplesPerFrame()*g_ggWave->getSampleSizeBytesOut()) {
|
||||
SDL_PauseAudioDevice(g_devIdIn, SDL_FALSE);
|
||||
if (::getTime_ms(tLastNoData, tNow) > 500.0f) {
|
||||
g_ggWave->decode(CBDequeueAudio);
|
||||
g_ggWave->decode(cbDequeueAudio);
|
||||
if ((int) SDL_GetQueuedAudioSize(g_devIdIn) > 32*g_ggWave->getSamplesPerFrame()*g_ggWave->getSampleSizeBytesIn()) {
|
||||
SDL_ClearQueuedAudio(g_devIdIn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user