Commit dae1bdd6 authored by David Reid's avatar David Reid

Update advanced config example.

parent f4693be9
...@@ -3,22 +3,23 @@ ...@@ -3,22 +3,23 @@
#include <stdio.h> #include <stdio.h>
void on_log(mal_context* pContext, mal_device* pDevice, const char* message) void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message)
{ {
(void)pContext; (void)pContext;
(void)pDevice; (void)pDevice;
printf("mini_al: %s\n", message); printf("mini_al: [%s] %s\n", mal_log_level_to_string(logLevel), message);
} }
mal_uint32 on_send_frames_to_device(mal_device* pDevice, mal_uint32 frameCount, void* pSamples) void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
{ {
(void)pDevice; (void)pDevice;
(void)pOutput;
(void)pInput;
(void)frameCount; (void)frameCount;
(void)pSamples; return; // Just output silence for this example.
return 0; // Just output silence for this example.
} }
void on_device_stop(mal_device* pDevice) void stop_callback(mal_device* pDevice)
{ {
(void)pDevice; (void)pDevice;
printf("Device stopped\n"); printf("Device stopped\n");
...@@ -32,7 +33,8 @@ int main(int argc, char** argv) ...@@ -32,7 +33,8 @@ int main(int argc, char** argv)
// When initializing a context, you can pass in an optional configuration object that allows you to control // When initializing a context, you can pass in an optional configuration object that allows you to control
// context-level configuration. The mal_context_config_init() function will initialize a config object with // context-level configuration. The mal_context_config_init() function will initialize a config object with
// common configuration settings, but you can set other members for more detailed control. // common configuration settings, but you can set other members for more detailed control.
mal_context_config contextConfig = mal_context_config_init(on_log); mal_context_config contextConfig = mal_context_config_init();
contextConfig.logCallback = log_callback;
// The priority of the worker thread can be set with the following. The default priority is // The priority of the worker thread can be set with the following. The default priority is
// mal_thread_priority_highest. // mal_thread_priority_highest.
...@@ -91,7 +93,7 @@ int main(int argc, char** argv) ...@@ -91,7 +93,7 @@ int main(int argc, char** argv)
mal_backend_pulseaudio, mal_backend_pulseaudio,
mal_backend_alsa, mal_backend_alsa,
mal_backend_jack, mal_backend_jack,
mal_backend_aaudio mal_backend_aaudio,
mal_backend_opensl, mal_backend_opensl,
mal_backend_webaudio, mal_backend_webaudio,
mal_backend_null // Lowest priority. mal_backend_null // Lowest priority.
...@@ -131,23 +133,29 @@ int main(int argc, char** argv) ...@@ -131,23 +133,29 @@ int main(int argc, char** argv)
// Open the device. // Open the device.
// //
// Unlike context configs, device configs are required. Similar to context configs, an API exists to help you // Unlike context configs, device configs are required. Similar to context configs, an API exists to help you
// initialize a config object called mal_device_config_init(). There are an additional two helper APIs to make // initialize a config object called mal_device_config_init().
// it easy for you to initialize playback or capture configs specifically: mal_device_config_init_playback() //
// and mal_device_config_init_capture(). // When using full-duplex you may want to use a different sample format, channel count and channel map. To
mal_device_config deviceConfig = mal_device_config_init(mal_format_s16, 2, 48000, NULL, on_send_frames_to_device, NULL); // support this, the device configuration splits these into "playback" and "capture" as shown below.
mal_device_config deviceConfig = mal_device_config_init(mal_device_type_playback);
deviceConfig.playback.format = mal_format_s16;
deviceConfig.playback.channels = 2;
deviceConfig.sampleRate = 48000;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = NULL;
// Applications can specify a callback for when a device is stopped. // Applications can specify a callback for when a device is stopped.
deviceConfig.onStopCallback = on_device_stop; deviceConfig.stopCallback = stop_callback;
// Applications can request exclusive control of the device using the config variable below. Note that not all // Applications can request exclusive control of the device using the config variable below. Note that not all
// backends support this feature, so this is actually just a hint. // backends support this feature, so this is actually just a hint.
deviceConfig.shareMode = mal_share_mode_exclusive; deviceConfig.playback.shareMode = mal_share_mode_exclusive;
// mini_al allows applications to control the mapping of channels. The config below swaps the left and right // mini_al allows applications to control the mapping of channels. The config below swaps the left and right
// channels. Normally in an interleaved audio stream, the left channel comes first, but we can change that // channels. Normally in an interleaved audio stream, the left channel comes first, but we can change that
// like the following: // like the following:
deviceConfig.channelMap[0] = MAL_CHANNEL_FRONT_RIGHT; deviceConfig.playback.channelMap[0] = MAL_CHANNEL_FRONT_RIGHT;
deviceConfig.channelMap[1] = MAL_CHANNEL_FRONT_LEFT; deviceConfig.playback.channelMap[1] = MAL_CHANNEL_FRONT_LEFT;
// The ALSA backend has two ways of delivering data to and from a device: memory mapping and read/write. By // The ALSA backend has two ways of delivering data to and from a device: memory mapping and read/write. By
// default memory mapping will be used over read/write because it avoids a single point of data movement // default memory mapping will be used over read/write because it avoids a single point of data movement
...@@ -174,7 +182,7 @@ int main(int argc, char** argv) ...@@ -174,7 +182,7 @@ int main(int argc, char** argv)
#endif #endif
mal_device playbackDevice; mal_device playbackDevice;
if (mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, &playbackDevice) != MAL_SUCCESS) { if (mal_device_init(&context, &deviceConfig, &playbackDevice) != MAL_SUCCESS) {
printf("Failed to initialize playback device.\n"); printf("Failed to initialize playback device.\n");
mal_context_uninit(&context); mal_context_uninit(&context);
return -7; return -7;
......
...@@ -270,6 +270,14 @@ ...@@ -270,6 +270,14 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\examples\advanced_config.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\examples\simple_capture.c"> <ClCompile Include="..\examples\simple_capture.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
...@@ -319,12 +327,12 @@ ...@@ -319,12 +327,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_duplex.c"> <ClCompile Include="mal_duplex.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="mal_no_device_io.c"> <ClCompile Include="mal_no_device_io.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
......
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
<ClCompile Include="..\examples\simple_capture.c"> <ClCompile Include="..\examples\simple_capture.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\examples\advanced_config.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\mini_al.h"> <ClInclude Include="..\mini_al.h">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment