mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
"mal_" to "ma_".
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ To compile these examples, cd into the "build" directory and run the applicable
|
||||
will be placed in the "bin" directory.
|
||||
|
||||
cd build
|
||||
./mal_build_examples_linux
|
||||
./ma_build_examples_linux
|
||||
|
||||
Then you can run executables like this:
|
||||
|
||||
|
||||
+49
-49
@@ -3,14 +3,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void log_callback(mal_context* pContext, mal_device* pDevice, mal_uint32 logLevel, const char* message)
|
||||
void log_callback(ma_context* pContext, ma_device* pDevice, ma_uint32 logLevel, const char* message)
|
||||
{
|
||||
(void)pContext;
|
||||
(void)pDevice;
|
||||
printf("miniaudio: [%s] %s\n", mal_log_level_to_string(logLevel), message);
|
||||
printf("miniaudio: [%s] %s\n", ma_log_level_to_string(logLevel), message);
|
||||
}
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pDevice;
|
||||
(void)pOutput;
|
||||
@@ -19,7 +19,7 @@ void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_u
|
||||
return; // Just output silence for this example.
|
||||
}
|
||||
|
||||
void stop_callback(mal_device* pDevice)
|
||||
void stop_callback(ma_device* pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
printf("Device stopped\n");
|
||||
@@ -31,14 +31,14 @@ int main(int argc, char** argv)
|
||||
(void)argv;
|
||||
|
||||
// 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 ma_context_config_init() function will initialize a config object with
|
||||
// common configuration settings, but you can set other members for more detailed control.
|
||||
mal_context_config contextConfig = mal_context_config_init();
|
||||
ma_context_config contextConfig = ma_context_config_init();
|
||||
contextConfig.logCallback = log_callback;
|
||||
|
||||
// The priority of the worker thread can be set with the following. The default priority is
|
||||
// mal_thread_priority_highest.
|
||||
contextConfig.threadPriority = mal_thread_priority_normal;
|
||||
// ma_thread_priority_highest.
|
||||
contextConfig.threadPriority = ma_thread_priority_normal;
|
||||
|
||||
|
||||
// PulseAudio
|
||||
@@ -80,52 +80,52 @@ int main(int argc, char** argv)
|
||||
|
||||
|
||||
// The prioritization of backends can be controlled by the application. You need only specify the backends
|
||||
// you care about. If the context cannot be initialized for any of the specified backends mal_context_init()
|
||||
// you care about. If the context cannot be initialized for any of the specified backends ma_context_init()
|
||||
// will fail.
|
||||
mal_backend backends[] = {
|
||||
mal_backend_wasapi, // Higest priority.
|
||||
mal_backend_dsound,
|
||||
mal_backend_winmm,
|
||||
mal_backend_coreaudio,
|
||||
mal_backend_sndio,
|
||||
mal_backend_audio4,
|
||||
mal_backend_oss,
|
||||
mal_backend_pulseaudio,
|
||||
mal_backend_alsa,
|
||||
mal_backend_jack,
|
||||
mal_backend_aaudio,
|
||||
mal_backend_opensl,
|
||||
mal_backend_webaudio,
|
||||
mal_backend_null // Lowest priority.
|
||||
ma_backend backends[] = {
|
||||
ma_backend_wasapi, // Higest priority.
|
||||
ma_backend_dsound,
|
||||
ma_backend_winmm,
|
||||
ma_backend_coreaudio,
|
||||
ma_backend_sndio,
|
||||
ma_backend_audio4,
|
||||
ma_backend_oss,
|
||||
ma_backend_pulseaudio,
|
||||
ma_backend_alsa,
|
||||
ma_backend_jack,
|
||||
ma_backend_aaudio,
|
||||
ma_backend_opensl,
|
||||
ma_backend_webaudio,
|
||||
ma_backend_null // Lowest priority.
|
||||
};
|
||||
|
||||
mal_context context;
|
||||
if (mal_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) {
|
||||
ma_context context;
|
||||
if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), &contextConfig, &context) != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
// Enumerate devices.
|
||||
mal_device_info* pPlaybackDeviceInfos;
|
||||
mal_uint32 playbackDeviceCount;
|
||||
mal_device_info* pCaptureDeviceInfos;
|
||||
mal_uint32 captureDeviceCount;
|
||||
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_device_info* pCaptureDeviceInfos;
|
||||
ma_uint32 captureDeviceCount;
|
||||
ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to retrieve device information.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Playback Devices (%d)\n", playbackDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
printf("Capture Devices (%d)\n", captureDeviceCount);
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
@@ -133,12 +133,12 @@ int main(int argc, char** argv)
|
||||
// Open the device.
|
||||
//
|
||||
// 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().
|
||||
// initialize a config object called ma_device_config_init().
|
||||
//
|
||||
// When using full-duplex you may want to use a different sample format, channel count and channel map. To
|
||||
// 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;
|
||||
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||
deviceConfig.playback.format = ma_format_s16;
|
||||
deviceConfig.playback.channels = 2;
|
||||
deviceConfig.sampleRate = 48000;
|
||||
deviceConfig.dataCallback = data_callback;
|
||||
@@ -149,7 +149,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// 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.
|
||||
deviceConfig.playback.shareMode = mal_share_mode_exclusive;
|
||||
deviceConfig.playback.shareMode = ma_share_mode_exclusive;
|
||||
|
||||
// miniaudio 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
|
||||
@@ -165,12 +165,12 @@ int main(int argc, char** argv)
|
||||
deviceConfig.alsa.noMMap = MA_TRUE;
|
||||
|
||||
// This is not used in this example, but miniaudio allows you to directly control the device ID that's used
|
||||
// for device selection by mal_device_init(). Below is an example for ALSA. In this example it forces
|
||||
// mal_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have
|
||||
// for device selection by ma_device_init(). Below is an example for ALSA. In this example it forces
|
||||
// ma_device_init() to try opening the "hw:0,0" device. This is useful for debugging in case you have
|
||||
// audio glitches or whatnot with specific devices.
|
||||
#ifdef MA_SUPPORT_ALSA
|
||||
mal_device_id customDeviceID;
|
||||
if (context.backend == mal_backend_alsa) {
|
||||
ma_device_id customDeviceID;
|
||||
if (context.backend == ma_backend_alsa) {
|
||||
strcpy(customDeviceID.alsa, "hw:0,0");
|
||||
|
||||
// The ALSA backend also supports a miniaudio-specific format which looks like this: ":0,0". In this case,
|
||||
@@ -181,26 +181,26 @@ int main(int argc, char** argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
mal_device playbackDevice;
|
||||
if (mal_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) {
|
||||
ma_device playbackDevice;
|
||||
if (ma_device_init(&context, &deviceConfig, &playbackDevice) != MA_SUCCESS) {
|
||||
printf("Failed to initialize playback device.\n");
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return -7;
|
||||
}
|
||||
|
||||
if (mal_device_start(&playbackDevice) != MA_SUCCESS) {
|
||||
if (ma_device_start(&playbackDevice) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&playbackDevice);
|
||||
mal_context_uninit(&context);
|
||||
ma_device_uninit(&playbackDevice);
|
||||
ma_context_uninit(&context);
|
||||
return -8;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&playbackDevice);
|
||||
ma_device_uninit(&playbackDevice);
|
||||
|
||||
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+10
-10
@@ -9,12 +9,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pOutput;
|
||||
|
||||
drwav* pWav = (drwav*)pDevice->pUserData;
|
||||
mal_assert(pWav != NULL);
|
||||
ma_assert(pWav != NULL);
|
||||
|
||||
drwav_write_pcm_frames(pWav, frameCount, pInput);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
drwav_data_format wavFormat;
|
||||
wavFormat.container = drwav_container_riff;
|
||||
@@ -41,23 +41,23 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_capture);
|
||||
config.capture.format = mal_format_f32;
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_capture);
|
||||
config.capture.format = ma_format_f32;
|
||||
config.capture.channels = wavFormat.channels;
|
||||
config.sampleRate = wavFormat.sampleRate;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &wav;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init(NULL, &config, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init(NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize capture device.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
printf("Failed to start device.\n");
|
||||
return -3;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ int main(int argc, char** argv)
|
||||
printf("Press Enter to stop recording...\n");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
drwav_uninit(&wav);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -8,35 +8,35 @@ int main(int argc, char** argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_context context;
|
||||
if (mal_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
|
||||
ma_context context;
|
||||
if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
|
||||
printf("Failed to initialize context.\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
mal_device_info* pPlaybackDeviceInfos;
|
||||
mal_uint32 playbackDeviceCount;
|
||||
mal_device_info* pCaptureDeviceInfos;
|
||||
mal_uint32 captureDeviceCount;
|
||||
mal_result result = mal_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_device_info* pCaptureDeviceInfos;
|
||||
ma_uint32 captureDeviceCount;
|
||||
ma_result result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, &pCaptureDeviceInfos, &captureDeviceCount);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to retrieve device information.\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Playback Devices\n");
|
||||
for (mal_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
printf("Capture Devices\n");
|
||||
for (mal_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
|
||||
printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
|
||||
}
|
||||
|
||||
|
||||
mal_context_uninit(&context);
|
||||
ma_context_uninit(&context);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+14
-14
@@ -10,14 +10,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
mal_decoder* pDecoder = (mal_decoder*)pDevice->pUserData;
|
||||
ma_decoder* pDecoder = (ma_decoder*)pDevice->pUserData;
|
||||
if (pDecoder == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mal_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
ma_decoder_read_pcm_frames(pDecoder, pOutput, frameCount);
|
||||
|
||||
(void)pInput;
|
||||
}
|
||||
@@ -29,38 +29,38 @@ int main(int argc, char** argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
mal_decoder decoder;
|
||||
mal_result result = mal_decoder_init_file(argv[1], NULL, &decoder);
|
||||
ma_decoder decoder;
|
||||
ma_result result = ma_decoder_init_file(argv[1], NULL, &decoder);
|
||||
if (result != MA_SUCCESS) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = decoder.outputFormat;
|
||||
config.playback.channels = decoder.outputChannels;
|
||||
config.sampleRate = decoder.outputSampleRate;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &decoder;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
ma_device device;
|
||||
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
printf("Failed to open playback device.\n");
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (mal_device_start(&device) != MA_SUCCESS) {
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
mal_decoder_uninit(&decoder);
|
||||
ma_device_uninit(&device);
|
||||
ma_decoder_uninit(&decoder);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ void main_loop__em()
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DEVICE_FORMAT mal_format_f32
|
||||
#define DEVICE_FORMAT ma_format_f32
|
||||
#define DEVICE_CHANNELS 1
|
||||
#define DEVICE_SAMPLE_RATE 48000
|
||||
|
||||
void data_callback(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pInput; /* Unused. */
|
||||
mal_assert(pDevice->playback.channels == DEVICE_CHANNELS);
|
||||
ma_assert(pDevice->playback.channels == DEVICE_CHANNELS);
|
||||
|
||||
mal_sine_wave* pSineWave = (mal_sine_wave*)pDevice->pUserData;
|
||||
mal_assert(pSineWave != NULL);
|
||||
ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
|
||||
ma_assert(pSineWave != NULL);
|
||||
|
||||
mal_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput);
|
||||
ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -31,27 +31,27 @@ int main(int argc, char** argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
mal_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
|
||||
ma_sine_wave sineWave;
|
||||
ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = DEVICE_FORMAT;
|
||||
config.playback.channels = DEVICE_CHANNELS;
|
||||
config.sampleRate = DEVICE_SAMPLE_RATE;
|
||||
config.dataCallback = data_callback;
|
||||
config.pUserData = &sineWave;
|
||||
|
||||
mal_device device;
|
||||
if (mal_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
ma_device device;
|
||||
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
|
||||
printf("Failed to open playback device.\n");
|
||||
return -4;
|
||||
}
|
||||
|
||||
printf("Device Name: %s\n", device.playback.name);
|
||||
|
||||
if (mal_device_start(&device) != MA_SUCCESS) {
|
||||
if (ma_device_start(&device) != MA_SUCCESS) {
|
||||
printf("Failed to start playback device.\n");
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return -5;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ int main(int argc, char** argv)
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user