| 1 |
#include "../../../miniaudio.c" |
| 2 |
#include "ma_reverb_node.c" |
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#define DEVICE_FORMAT ma_format_f32 |
| 7 |
#define DEVICE_CHANNELS 1 |
| 8 |
#define DEVICE_SAMPLE_RATE 48000 |
| 9 |
|
| 10 |
static ma_audio_buffer_ref g_dataSupply; |
| 11 |
static ma_data_source_node g_dataSupplyNode; |
| 12 |
static ma_reverb_node g_reverbNode; |
| 13 |
static ma_node_graph g_nodeGraph; |
| 14 |
|
| 15 |
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) |
| 16 |
{ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
if (pDevice->capture.format != DEVICE_FORMAT || pDevice->playback.format != DEVICE_FORMAT || pDevice->capture.channels != pDevice->playback.channels) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
ma_audio_buffer_ref_set_data(&g_dataSupply, pInput, frameCount); |
| 32 |
|
| 33 |
|
| 34 |
ma_node_graph_read_pcm_frames(&g_nodeGraph, pOutput, frameCount, NULL); |
| 35 |
} |
| 36 |
|
| 37 |
int main(int argc, char** argv) |
| 38 |
{ |
| 39 |
ma_result result; |
| 40 |
ma_device_config deviceConfig; |
| 41 |
ma_device device; |
| 42 |
ma_node_graph_config nodeGraphConfig; |
| 43 |
ma_reverb_node_config reverbNodeConfig; |
| 44 |
ma_data_source_node_config dataSupplyNodeConfig; |
| 45 |
|
| 46 |
deviceConfig = ma_device_config_init(ma_device_type_duplex); |
| 47 |
deviceConfig.capture.pDeviceID = NULL; |
| 48 |
deviceConfig.capture.format = DEVICE_FORMAT; |
| 49 |
deviceConfig.capture.channels = DEVICE_CHANNELS; |
| 50 |
deviceConfig.capture.shareMode = ma_share_mode_shared; |
| 51 |
deviceConfig.playback.pDeviceID = NULL; |
| 52 |
deviceConfig.playback.format = DEVICE_FORMAT; |
| 53 |
deviceConfig.playback.channels = DEVICE_CHANNELS; |
| 54 |
deviceConfig.sampleRate = DEVICE_SAMPLE_RATE; |
| 55 |
deviceConfig.dataCallback = data_callback; |
| 56 |
result = ma_device_init(NULL, &deviceConfig, &device); |
| 57 |
if (result != MA_SUCCESS) { |
| 58 |
return result; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
nodeGraphConfig = ma_node_graph_config_init(device.capture.channels); |
| 64 |
|
| 65 |
result = ma_node_graph_init(&nodeGraphConfig, NULL, &g_nodeGraph); |
| 66 |
if (result != MA_SUCCESS) { |
| 67 |
printf("Failed to initialize node graph."); |
| 68 |
goto done0; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
reverbNodeConfig = ma_reverb_node_config_init(device.capture.channels, device.sampleRate); |
| 74 |
|
| 75 |
result = ma_reverb_node_init(&g_nodeGraph, &reverbNodeConfig, NULL, &g_reverbNode); |
| 76 |
if (result != MA_SUCCESS) { |
| 77 |
printf("Failed to initialize reverb node."); |
| 78 |
goto done1; |
| 79 |
} |
| 80 |
|
| 81 |
ma_node_attach_output_bus(&g_reverbNode, 0, ma_node_graph_get_endpoint(&g_nodeGraph), 0); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
result = ma_audio_buffer_ref_init(device.capture.format, device.capture.channels, NULL, 0, &g_dataSupply); |
| 86 |
if (result != MA_SUCCESS) { |
| 87 |
printf("Failed to initialize audio buffer for source."); |
| 88 |
goto done2; |
| 89 |
} |
| 90 |
|
| 91 |
dataSupplyNodeConfig = ma_data_source_node_config_init(&g_dataSupply); |
| 92 |
|
| 93 |
result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode); |
| 94 |
if (result != MA_SUCCESS) { |
| 95 |
printf("Failed to initialize source node."); |
| 96 |
goto done2; |
| 97 |
} |
| 98 |
|
| 99 |
ma_node_attach_output_bus(&g_dataSupplyNode, 0, &g_reverbNode, 0); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
ma_device_start(&device); |
| 105 |
|
| 106 |
printf("Press Enter to quit...\n"); |
| 107 |
getchar(); |
| 108 |
|
| 109 |
|
| 110 |
ma_device_stop(&device); |
| 111 |
|
| 112 |
|
| 113 |
ma_data_source_node_uninit(&g_dataSupplyNode, NULL); |
| 114 |
done2: ma_reverb_node_uninit(&g_reverbNode, NULL); |
| 115 |
done1: ma_node_graph_uninit(&g_nodeGraph, NULL); |
| 116 |
done0: ma_device_uninit(&device); |
| 117 |
|
| 118 |
(void)argc; |
| 119 |
(void)argv; |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |