mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Update example for the decoder API.
This commit is contained in:
@@ -58,6 +58,70 @@
|
|||||||
#define MAL_IMPLEMENTATION
|
#define MAL_IMPLEMENTATION
|
||||||
#include "../mini_al.h"
|
#include "../mini_al.h"
|
||||||
|
|
||||||
|
mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pFramesOut)
|
||||||
|
{
|
||||||
|
mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData;
|
||||||
|
if (pDecoder == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (mal_uint32)mal_decoder_read(pDecoder, frameCount, pFramesOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("No input file.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mal_decoder_config decoderConfig = mal_decoder_config_init(mal_format_f32, 2, 48000);
|
||||||
|
mal_decoder decoder;
|
||||||
|
mal_result result = mal_decoder_init_file(argv[1], /*&decoderConfig*/NULL, &decoder);
|
||||||
|
if (result != MAL_SUCCESS) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mal_context context;
|
||||||
|
if (mal_context_init(NULL, 0, NULL, &context) != MAL_SUCCESS) {
|
||||||
|
printf("Failed to initialize context.\n");
|
||||||
|
mal_decoder_uninit(&decoder);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
mal_device_config deviceConfig = mal_device_config_init_playback(decoder.outputFormat, decoder.outputChannels, decoder.outputSampleRate, on_send_frames_to_device);
|
||||||
|
mal_copy_memory(&deviceConfig.channelMap, decoder.outputChannelMap, sizeof(decoder.outputChannelMap));
|
||||||
|
|
||||||
|
mal_device device;
|
||||||
|
if (mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, &decoder, &device) != MAL_SUCCESS) {
|
||||||
|
printf("Failed to initialize device.\n");
|
||||||
|
mal_context_uninit(&context);
|
||||||
|
mal_decoder_uninit(&decoder);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mal_device_start(&device) != MAL_SUCCESS) {
|
||||||
|
printf("Failed to start playback device.\n");
|
||||||
|
mal_device_uninit(&device);
|
||||||
|
mal_context_uninit(&context);
|
||||||
|
mal_decoder_uninit(&decoder);
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("Press Enter to quit...");
|
||||||
|
getchar();
|
||||||
|
|
||||||
|
mal_device_uninit(&device);
|
||||||
|
mal_context_uninit(&context);
|
||||||
|
mal_decoder_uninit(&decoder);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
mal_uint32 on_send_flac_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pSamples)
|
mal_uint32 on_send_flac_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pSamples)
|
||||||
@@ -211,3 +275,4 @@ end:;
|
|||||||
|
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user