| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#define MA_NO_DECODING |
| 16 |
#define MA_NO_ENCODING |
| 17 |
#include "../miniaudio.c" |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
|
| 21 |
#ifdef __EMSCRIPTEN__ |
| 22 |
#include <emscripten.h> |
| 23 |
|
| 24 |
void main_loop__em() |
| 25 |
{ |
| 26 |
} |
| 27 |
#endif |
| 28 |
|
| 29 |
#define DEVICE_FORMAT ma_format_f32 |
| 30 |
#define DEVICE_CHANNELS 2 |
| 31 |
#define DEVICE_SAMPLE_RATE 48000 |
| 32 |
|
| 33 |
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) |
| 34 |
{ |
| 35 |
ma_waveform_read_pcm_frames((ma_waveform*)pDevice->pUserData, pOutput, frameCount, NULL); |
| 36 |
|
| 37 |
(void)pInput; |
| 38 |
} |
| 39 |
|
| 40 |
int main(int argc, char** argv) |
| 41 |
{ |
| 42 |
ma_waveform sineWave; |
| 43 |
ma_device_config deviceConfig; |
| 44 |
ma_device device; |
| 45 |
ma_waveform_config sineWaveConfig; |
| 46 |
|
| 47 |
deviceConfig = ma_device_config_init(ma_device_type_playback); |
| 48 |
deviceConfig.playback.format = DEVICE_FORMAT; |
| 49 |
deviceConfig.playback.channels = DEVICE_CHANNELS; |
| 50 |
deviceConfig.sampleRate = DEVICE_SAMPLE_RATE; |
| 51 |
deviceConfig.dataCallback = data_callback; |
| 52 |
deviceConfig.pUserData = &sineWave; |
| 53 |
|
| 54 |
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { |
| 55 |
printf("Failed to open playback device.\n"); |
| 56 |
return -4; |
| 57 |
} |
| 58 |
|
| 59 |
printf("Device Name: %s\n", device.playback.name); |
| 60 |
|
| 61 |
sineWaveConfig = ma_waveform_config_init(device.playback.format, device.playback.channels, device.sampleRate, ma_waveform_type_sine, 0.2, 220); |
| 62 |
ma_waveform_init(&sineWaveConfig, &sineWave); |
| 63 |
|
| 64 |
if (ma_device_start(&device) != MA_SUCCESS) { |
| 65 |
printf("Failed to start playback device.\n"); |
| 66 |
ma_device_uninit(&device); |
| 67 |
return -5; |
| 68 |
} |
| 69 |
|
| 70 |
#ifdef __EMSCRIPTEN__ |
| 71 |
emscripten_set_main_loop(main_loop__em, 0, 1); |
| 72 |
#else |
| 73 |
printf("Press Enter to quit...\n"); |
| 74 |
getchar(); |
| 75 |
#endif |
| 76 |
|
| 77 |
ma_device_uninit(&device); |
| 78 |
ma_waveform_uninit(&sineWave); |
| 79 |
|
| 80 |
(void)argc; |
| 81 |
(void)argv; |
| 82 |
return 0; |
| 83 |
} |