API CHANGE: Change the data callback in preparation for full-duplex.

This removes the two separate callbacks for sending and receiving data
to/from the device to a unified callback that's used for both input and
output. The new callback takes a pointer to both an input and output
buffer. When the device is opened in playback mode the input pointer
will be set to null. Likewise the output pointer will be set to null
for capture devices. Both input and output pointers will be non-null
for full-duplex devices.
This commit is contained in:
David Reid
2019-01-12 09:34:30 +10:00
parent 3badd55b32
commit 67db06350d
8 changed files with 269 additions and 105 deletions
+3 -9
View File
@@ -2232,18 +2232,16 @@ typedef struct
mal_event endOfPlaybackEvent;
} playback_test_callback_data;
mal_uint32 on_send__playback_test(mal_device* pDevice, mal_uint32 frameCount, void* pFrames)
void on_send__playback_test(mal_device* pDevice, const void* pInput, void* pOutput, mal_uint32 frameCount)
{
playback_test_callback_data* pData = (playback_test_callback_data*)pDevice->pUserData;
mal_assert(pData != NULL);
#if !defined(__EMSCRIPTEN__)
mal_uint64 framesRead = mal_decoder_read_pcm_frames(pData->pDecoder, frameCount, pFrames);
mal_uint64 framesRead = mal_decoder_read_pcm_frames(pData->pDecoder, frameCount, pOutput);
if (framesRead == 0) {
mal_event_signal(&pData->endOfPlaybackEvent);
}
return (mal_uint32)framesRead;
#else
if (pDevice->format == mal_format_f32) {
for (mal_uint32 iFrame = 0; iFrame < frameCount; ++iFrame) {
@@ -2254,10 +2252,6 @@ mal_uint32 on_send__playback_test(mal_device* pDevice, mal_uint32 frameCount, vo
((float*)pFrames)[iFrame*pDevice->channels + iChannel] = sample;
}
}
return frameCount;
} else {
return 0;
}
#endif
}
@@ -2290,7 +2284,7 @@ int do_playback_test(mal_backend backend)
printf(" Opening Device... ");
{
mal_context_config contextConfig = mal_context_config_init(on_log);
mal_device_config deviceConfig = mal_device_config_init_default_playback(on_send__playback_test, &callbackData);
mal_device_config deviceConfig = mal_device_config_init_default(on_send__playback_test, &callbackData);
deviceConfig.onStopCallback = on_stop__playback_test;
#if defined(__EMSCRIPTEN__)