summaryrefslogtreecommitdiff
path: root/example1.c
diff options
context:
space:
mode:
Diffstat (limited to 'example1.c')
-rw-r--r--example1.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/example1.c b/example1.c
index ce38a7c..200fd1b 100644
--- a/example1.c
+++ b/example1.c
@@ -4,9 +4,8 @@
4#include "minisdl_audio.h" 4#include "minisdl_audio.h"
5 5
6//This is a minimal SoundFont with a single loopin saw-wave sample/instrument/preset (484 bytes) 6//This is a minimal SoundFont with a single loopin saw-wave sample/instrument/preset (484 bytes)
7const static unsigned char MinimalSoundFont[] = 7const static unsigned char MinimalSoundFont[] = {
8{ 8#define TEN0 0,0,0,0,0,0,0,0,0,0
9 #define TEN0 0,0,0,0,0,0,0,0,0,0
10 'R','I','F','F',220,1,0,0,'s','f','b','k', 9 'R','I','F','F',220,1,0,0,'s','f','b','k',
11 'L','I','S','T',88,1,0,0,'p','d','t','a', 10 'L','I','S','T',88,1,0,0,'p','d','t','a',
12 '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, 11 '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[] =
16 'i','g','e','n',12,0,0,0,54,0,1,0,53,0,0,0,0,0,0,0, 15 'i','g','e','n',12,0,0,0,54,0,1,0,53,0,0,0,0,0,0,0,
17 '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, 16 '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,
18 '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, 17 '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,
19 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 18 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
20}; 19};
21 20
22// Holds the global instance pointer 21// Holds the global instance pointer
23static tsf* g_TinySoundFont; 22static tsf* g_TinySoundFont;
24 23
25// Callback function called by the audio thread 24// Callback function called by the audio thread
26static void AudioCallback(void* data, Uint8 *stream, int len) 25static void AudioCallback(void* data, Uint8 *stream, int len) {
27{
28 // Note we don't do any thread concurrency control here because in this 26 // Note we don't do any thread concurrency control here because in this
29 // example all notes are started before the audio playback begins. 27 // example all notes are started before the audio playback begins.
30 // If you do play notes while the audio thread renders output you 28 // 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)
33 tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0); 31 tsf_render_short(g_TinySoundFont, (short*)stream, SampleCount, 0);
34} 32}
35 33
36int main(int argc, char *argv[]) 34int main(int argc, char *argv[]) {
37{
38 // Define the desired audio output format we request 35 // Define the desired audio output format we request
39 SDL_AudioSpec OutputAudioSpec; 36 SDL_AudioSpec OutputAudioSpec;
40 OutputAudioSpec.freq = 44100; 37 OutputAudioSpec.freq = 44100;
@@ -44,16 +41,14 @@ int main(int argc, char *argv[])
44 OutputAudioSpec.callback = AudioCallback; 41 OutputAudioSpec.callback = AudioCallback;
45 42
46 // Initialize the audio system 43 // Initialize the audio system
47 if (SDL_AudioInit(NULL) < 0) 44 if (SDL_AudioInit(NULL) < 0) {
48 {
49 fprintf(stderr, "Could not initialize audio hardware or driver\n"); 45 fprintf(stderr, "Could not initialize audio hardware or driver\n");
50 return 1; 46 return 1;
51 } 47 }
52 48
53 // Load the SoundFont from the memory block 49 // Load the SoundFont from the memory block
54 g_TinySoundFont = tsf_load_memory(MinimalSoundFont, sizeof(MinimalSoundFont)); 50 g_TinySoundFont = tsf_load_memory(MinimalSoundFont, sizeof(MinimalSoundFont));
55 if (!g_TinySoundFont) 51 if (!g_TinySoundFont) {
56 {
57 fprintf(stderr, "Could not load soundfont\n"); 52 fprintf(stderr, "Could not load soundfont\n");
58 return 1; 53 return 1;
59 } 54 }
@@ -66,8 +61,7 @@ int main(int argc, char *argv[])
66 tsf_note_on(g_TinySoundFont, 0, 52, 1.0f); //E2 61 tsf_note_on(g_TinySoundFont, 0, 52, 1.0f); //E2
67 62
68 // Request the desired audio output format 63 // Request the desired audio output format
69 if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0) 64 if (SDL_OpenAudio(&OutputAudioSpec, NULL) < 0) {
70 {
71 fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n"); 65 fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n");
72 return 1; 66 return 1;
73 } 67 }
@@ -84,3 +78,4 @@ int main(int argc, char *argv[])
84 // because the process ends here. 78 // because the process ends here.
85 return 0; 79 return 0;
86} 80}
81