| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include "../miniaudio.c" |
| 14 |
|
| 15 |
#include <stdio.h> |
| 16 |
|
| 17 |
#ifdef __EMSCRIPTEN__ |
| 18 |
void main_loop__em() |
| 19 |
{ |
| 20 |
} |
| 21 |
#endif |
| 22 |
|
| 23 |
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) |
| 24 |
{ |
| 25 |
|
| 26 |
if (pDevice->capture.format != pDevice->playback.format || pDevice->capture.channels != pDevice->playback.channels) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
MA_COPY_MEMORY(pOutput, pInput, frameCount * ma_get_bytes_per_frame(pDevice->capture.format, pDevice->capture.channels)); |
| 32 |
} |
| 33 |
|
| 34 |
int main(int argc, char** argv) |
| 35 |
{ |
| 36 |
ma_result result; |
| 37 |
ma_device_config deviceConfig; |
| 38 |
ma_device device; |
| 39 |
|
| 40 |
deviceConfig = ma_device_config_init(ma_device_type_duplex); |
| 41 |
deviceConfig.capture.pDeviceID = NULL; |
| 42 |
deviceConfig.capture.format = ma_format_s16; |
| 43 |
deviceConfig.capture.channels = 2; |
| 44 |
deviceConfig.capture.shareMode = ma_share_mode_shared; |
| 45 |
deviceConfig.playback.pDeviceID = NULL; |
| 46 |
deviceConfig.playback.format = ma_format_s16; |
| 47 |
deviceConfig.playback.channels = 2; |
| 48 |
deviceConfig.dataCallback = data_callback; |
| 49 |
result = ma_device_init(NULL, &deviceConfig, &device); |
| 50 |
if (result != MA_SUCCESS) { |
| 51 |
return result; |
| 52 |
} |
| 53 |
|
| 54 |
#ifdef __EMSCRIPTEN__ |
| 55 |
getchar(); |
| 56 |
#endif |
| 57 |
|
| 58 |
ma_device_start(&device); |
| 59 |
|
| 60 |
#ifdef __EMSCRIPTEN__ |
| 61 |
emscripten_set_main_loop(main_loop__em, 0, 1); |
| 62 |
#else |
| 63 |
printf("Press Enter to quit...\n"); |
| 64 |
getchar(); |
| 65 |
#endif |
| 66 |
|
| 67 |
ma_device_uninit(&device); |
| 68 |
|
| 69 |
(void)argc; |
| 70 |
(void)argv; |
| 71 |
return 0; |
| 72 |
} |