This example show how a custom backend can be implemented.
@@ -293,9 +293,12 @@ backends would actually get hit. By default, the /* Support SDL on everything. */#define MA_SUPPORT_SDL
-/* Only enable SDL if it's hasn't been explicitly disabled (MA_NO_SDL) and it's supported at compile time (MA_SUPPORT_SDL). */
-#if !defined(MA_NO_SDL) && defined(MA_SUPPORT_SDL)
- #define MA_ENABLE_SDL
+/*
+Only enable SDL if it's hasn't been explicitly disabled (MA_NO_SDL) or enabled (MA_ENABLE_SDL with
+MA_ENABLE_ONLY_SPECIFIC_BACKENDS) and it's supported at compile time (MA_SUPPORT_SDL).
+*/
+#if defined(MA_SUPPORT_SDL) && !defined(MA_NO_SDL) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_SDL))
+ #define MA_HAS_SDL
#endif
@@ -331,9 +334,7 @@ backends would actually get hit. By default, the #if defined(MA_ENABLE_SDL)
- #define MA_HAS_SDL
-
+#if defined(MA_HAS_SDL)
/* SDL headers are necessary if using compile-time linking. */#ifdef MA_NO_RUNTIME_LINKING
#ifdef __has_include
@@ -587,7 +588,7 @@ ma_format ma_format_from_sdl(MA_SDL_AudioFormat format)
MA_ASSERT(pDeviceEx != NULL);
- ma_device_handle_backend_data_callback((ma_device*)pDeviceEx, pBuffer, NULL, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceEx->device.capture.internalFormat, pDeviceEx->device.capture.internalChannels));
+ ma_device_handle_backend_data_callback((ma_device*)pDeviceEx, pBuffer, NULL, (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(pDeviceEx->device.playback.internalFormat, pDeviceEx->device.playback.internalChannels));
}
staticma_result ma_device_init_internal__sdl(ma_device_ex* pDeviceEx, constma_device_config* pConfig, ma_device_descriptor* pDescriptor)
@@ -622,22 +623,11 @@ ma_format ma_format_from_sdl(MA_SDL_AudioFormat format)
Note that options 2 and 3 require knowledge of the sample rate in order to convert it to a frame count. You should try to keep the
calculation of the period size as accurate as possible, but sometimes it's just not practical so just use whatever you can.
+
+ A helper function called ma_calculate_buffer_size_in_frames_from_descriptor() is available to do all of this for you which is what
+ we'll be using here.
*/
- if (pDescriptor->periodSizeInFrames == 0) {
- if (pDescriptor->periodSizeInMilliseconds == 0) {
- /* The default period size has been requested. I don't think SDL has an API to retrieve this, so just using defaults defined by miniaudio. */
- if (pConfig->performanceProfile == ma_performance_profile_low_latency) {
- pDescriptor->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_LOW_LATENCY, pDescriptor->sampleRate);
- } else {
- pDescriptor->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(MA_DEFAULT_PERIOD_SIZE_IN_MILLISECONDS_CONSERVATIVE, pDescriptor->sampleRate);
- }
- } else {
- /* An explicit period size in milliseconds was specified. */
- pDescriptor->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_milliseconds(pDescriptor->periodSizeInMilliseconds, pDescriptor->sampleRate);
- }
- } else {
- /* Nothing to do here. An explicit period size in frames was specified. */
- }
+ pDescriptor->periodSizeInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptor, pDescriptor->sampleRate, pConfig->performanceProfile);
/* SDL wants the buffer size to be a power of 2 for some reason. */if (pDescriptor->periodSizeInFrames > 32768) {
diff --git a/docs/examples/custom_decoder.html b/docs/examples/custom_decoder.html
new file mode 100644
index 00000000..922ba4d5
--- /dev/null
+++ b/docs/examples/custom_decoder.html
@@ -0,0 +1,549 @@
+
+
+
+ miniaudio - A single file audio playback and capture library.
+
+
+
+
+
+
+
+
+
+
+
+
+
+Demonstrates how to implement a custom decoder.
+
+
+
+This example implements two custom decoders:
+
+
+
+
+
+
+
+Vorbis via libvorbis
+
+
+Opus via libopus
+
+A
+
+
+A custom decoder must implement a data source. In this example, the libvorbis data source is called
+ma_libvorbis and the Opus data source is called ma_libopus. These two objects are compatible
+with the ma_data_source APIs and can be taken straight from this example and used in real code.
+
+
+
+The custom decoding data sources (ma_libvorbis and ma_libopus in this example) are connected to
+the decoder via the decoder config (ma_decoder_config). You need to implement a vtable for each
+of your custom decoders. See ma_decoding_backend_vtable for the functions you need to implement.
+The onInitFile, onInitFileW and onInitMemory functions are optional.
Demonstrates how to load a sound file and play it back using the low-level API.
@@ -293,6 +293,7 @@ the simple_mixing example for how best to do this.
result = ma_decoder_init_file(argv[1], NULL, &decoder);
if (result != MA_SUCCESS) {
+ printf("Could not load file: %s\n", argv[1]);
return -2;
}
diff --git a/docs/examples/simple_playback_sine.html b/docs/examples/simple_playback_sine.html
index a2ecb8cf..953f6eec 100644
--- a/docs/examples/simple_playback_sine.html
+++ b/docs/examples/simple_playback_sine.html
@@ -245,7 +245,7 @@ a.doc-navigation-l4 {
When loading a decoder, miniaudio uses a trial and error technique to find the appropriate decoding backend. This can be unnecessarily inefficient if the type
-is already known. In this case you can use the _wav, _mp3, etc. varients of the aforementioned initialization APIs:
+is already known. In this case you can use encodingFormat variable in the device config to specify a specific encoding format you want to decode: