From 988f5d2b5343850e19ad1512cefe6c53953aa02e Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Mon, 7 Oct 2024 06:50:04 +0200 Subject: Added bunch of examples --- example1.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'example1.c') diff --git a/example1.c b/example1.c index ce38a7c..200fd1b 100644 --- a/example1.c +++ b/example1.c @@ -4,9 +4,8 @@ #include "minisdl_audio.h" //This is a minimal SoundFont with a single loopin saw-wave sample/instrument/preset (484 bytes) -const static unsigned char MinimalSoundFont[] = -{ - #define TEN0 0,0,0,0,0,0,0,0,0,0 +const static unsigned char MinimalSoundFont[] = { +#define TEN0 0,0,0,0,0,0,0,0,0,0 'R','I','F','F',220,1,0,0,'s','f','b','k', 'L','I','S','T',88,1,0,0,'p','d','t','a', 'p','h','d','r',76,TEN0,TEN0,TEN0,TEN0,0,0,0,0,TEN0,0,0,0,0,0,0,0,255,0,255,0,1,TEN0,0,0,0, @@ -16,15 +15,14 @@ const static unsigned char MinimalSoundFont[] = 'i','g','e','n',12,0,0,0,54,0,1,0,53,0,0,0,0,0,0,0, 's','h','d','r',92,TEN0,TEN0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,49,0,0,0,34,86,0,0,60,0,0,0,1,TEN0,TEN0,TEN0,TEN0,0,0,0,0,0,0,0, 'L','I','S','T',112,0,0,0,'s','d','t','a','s','m','p','l',100,0,0,0,86,0,119,3,31,7,147,10,43,14,169,17,58,21,189,24,73,28,204,31,73,35,249,38,46,42,71,46,250,48,150,53,242,55,126,60,151,63,108,66,126,72,207, - 70,86,83,100,72,74,100,163,39,241,163,59,175,59,179,9,179,134,187,6,186,2,194,5,194,15,200,6,202,96,206,159,209,35,213,213,216,45,220,221,223,76,227,221,230,91,234,242,237,105,241,8,245,118,248,32,252 + 70,86,83,100,72,74,100,163,39,241,163,59,175,59,179,9,179,134,187,6,186,2,194,5,194,15,200,6,202,96,206,159,209,35,213,213,216,45,220,221,223,76,227,221,230,91,234,242,237,105,241,8,245,118,248,32,252 }; // Holds the global instance pointer static tsf* g_TinySoundFont; // Callback function called by the audio thread -static void AudioCallback(void* data, Uint8 *stream, int len) -{ +static void AudioCallback(void* data, Uint8 *stream, int len) { // Note we don't do any thread concurrency control here because in this // example all notes are started before the audio playback begins. // If you do play notes while the audio thread renders output you @@ -33,8 +31,7 @@ static void AudioCallback(void* data, Uint8 *stream, int len) tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0); } -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { // Define the desired audio output format we request SDL_AudioSpec OutputAudioSpec; OutputAudioSpec.freq = 44100; @@ -44,16 +41,14 @@ int main(int argc, char *argv[]) OutputAudioSpec.callback = AudioCallback; // Initialize the audio system - if (SDL_AudioInit(NULL) < 0) - { + if (SDL_AudioInit(NULL) < 0) { fprintf(stderr, "Could not initialize audio hardware or driver\n"); return 1; } // Load the SoundFont from the memory block g_TinySoundFont = tsf_load_memory(MinimalSoundFont, sizeof(MinimalSoundFont)); - if (!g_TinySoundFont) - { + if (!g_TinySoundFont) { fprintf(stderr, "Could not load soundfont\n"); return 1; } @@ -66,8 +61,7 @@ int main(int argc, char *argv[]) tsf_note_on(g_TinySoundFont, 0, 52, 1.0f); //E2 // Request the desired audio output format - if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0) - { + if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0) { fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n"); return 1; } @@ -84,3 +78,4 @@ int main(int argc, char *argv[]) // because the process ends here. return 0; } + -- cgit v1.2.3