Add simple_duplex example and remove old duplex text.

Duplex can be tested with the deviceio test.
This commit is contained in:
David Reid
2020-03-01 12:19:44 +10:00
parent 348bb43a47
commit fff4cd56c9
2 changed files with 62 additions and 160 deletions
+62
View File
@@ -0,0 +1,62 @@
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h"
#include <stdio.h>
#ifdef __EMSCRIPTEN__
void main_loop__em()
{
}
#endif
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
MA_ASSERT(pDevice->capture.format == pDevice->playback.format);
MA_ASSERT(pDevice->capture.channels == pDevice->playback.channels);
/* In this example the format and channel count are the same for both input and output which means we can just memcpy(). */
MA_COPY_MEMORY(pOutput, pInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels));
}
int main(int argc, char** argv)
{
ma_result result;
ma_device_config deviceConfig;
ma_device device;
deviceConfig = ma_device_config_init(ma_device_type_duplex);
deviceConfig.capture.pDeviceID = NULL;
deviceConfig.capture.format = ma_format_s16;
deviceConfig.capture.channels = 2;
deviceConfig.capture.shareMode = ma_share_mode_shared;
deviceConfig.playback.pDeviceID = NULL;
deviceConfig.playback.format = ma_format_s16;
deviceConfig.playback.channels = 2;
deviceConfig.dataCallback = data_callback;
result = ma_device_init(NULL, &deviceConfig, &device);
if (result != MA_SUCCESS) {
return result;
}
#ifdef __EMSCRIPTEN__
getchar();
#endif
ma_device_start(&device);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(main_loop__em, 0, 1);
#else
printf("Press Enter to quit...\n");
getchar();
#endif
ma_device_uninit(&device);
(void)argc;
(void)argv;
return 0;
}