Commit 971eb610 authored by David Reid's avatar David Reid

Update examples to C89.

parent 2fcb2b9a
This diff is collapsed.
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
emcc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten.html
\ No newline at end of file
emcc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten.html -std=c89 -ansi -Wall
\ No newline at end of file
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c99 -lpthread -ldl -lm
\ No newline at end of file
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -ldl -lm
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c99 -lpthread -lm
cc ../simple_playback.c -o ../bin/simple_playback -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_capture.c -o ../bin/simple_capture -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_enumeration.c -o ../bin/simple_enumeration -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../advanced_config.c -o ../bin/advanced_config -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_mixing.c -o ../bin/simple_mixing -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
cc ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten -Wall -Wpedantic -std=c89 -ansi -pedantic -lpthread -lm
@echo off
SET c_compiler=gcc
SET cpp_compiler=g++
SET options=-Wall -Wpedantic -std=c99
SET options=-Wall -Wpedantic -std=c89 -ansi -pedantic
@echo on
%c_compiler% ../simple_playback.c -o ../bin/simple_playback.exe %options%
%c_compiler% ../simple_capture.c -o ../bin/simple_capture.exe %options%
%c_compiler% ../simple_enumeration.c -o ../bin/simple_enumeration.exe %options%
%c_compiler% ../advanced_config.c -o ../bin/advanced_config.exe %options%
\ No newline at end of file
%c_compiler% ../simple_playback.c -o ../bin/simple_playback.exe %options%
%c_compiler% ../simple_capture.c -o ../bin/simple_capture.exe %options%
%c_compiler% ../simple_enumeration.c -o ../bin/simple_enumeration.exe %options%
%c_compiler% ../simple_mixing.c -o ../bin/simple_mixing.exe %options%
%c_compiler% ../simple_playback_emscripten.c -o ../bin/simple_playback_emscripten.exe %options%
%c_compiler% ../advanced_config.c -o ../bin/advanced_config.exe %options%
\ No newline at end of file
// This example simply captures data from your default microphone until you press Enter. The output is saved to the file specified on the command line.
/* This example simply captures data from your default microphone until you press Enter. The output is saved to the file specified on the command line. */
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
......@@ -11,45 +11,46 @@
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
(void)pOutput;
drwav* pWav = (drwav*)pDevice->pUserData;
ma_assert(pWav != NULL);
drwav_write_pcm_frames(pWav, frameCount, pInput);
(void)pOutput;
}
int main(int argc, char** argv)
{
ma_result result;
drwav_data_format wavFormat;
drwav wav;
ma_device_config deviceConfig;
ma_device device;
if (argc < 2) {
printf("No input file.\n");
return -1;
}
ma_result result;
drwav_data_format wavFormat;
wavFormat.container = drwav_container_riff;
wavFormat.format = DR_WAVE_FORMAT_IEEE_FLOAT;
wavFormat.channels = 2;
wavFormat.sampleRate = 44100;
wavFormat.bitsPerSample = 32;
drwav wav;
if (drwav_init_file_write(&wav, argv[1], &wavFormat) == DRWAV_FALSE) {
printf("Failed to initialize output file.\n");
return -1;
}
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;
deviceConfig = ma_device_config_init(ma_device_type_capture);
deviceConfig.capture.format = ma_format_f32;
deviceConfig.capture.channels = wavFormat.channels;
deviceConfig.sampleRate = wavFormat.sampleRate;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &wav;
ma_device device;
result = ma_device_init(NULL, &config, &device);
result = ma_device_init(NULL, &deviceConfig, &device);
if (result != MA_SUCCESS) {
printf("Failed to initialize capture device.\n");
return -2;
......
......@@ -5,38 +5,41 @@
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
ma_result result;
ma_context context;
ma_device_info* pPlaybackDeviceInfos;
ma_uint32 playbackDeviceCount;
ma_device_info* pCaptureDeviceInfos;
ma_uint32 captureDeviceCount;
ma_uint32 iDevice;
if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) {
printf("Failed to initialize context.\n");
return -2;
}
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);
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 (ma_uint32 iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
for (iDevice = 0; iDevice < playbackDeviceCount; ++iDevice) {
printf(" %u: %s\n", iDevice, pPlaybackDeviceInfos[iDevice].name);
}
printf("\n");
printf("Capture Devices\n");
for (ma_uint32 iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
for (iDevice = 0; iDevice < captureDeviceCount; ++iDevice) {
printf(" %u: %s\n", iDevice, pCaptureDeviceInfos[iDevice].name);
}
ma_context_uninit(&context);
(void)argc;
(void)argv;
return 0;
}
......@@ -4,11 +4,11 @@ Example: simple_mixing file1.wav file2.flac
*/
#define DR_FLAC_IMPLEMENTATION
#include "../extras/dr_flac.h" // Enables FLAC decoding.
#include "../extras/dr_flac.h" /* Enables FLAC decoding. */
#define DR_MP3_IMPLEMENTATION
#include "../extras/dr_mp3.h" // Enables MP3 decoding.
#include "../extras/dr_mp3.h" /* Enables MP3 decoding. */
#define DR_WAV_IMPLEMENTATION
#include "../extras/dr_wav.h" // Enables WAV decoding.
#include "../extras/dr_wav.h" /* Enables WAV decoding. */
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
......@@ -30,7 +30,8 @@ ma_event g_stopEvent; /* <-- Signaled by the audio thread, waited on by the main
ma_bool32 are_all_decoders_at_end()
{
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
ma_uint32 iDecoder;
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
if (g_pDecodersAtEnd[iDecoder] == MA_FALSE) {
return MA_FALSE;
}
......@@ -51,6 +52,7 @@ ma_uint32 read_and_mix_pcm_frames_f32(ma_decoder* pDecoder, float* pOutputF32, m
ma_uint32 totalFramesRead = 0;
while (totalFramesRead < frameCount) {
ma_uint32 iSample;
ma_uint32 framesReadThisIteration;
ma_uint32 totalFramesRemaining = frameCount - totalFramesRead;
ma_uint32 framesToReadThisIteration = tempCapInFrames;
......@@ -64,7 +66,7 @@ ma_uint32 read_and_mix_pcm_frames_f32(ma_decoder* pDecoder, float* pOutputF32, m
}
/* Mix the frames together. */
for (ma_uint32 iSample = 0; iSample < framesReadThisIteration*CHANNEL_COUNT; ++iSample) {
for (iSample = 0; iSample < framesReadThisIteration*CHANNEL_COUNT; ++iSample) {
pOutputF32[totalFramesRead*CHANNEL_COUNT + iSample] += temp[iSample];
}
......@@ -81,10 +83,11 @@ ma_uint32 read_and_mix_pcm_frames_f32(ma_decoder* pDecoder, float* pOutputF32, m
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
float* pOutputF32 = (float*)pOutput;
ma_uint32 iDecoder;
ma_assert(pDevice->playback.format == SAMPLE_FORMAT); /* <-- Important for this example. */
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
if (!g_pDecodersAtEnd[iDecoder]) {
ma_uint32 framesRead = read_and_mix_pcm_frames_f32(&g_pDecoders[iDecoder], pOutputF32, frameCount);
if (framesRead < frameCount) {
......@@ -108,6 +111,9 @@ int main(int argc, char** argv)
{
ma_result result;
ma_decoder_config decoderConfig;
ma_device_config deviceConfig;
ma_device device;
ma_uint32 iDecoder;
if (argc < 2) {
printf("No input files.\n");
......@@ -120,10 +126,11 @@ int main(int argc, char** argv)
/* In this example, all decoders need to have the same output format. */
decoderConfig = ma_decoder_config_init(SAMPLE_FORMAT, CHANNEL_COUNT, SAMPLE_RATE);
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
result = ma_decoder_init_file(argv[1+iDecoder], &decoderConfig, &g_pDecoders[iDecoder]);
if (result != MA_SUCCESS) {
for (ma_uint32 iDecoder2 = 0; iDecoder2 < iDecoder; ++iDecoder2) {
ma_uint32 iDecoder2;
for (iDecoder2 = 0; iDecoder2 < iDecoder; ++iDecoder2) {
ma_decoder_uninit(&g_pDecoders[iDecoder2]);
}
free(g_pDecoders);
......@@ -136,16 +143,15 @@ int main(int argc, char** argv)
}
/* Create only a single device. The decoders will be mixed together in the callback. In this example the data format needs to be the same as the decoders. */
ma_device_config config = ma_device_config_init(ma_device_type_playback);
config.playback.format = SAMPLE_FORMAT;
config.playback.channels = CHANNEL_COUNT;
config.sampleRate = SAMPLE_RATE;
config.dataCallback = data_callback;
config.pUserData = NULL;
ma_device device;
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = SAMPLE_FORMAT;
deviceConfig.playback.channels = CHANNEL_COUNT;
deviceConfig.sampleRate = SAMPLE_RATE;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = NULL;
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
ma_decoder_uninit(&g_pDecoders[iDecoder]);
}
free(g_pDecoders);
......@@ -165,7 +171,7 @@ int main(int argc, char** argv)
/* Now we start playback and wait for the audio thread to tell us to stop. */
if (ma_device_start(&device) != MA_SUCCESS) {
ma_device_uninit(&device);
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
ma_decoder_uninit(&g_pDecoders[iDecoder]);
}
free(g_pDecoders);
......@@ -181,7 +187,7 @@ int main(int argc, char** argv)
/* Getting here means the audio thread has signaled that the device should be stopped. */
ma_device_uninit(&device);
for (ma_uint32 iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
for (iDecoder = 0; iDecoder < g_decoderCount; ++iDecoder) {
ma_decoder_uninit(&g_pDecoders[iDecoder]);
}
free(g_pDecoders);
......
......@@ -26,7 +26,7 @@ int main(int argc, char** argv)
{
ma_result result;
ma_decoder decoder;
ma_device_config config;
ma_device_config deviceConfig;
ma_device device;
if (argc < 2) {
......@@ -39,14 +39,14 @@ int main(int argc, char** argv)
return -2;
}
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;
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = decoder.outputFormat;
deviceConfig.playback.channels = decoder.outputChannels;
deviceConfig.sampleRate = decoder.outputSampleRate;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &decoder;
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
ma_decoder_uninit(&decoder);
return -3;
......
......@@ -17,32 +17,34 @@ void main_loop__em()
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
(void)pInput; /* Unused. */
ma_sine_wave* pSineWave;
ma_assert(pDevice->playback.channels == DEVICE_CHANNELS);
ma_sine_wave* pSineWave = (ma_sine_wave*)pDevice->pUserData;
pSineWave = (ma_sine_wave*)pDevice->pUserData;
ma_assert(pSineWave != NULL);
ma_sine_wave_read_f32(pSineWave, frameCount, (float*)pOutput);
(void)pInput; /* Unused. */
}
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
ma_sine_wave sineWave;
ma_device_config deviceConfig;
ma_device device;
ma_sine_wave_init(0.2, 400, DEVICE_SAMPLE_RATE, &sineWave);
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;
deviceConfig = ma_device_config_init(ma_device_type_playback);
deviceConfig.playback.format = DEVICE_FORMAT;
deviceConfig.playback.channels = DEVICE_CHANNELS;
deviceConfig.sampleRate = DEVICE_SAMPLE_RATE;
deviceConfig.dataCallback = data_callback;
deviceConfig.pUserData = &sineWave;
ma_device device;
if (ma_device_init(NULL, &config, &device) != MA_SUCCESS) {
if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
printf("Failed to open playback device.\n");
return -4;
}
......@@ -64,5 +66,7 @@ int main(int argc, char** argv)
ma_device_uninit(&device);
(void)argc;
(void)argv;
return 0;
}
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