summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/sound.c')
-rw-r--r--uisimulator/sdl/sound.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
index 388b188448..66df6961b2 100644
--- a/uisimulator/sdl/sound.c
+++ b/uisimulator/sdl/sound.c
@@ -21,24 +21,15 @@
21 21
22#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ 22#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
23 23
24#include <stdio.h> 24#include <memory.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <unistd.h> 26#include "uisdl.h"
27#include <fcntl.h>
28#include <string.h>
29#include <SDL.h>
30
31#include "sound.h" 27#include "sound.h"
32 28
33//static Uint8 *audio_chunk;
34static int audio_len; 29static int audio_len;
35static char *audio_pos; 30static char *audio_pos;
36SDL_sem* sem; 31SDL_sem* sem;
37 32
38/* The audio function callback takes the following parameters:
39 stream: A pointer to the audio buffer to be filled
40 len: The length (in bytes) of the audio buffer
41*/
42void mixaudio(void *udata, Uint8 *stream, int len) 33void mixaudio(void *udata, Uint8 *stream, int len)
43{ 34{
44 (void)udata; 35 (void)udata;
@@ -59,8 +50,6 @@ void mixaudio(void *udata, Uint8 *stream, int len)
59 } 50 }
60} 51}
61 52
62
63
64int sim_sound_init(void) 53int sim_sound_init(void)
65{ 54{
66 SDL_AudioSpec fmt; 55 SDL_AudioSpec fmt;
@@ -80,15 +69,12 @@ int sim_sound_init(void)
80 fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); 69 fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
81 return -1; 70 return -1;
82 } 71 }
72
83 SDL_PauseAudio(0); 73 SDL_PauseAudio(0);
84 return 0; 74 return 0;
85
86 //...
87
88 //SDL_CloseAudio();
89} 75}
90 76
91int sound_playback_thread(void* p) 77int sound_playback_thread(void *p)
92{ 78{
93 int sndret = sim_sound_init(); 79 int sndret = sim_sound_init();
94 unsigned char *buf; 80 unsigned char *buf;
@@ -97,12 +83,12 @@ int sound_playback_thread(void* p)
97 (void)p; 83 (void)p;
98 84
99 while(sndret) 85 while(sndret)
100 sleep(100000); /* wait forever, can't play sound! */ 86 SDL_Delay(100000); /* wait forever, can't play sound! */
101 87
102 do { 88 do {
103 while(!sound_get_pcm) 89 while(!sound_get_pcm)
104 /* TODO: fix a fine thread-synch mechanism here */ 90 /* TODO: fix a fine thread-synch mechanism here */
105 usleep(10000); 91 SDL_Delay(100);
106 do { 92 do {
107 sound_get_pcm(&buf, &size); 93 sound_get_pcm(&buf, &size);
108 if(!size) { 94 if(!size) {
@@ -111,11 +97,13 @@ int sound_playback_thread(void* p)
111 } 97 }
112 audio_pos = buf; // TODO: is this safe? 98 audio_pos = buf; // TODO: is this safe?
113 audio_len = size; 99 audio_len = size;
114 //printf("len: %i\n",audio_len); 100
115 if(SDL_SemWait(sem)) 101 if(SDL_SemWait(sem))
116 fprintf(stderr,"Couldn't wait: %s",SDL_GetError()); 102 fprintf(stderr,"Couldn't wait: %s",SDL_GetError());
117 } while(size); 103 } while(size);
118 } while(1); 104 } while(1);
105
119} 106}
120 107
121#endif /* ROCKBOX_HAS_SIMSOUND */ 108#endif /* ROCKBOX_HAS_SIMSOUND */
109