aboutsummaryrefslogtreecommitdiff
path: root/example2.c
diff options
context:
space:
mode:
Diffstat (limited to 'example2.c')
-rw-r--r--example2.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/example2.c b/example2.c
index ea14db1..cfc0fc0 100644
--- a/example2.c
+++ b/example2.c
@@ -9,8 +9,7 @@ static tsf* g_TinySoundFont;
9// A Mutex so we don't call note_on/note_off while rendering audio samples 9// A Mutex so we don't call note_on/note_off while rendering audio samples
10static SDL_mutex* g_Mutex; 10static SDL_mutex* g_Mutex;
11 11
12static void AudioCallback(void* data, Uint8 *stream, int len) 12static void AudioCallback(void* data, Uint8 *stream, int len) {
13{
14 // Render the audio samples in float format 13 // Render the audio samples in float format
15 int SampleCount = (len / (2 * sizeof(float))); //2 output channels 14 int SampleCount = (len / (2 * sizeof(float))); //2 output channels
16 SDL_LockMutex(g_Mutex); //get exclusive lock 15 SDL_LockMutex(g_Mutex); //get exclusive lock
@@ -18,8 +17,7 @@ static void AudioCallback(void* data, Uint8 *stream, int len)
18 SDL_UnlockMutex(g_Mutex); 17 SDL_UnlockMutex(g_Mutex);
19} 18}
20 19
21int main(int argc, char *argv[]) 20int main(int argc, char *argv[]) {
22{
23 int i, Notes[7] = { 48, 50, 52, 53, 55, 57, 59 }; 21 int i, Notes[7] = { 48, 50, 52, 53, 55, 57, 59 };
24 22
25 // Define the desired audio output format we request 23 // Define the desired audio output format we request
@@ -31,16 +29,14 @@ int main(int argc, char *argv[])
31 OutputAudioSpec.callback = AudioCallback; 29 OutputAudioSpec.callback = AudioCallback;
32 30
33 // Initialize the audio system 31 // Initialize the audio system
34 if (SDL_AudioInit(TSF_NULL) < 0) 32 if (SDL_AudioInit(TSF_NULL) < 0) {
35 {
36 fprintf(stderr, "Could not initialize audio hardware or driver\n"); 33 fprintf(stderr, "Could not initialize audio hardware or driver\n");
37 return 1; 34 return 1;
38 } 35 }
39 36
40 // Load the SoundFont from a file 37 // Load the SoundFont from a file
41 g_TinySoundFont = tsf_load_filename("florestan-subset.sf2"); 38 g_TinySoundFont = tsf_load_filename("sf2/florestan-subset.sf2");
42 if (!g_TinySoundFont) 39 if (!g_TinySoundFont) {
43 {
44 fprintf(stderr, "Could not load SoundFont\n"); 40 fprintf(stderr, "Could not load SoundFont\n");
45 return 1; 41 return 1;
46 } 42 }
@@ -52,8 +48,7 @@ int main(int argc, char *argv[])
52 g_Mutex = SDL_CreateMutex(); 48 g_Mutex = SDL_CreateMutex();
53 49
54 // Request the desired audio output format 50 // Request the desired audio output format
55 if (SDL_OpenAudio(&OutputAudioSpec, TSF_NULL) < 0) 51 if (SDL_OpenAudio(&OutputAudioSpec, TSF_NULL) < 0) {
56 {
57 fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n"); 52 fprintf(stderr, "Could not open the audio hardware or the desired audio output format\n");
58 return 1; 53 return 1;
59 } 54 }
@@ -63,8 +58,7 @@ int main(int argc, char *argv[])
63 SDL_PauseAudio(0); 58 SDL_PauseAudio(0);
64 59
65 // Loop through all the presets in the loaded SoundFont 60 // Loop through all the presets in the loaded SoundFont
66 for (i = 0; i < tsf_get_presetcount(g_TinySoundFont); i++) 61 for (i = 0; i < tsf_get_presetcount(g_TinySoundFont); i++) {
67 {
68 //Get exclusive mutex lock, end the previous note and play a new note 62 //Get exclusive mutex lock, end the previous note and play a new note
69 printf("Play note %d with preset #%d '%s'\n", Notes[i % 7], i, tsf_get_presetname(g_TinySoundFont, i)); 63 printf("Play note %d with preset #%d '%s'\n", Notes[i % 7], i, tsf_get_presetname(g_TinySoundFont, i));
70 SDL_LockMutex(g_Mutex); 64 SDL_LockMutex(g_Mutex);
@@ -79,3 +73,4 @@ int main(int argc, char *argv[])
79 // because the process ends here. 73 // because the process ends here.
80 return 0; 74 return 0;
81} 75}
76