diff options
author | Dan Everton <dan@iocaine.org> | 2006-02-21 21:48:06 +0000 |
---|---|---|
committer | Dan Everton <dan@iocaine.org> | 2006-02-21 21:48:06 +0000 |
commit | 394521881072eb49b29352f479a8f17ee403fbd6 (patch) | |
tree | 90669c700d75f539b994e2c4c6fbc862ff563119 /uisimulator | |
parent | 8850c61ee1270b670533ea0810a73ce9a5b30c86 (diff) | |
download | rockbox-394521881072eb49b29352f479a8f17ee403fbd6.tar.gz rockbox-394521881072eb49b29352f479a8f17ee403fbd6.zip |
Proper working sound in the SDL sim. Add option to write raw audio to a file, use --debugaudio command line option.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8770 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/sdl/sound.c | 66 | ||||
-rw-r--r-- | uisimulator/sdl/uisdl.c | 10 |
2 files changed, 54 insertions, 22 deletions
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c index 4b8427ca90..757ebe13c7 100644 --- a/uisimulator/sdl/sound.c +++ b/uisimulator/sdl/sound.c | |||
@@ -33,13 +33,19 @@ static bool pcm_paused; | |||
33 | static Uint8* pcm_data; | 33 | static Uint8* pcm_data; |
34 | static int pcm_data_size; | 34 | static int pcm_data_size; |
35 | 35 | ||
36 | extern bool debug_audio; | ||
37 | |||
36 | static void sdl_dma_start(const void *addr, size_t size) | 38 | static void sdl_dma_start(const void *addr, size_t size) |
37 | { | 39 | { |
38 | pcm_playing = true; | 40 | pcm_playing = true; |
39 | 41 | ||
42 | SDL_LockAudio(); | ||
43 | |||
40 | pcm_data = (Uint8 *) addr; | 44 | pcm_data = (Uint8 *) addr; |
41 | pcm_data_size = size; | 45 | pcm_data_size = size; |
42 | 46 | ||
47 | SDL_UnlockAudio(); | ||
48 | |||
43 | SDL_PauseAudio(0); | 49 | SDL_PauseAudio(0); |
44 | } | 50 | } |
45 | 51 | ||
@@ -136,37 +142,57 @@ bool pcm_is_playing(void) | |||
136 | return pcm_playing; | 142 | return pcm_playing; |
137 | } | 143 | } |
138 | 144 | ||
145 | char overflow[8192]; | ||
146 | int overflow_amount = 0; | ||
147 | |||
139 | void sdl_audio_callback(void *udata, Uint8 *stream, int len) | 148 | void sdl_audio_callback(void *udata, Uint8 *stream, int len) |
140 | { | 149 | { |
141 | int datalen; | 150 | int datalen, offset; |
142 | 151 | FILE *debug = (FILE *)udata; | |
143 | (void) udata; | ||
144 | 152 | ||
145 | if (pcm_data_size == 0) { | 153 | /* At all times we need to write a full 'len' bytes to stream. */ |
146 | return; | ||
147 | } | ||
148 | |||
149 | datalen = (len > pcm_data_size) ? pcm_data_size : len; | ||
150 | 154 | ||
151 | memcpy(stream, pcm_data, datalen); | 155 | if (pcm_data_size <= len) { |
156 | /* Play what we have */ | ||
157 | memcpy(stream, pcm_data, pcm_data_size); | ||
152 | 158 | ||
153 | pcm_data_size -= datalen; | 159 | if (debug != NULL) { |
154 | pcm_data += datalen; | 160 | fwrite(pcm_data, sizeof(Uint8), pcm_data_size, debug); |
161 | } | ||
155 | 162 | ||
156 | if (pcm_data_size == 0) { | 163 | offset = pcm_data_size; |
157 | void (*get_more)(unsigned char**, size_t*) = callback_for_more; | 164 | datalen = len - pcm_data_size; |
158 | if (get_more) { | 165 | |
159 | get_more(&pcm_data, &pcm_data_size); | 166 | /* Get some more */ |
160 | } else { | 167 | callback_for_more(&pcm_data, &pcm_data_size); |
161 | pcm_data_size = 0; | 168 | |
162 | pcm_data = NULL; | 169 | /* Play enough of that to keep the audio buffer full */ |
170 | memcpy(stream + offset, pcm_data, datalen); | ||
171 | |||
172 | if (debug != NULL) { | ||
173 | fwrite(pcm_data, sizeof(Uint8), datalen, debug); | ||
174 | } | ||
175 | } else { | ||
176 | datalen = len; | ||
177 | memcpy(stream, pcm_data, len); | ||
178 | |||
179 | if (debug != NULL) { | ||
180 | fwrite(pcm_data, sizeof(Uint8), len, debug); | ||
163 | } | 181 | } |
164 | } | 182 | } |
183 | |||
184 | pcm_data_size -= datalen; | ||
185 | pcm_data += datalen; | ||
165 | } | 186 | } |
166 | 187 | ||
167 | int pcm_init(void) | 188 | int pcm_init(void) |
168 | { | 189 | { |
169 | SDL_AudioSpec fmt; | 190 | SDL_AudioSpec fmt; |
191 | FILE *debug = NULL; | ||
192 | |||
193 | if (debug_audio) { | ||
194 | debug = fopen("audiodebug.raw", "wb"); | ||
195 | } | ||
170 | 196 | ||
171 | /* Set 16-bit stereo audio at 44Khz */ | 197 | /* Set 16-bit stereo audio at 44Khz */ |
172 | fmt.freq = 44100; | 198 | fmt.freq = 44100; |
@@ -174,14 +200,14 @@ int pcm_init(void) | |||
174 | fmt.channels = 2; | 200 | fmt.channels = 2; |
175 | fmt.samples = 512; | 201 | fmt.samples = 512; |
176 | fmt.callback = sdl_audio_callback; | 202 | fmt.callback = sdl_audio_callback; |
177 | fmt.userdata = NULL; | 203 | fmt.userdata = debug; |
178 | 204 | ||
179 | /* Open the audio device and start playing sound! */ | 205 | /* Open the audio device and start playing sound! */ |
180 | if(SDL_OpenAudio(&fmt, NULL) < 0) { | 206 | if(SDL_OpenAudio(&fmt, NULL) < 0) { |
181 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | 207 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
182 | return -1; | 208 | return -1; |
183 | } | 209 | } |
184 | 210 | ||
185 | sdl_dma_stop(); | 211 | sdl_dma_stop(); |
186 | 212 | ||
187 | return 0; | 213 | return 0; |
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 1e36bfa223..3d802ba4de 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c | |||
@@ -51,7 +51,9 @@ SDL_Thread *gui_thread; | |||
51 | SDL_TimerID tick_timer_id; | 51 | SDL_TimerID tick_timer_id; |
52 | 52 | ||
53 | bool lcd_display_redraw = true; /* Used for player simulator */ | 53 | bool lcd_display_redraw = true; /* Used for player simulator */ |
54 | char having_new_lcd=true; /* Used for player simulator */ | 54 | char having_new_lcd = true; /* Used for player simulator */ |
55 | |||
56 | bool debug_audio = false; | ||
55 | 57 | ||
56 | long start_tick; | 58 | long start_tick; |
57 | 59 | ||
@@ -190,7 +192,10 @@ int main(int argc, char *argv[]) | |||
190 | if (argc >= 1) { | 192 | if (argc >= 1) { |
191 | int x; | 193 | int x; |
192 | for (x = 1; x < argc; x++) { | 194 | for (x = 1; x < argc; x++) { |
193 | if (!strcmp("--background", argv[x])) { | 195 | if (!strcmp("--debugaudio", argv[x])) { |
196 | debug_audio = true; | ||
197 | printf("Writing debug audio file.\n"); | ||
198 | } else if (!strcmp("--background", argv[x])) { | ||
194 | background = true; | 199 | background = true; |
195 | printf("Using background image.\n"); | 200 | printf("Using background image.\n"); |
196 | } else if (!strcmp("--old_lcd", argv[x])) { | 201 | } else if (!strcmp("--old_lcd", argv[x])) { |
@@ -203,6 +208,7 @@ int main(int argc, char *argv[]) | |||
203 | } else { | 208 | } else { |
204 | printf("rockboxui\n"); | 209 | printf("rockboxui\n"); |
205 | printf("Arguments:\n"); | 210 | printf("Arguments:\n"); |
211 | printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); | ||
206 | printf(" --background \t Use background image of hardware\n"); | 212 | printf(" --background \t Use background image of hardware\n"); |
207 | printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); | 213 | printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); |
208 | printf(" --zoom \t window zoom (will disable backgrounds)\n"); | 214 | printf(" --zoom \t window zoom (will disable backgrounds)\n"); |