Debian Codegraph @

examples/custom_decoder_engine.c

raw symbols SCIP
1 /*
2 Demonstrates how to implement a custom decoder and use it with the high level API.
3
4 This is the same as the custom_decoder example, only it's used with the high level engine API
5 rather than the low level decoding API. You can use this to add support for Opus to your games, for
6 example (via libopus).
7 */
8 #include "../miniaudio.c"
9 #include "../extras/decoders/libvorbis/miniaudio_libvorbis.c"
10 #include "../extras/decoders/libopus/miniaudio_libopus.c"
11
12 #include <stdio.h>
13
14
15 int main(int argc, char** argv)
16 {
17 ma_result result;
18 ma_resource_manager_config resourceManagerConfig;
19 ma_resource_manager resourceManager;
20 ma_engine_config engineConfig;
21 ma_engine engine;
22
23 /*
24 Add your custom backend vtables here. The order in the array defines the order of priority. The
25 vtables will be passed in to the resource manager config.
26 */
27 ma_decoding_backend_vtable* pCustomBackendVTables[] =
28 {
29 ma_decoding_backend_libvorbis,
30 ma_decoding_backend_libopus
31 };
32
33
34 if (argc < 2) {
35 printf("No input file.\n");
36 return -1;
37 }
38
39
40 /* Using custom decoding backends requires a resource manager. */
41 resourceManagerConfig = ma_resource_manager_config_init();
42 resourceManagerConfig.ppCustomDecodingBackendVTables = pCustomBackendVTables;
43 resourceManagerConfig.customDecodingBackendCount = sizeof(pCustomBackendVTables) / sizeof(pCustomBackendVTables[0]);
44 resourceManagerConfig.pCustomDecodingBackendUserData = NULL; /* <-- This will be passed in to the pUserData parameter of each function in the decoding backend vtables. */
45
46 result = ma_resource_manager_init(&resourceManagerConfig, &resourceManager);
47 if (result != MA_SUCCESS) {
48 printf("Failed to initialize resource manager.");
49 return -1;
50 }
51
52
53 /* Once we have a resource manager we can create the engine. */
54 engineConfig = ma_engine_config_init();
55 engineConfig.pResourceManager = &resourceManager;
56
57 result = ma_engine_init(&engineConfig, &engine);
58 if (result != MA_SUCCESS) {
59 printf("Failed to initialize engine.");
60 return -1;
61 }
62
63
64 /* Now we can play our sound. */
65 result = ma_engine_play_sound(&engine, argv[1], NULL);
66 if (result != MA_SUCCESS) {
67 printf("Failed to play sound.");
68 return -1;
69 }
70
71
72 printf("Press Enter to quit...");
73 getchar();
74
75 ma_engine_uninit(&engine);
76 ma_resource_manager_uninit(&resourceManager);
77
78 return 0;
79 }