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:
+25
-25
@@ -3,38 +3,38 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "../miniaudio.h"
|
||||
|
||||
mal_sine_wave sineWave;
|
||||
mal_uint32 framesWritten;
|
||||
mal_event stopEvent;
|
||||
mal_bool32 isInitialRun = MA_TRUE;
|
||||
ma_sine_wave sineWave;
|
||||
ma_uint32 framesWritten;
|
||||
ma_event stopEvent;
|
||||
ma_bool32 isInitialRun = MA_TRUE;
|
||||
|
||||
void on_stop(mal_device* pDevice)
|
||||
void on_stop(ma_device* pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
printf("STOPPED\n");
|
||||
}
|
||||
|
||||
void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32 frameCount)
|
||||
void on_data(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
|
||||
{
|
||||
(void)pInput; /* Not used yet. */
|
||||
|
||||
/* Output exactly one second of data. Pad the end with silence. */
|
||||
mal_uint32 framesRemaining = pDevice->sampleRate - framesWritten;
|
||||
mal_uint32 framesToProcess = frameCount;
|
||||
ma_uint32 framesRemaining = pDevice->sampleRate - framesWritten;
|
||||
ma_uint32 framesToProcess = frameCount;
|
||||
if (framesToProcess > framesRemaining && isInitialRun) {
|
||||
framesToProcess = framesRemaining;
|
||||
}
|
||||
|
||||
mal_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, mal_stream_layout_interleaved, (float**)&pOutput);
|
||||
ma_sine_wave_read_f32_ex(&sineWave, framesToProcess, pDevice->playback.channels, ma_stream_layout_interleaved, (float**)&pOutput);
|
||||
if (isInitialRun) {
|
||||
framesWritten += framesToProcess;
|
||||
}
|
||||
|
||||
mal_assert(framesWritten <= pDevice->sampleRate);
|
||||
ma_assert(framesWritten <= pDevice->sampleRate);
|
||||
if (framesWritten >= pDevice->sampleRate) {
|
||||
if (isInitialRun) {
|
||||
printf("STOPPING [AUDIO THREAD]...\n");
|
||||
mal_event_signal(&stopEvent);
|
||||
ma_event_signal(&stopEvent);
|
||||
isInitialRun = MA_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -42,57 +42,57 @@ void on_data(mal_device* pDevice, void* pOutput, const void* pInput, mal_uint32
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
mal_result result;
|
||||
ma_result result;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
mal_backend backend = mal_backend_wasapi;
|
||||
ma_backend backend = ma_backend_wasapi;
|
||||
|
||||
mal_sine_wave_init(0.25, 400, 44100, &sineWave);
|
||||
ma_sine_wave_init(0.25, 400, 44100, &sineWave);
|
||||
|
||||
mal_device_config config = mal_device_config_init(mal_device_type_playback);
|
||||
config.playback.format = mal_format_f32;
|
||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.format = ma_format_f32;
|
||||
config.playback.channels = 2;
|
||||
config.sampleRate = 44100;
|
||||
config.dataCallback = on_data;
|
||||
config.stopCallback = on_stop;
|
||||
config.bufferSizeInFrames = 16384;
|
||||
|
||||
mal_device device;
|
||||
result = mal_device_init_ex(&backend, 1, NULL, &config, &device);
|
||||
ma_device device;
|
||||
result = ma_device_init_ex(&backend, 1, NULL, &config, &device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize device.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = mal_event_init(device.pContext, &stopEvent);
|
||||
result = ma_event_init(device.pContext, &stopEvent);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to initialize stop event.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
mal_device_start(&device);
|
||||
ma_device_start(&device);
|
||||
|
||||
/* We wait for the stop event, stop the device, then ask the user to press any key to restart. This checks that the device can restart after stopping. */
|
||||
mal_event_wait(&stopEvent);
|
||||
ma_event_wait(&stopEvent);
|
||||
|
||||
printf("STOPPING [MAIN THREAD]...\n");
|
||||
mal_device_stop(&device);
|
||||
ma_device_stop(&device);
|
||||
|
||||
printf("Press Enter to restart...\n");
|
||||
getchar();
|
||||
|
||||
result = mal_device_start(&device);
|
||||
result = ma_device_start(&device);
|
||||
if (result != MA_SUCCESS) {
|
||||
printf("Failed to restart the device.\n");
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Press Enter to quit...\n");
|
||||
getchar();
|
||||
|
||||
mal_device_uninit(&device);
|
||||
ma_device_uninit(&device);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user