(DSound) Create dsound_set_wavefmt

This commit is contained in:
twinaphex 2020-01-05 17:16:55 +01:00
parent bdc866d6d5
commit fa2a748631

View File

@ -328,6 +328,19 @@ static BOOL CALLBACK enumerate_cb(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOI
return TRUE; return TRUE;
} }
static void dsound_set_wavefmt(WAVEFORMATEX *wfx,
unsigned channels, unsigned samplerate)
{
wfx->wFormatTag = WAVE_FORMAT_PCM;
wfx->nBlockAlign = channels * sizeof(int16_t);
wfx->wBitsPerSample = 16;
wfx->nChannels = channels;
wfx->nSamplesPerSec = samplerate;
wfx->nAvgBytesPerSec = wfx->nSamplesPerSec * wfx->nBlockAlign;
wfx->cbSize = 0;
}
static void *dsound_init(const char *dev, unsigned rate, unsigned latency, static void *dsound_init(const char *dev, unsigned rate, unsigned latency,
unsigned block_frames, unsigned block_frames,
unsigned *new_rate) unsigned *new_rate)
@ -390,12 +403,7 @@ static void *dsound_init(const char *dev, unsigned rate, unsigned latency,
goto error; goto error;
#endif #endif
wfx.wFormatTag = WAVE_FORMAT_PCM; dsound_set_wavefmt(&wfx, 2, rate);
wfx.nChannels = 2;
wfx.nSamplesPerSec = rate;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = 2 * sizeof(int16_t);
wfx.nAvgBytesPerSec = rate * 2 * sizeof(int16_t);
ds->buffer_size = (latency * wfx.nAvgBytesPerSec) / 1000; ds->buffer_size = (latency * wfx.nAvgBytesPerSec) / 1000;
ds->buffer_size /= CHUNK_SIZE; ds->buffer_size /= CHUNK_SIZE;