| 1 |
#include "../../../miniaudio.c" |
| 2 |
#include "ma_ltrim_node.c" |
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#define DEVICE_FORMAT ma_format_f32 |
| 7 |
#define DEVICE_CHANNELS 0 |
| 8 |
#define DEVICE_SAMPLE_RATE 0 |
| 9 |
|
| 10 |
static ma_decoder g_decoder; |
| 11 |
static ma_data_source_node g_dataSupplyNode; |
| 12 |
static ma_ltrim_node g_trimNode; |
| 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 |
(void)pInput; |
| 18 |
(void)pDevice; |
| 19 |
|
| 20 |
|
| 21 |
ma_node_graph_read_pcm_frames(&g_nodeGraph, pOutput, frameCount, NULL); |
| 22 |
} |
| 23 |
|
| 24 |
int main(int argc, char** argv) |
| 25 |
{ |
| 26 |
ma_result result; |
| 27 |
ma_decoder_config decoderConfig; |
| 28 |
ma_device_config deviceConfig; |
| 29 |
ma_device device; |
| 30 |
ma_node_graph_config nodeGraphConfig; |
| 31 |
ma_ltrim_node_config trimNodeConfig; |
| 32 |
ma_data_source_node_config dataSupplyNodeConfig; |
| 33 |
|
| 34 |
if (argc < 1) { |
| 35 |
printf("No input file.\n"); |
| 36 |
return -1; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
decoderConfig = ma_decoder_config_init(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE); |
| 42 |
|
| 43 |
result = ma_decoder_init_file(argv[1], &decoderConfig, &g_decoder); |
| 44 |
if (result != MA_SUCCESS) { |
| 45 |
printf("Failed to load decoder.\n"); |
| 46 |
return -1; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
deviceConfig = ma_device_config_init(ma_device_type_playback); |
| 52 |
deviceConfig.playback.pDeviceID = NULL; |
| 53 |
deviceConfig.playback.format = g_decoder.outputFormat; |
| 54 |
deviceConfig.playback.channels = g_decoder.outputChannels; |
| 55 |
deviceConfig.sampleRate = g_decoder.outputSampleRate; |
| 56 |
deviceConfig.dataCallback = data_callback; |
| 57 |
result = ma_device_init(NULL, &deviceConfig, &device); |
| 58 |
if (result != MA_SUCCESS) { |
| 59 |
return result; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
nodeGraphConfig = ma_node_graph_config_init(device.playback.channels); |
| 65 |
|
| 66 |
result = ma_node_graph_init(&nodeGraphConfig, NULL, &g_nodeGraph); |
| 67 |
if (result != MA_SUCCESS) { |
| 68 |
printf("Failed to initialize node graph."); |
| 69 |
goto done0; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
trimNodeConfig = ma_ltrim_node_config_init(device.playback.channels, 0); |
| 75 |
|
| 76 |
result = ma_ltrim_node_init(&g_nodeGraph, &trimNodeConfig, NULL, &g_trimNode); |
| 77 |
if (result != MA_SUCCESS) { |
| 78 |
printf("Failed to initialize ltrim node."); |
| 79 |
goto done1; |
| 80 |
} |
| 81 |
|
| 82 |
ma_node_attach_output_bus(&g_trimNode, 0, ma_node_graph_get_endpoint(&g_nodeGraph), 0); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
dataSupplyNodeConfig = ma_data_source_node_config_init(&g_decoder); |
| 87 |
|
| 88 |
result = ma_data_source_node_init(&g_nodeGraph, &dataSupplyNodeConfig, NULL, &g_dataSupplyNode); |
| 89 |
if (result != MA_SUCCESS) { |
| 90 |
printf("Failed to initialize data source node."); |
| 91 |
goto done2; |
| 92 |
} |
| 93 |
|
| 94 |
ma_node_attach_output_bus(&g_dataSupplyNode, 0, &g_trimNode, 0); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
ma_device_start(&device); |
| 100 |
|
| 101 |
printf("Press Enter to quit...\n"); |
| 102 |
getchar(); |
| 103 |
|
| 104 |
|
| 105 |
ma_device_stop(&device); |
| 106 |
|
| 107 |
|
| 108 |
ma_data_source_node_uninit(&g_dataSupplyNode, NULL); |
| 109 |
done2: ma_ltrim_node_uninit(&g_trimNode, NULL); |
| 110 |
done1: ma_node_graph_uninit(&g_nodeGraph, NULL); |
| 111 |
done0: ma_device_uninit(&device); |
| 112 |
|
| 113 |
return 0; |
| 114 |
} |