diff options
Diffstat (limited to 'uisimulator/x11/mpegplay.c')
-rw-r--r-- | uisimulator/x11/mpegplay.c | 47 |
1 files changed, 9 insertions, 38 deletions
diff --git a/uisimulator/x11/mpegplay.c b/uisimulator/x11/mpegplay.c index 0ed3ac89e3..da02ec9de4 100644 --- a/uisimulator/x11/mpegplay.c +++ b/uisimulator/x11/mpegplay.c | |||
@@ -33,10 +33,8 @@ | |||
33 | 33 | ||
34 | #include <stdio.h> | 34 | #include <stdio.h> |
35 | #include <mad.h> | 35 | #include <mad.h> |
36 | #include <linux/soundcard.h> | ||
37 | 36 | ||
38 | /* We want to use the "real" open in some cases */ | 37 | #include "oss_sound.h" |
39 | #undef open | ||
40 | 38 | ||
41 | /* The "dither" code to convert the 24-bit samples produced by libmad was | 39 | /* The "dither" code to convert the 24-bit samples produced by libmad was |
42 | taken from the coolplayer project - coolplayer.sourceforge.net */ | 40 | taken from the coolplayer project - coolplayer.sourceforge.net */ |
@@ -52,7 +50,6 @@ struct mad_stream Stream; | |||
52 | struct mad_frame Frame; | 50 | struct mad_frame Frame; |
53 | struct mad_synth Synth; | 51 | struct mad_synth Synth; |
54 | mad_timer_t Timer; | 52 | mad_timer_t Timer; |
55 | int sound; | ||
56 | 53 | ||
57 | /* | 54 | /* |
58 | * NAME: prng() | 55 | * NAME: prng() |
@@ -169,29 +166,6 @@ void pack_pcm(unsigned char **pcm, unsigned int nsamples, | |||
169 | } | 166 | } |
170 | } | 167 | } |
171 | 168 | ||
172 | void init_oss(int sound, int sound_freq, int channels) { | ||
173 | int format=AFMT_U16_LE; | ||
174 | int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS? | ||
175 | |||
176 | if (ioctl(sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) { | ||
177 | perror("SNDCTL_DSP_SETFRAGMENT"); | ||
178 | } | ||
179 | |||
180 | if (ioctl(sound,SNDCTL_DSP_STEREO,&channels)==-1) { | ||
181 | perror("SNDCTL_DSP_STEREO"); | ||
182 | } | ||
183 | if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); } | ||
184 | |||
185 | if (ioctl(sound,SNDCTL_DSP_SETFMT,&format)==-1) { | ||
186 | perror("SNDCTL_DSP_SETFMT"); | ||
187 | } | ||
188 | |||
189 | // fprintf(stderr,"SETTING /dev/dsp to %dHz\n",sound_freq); | ||
190 | if (ioctl(sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) { | ||
191 | perror("SNDCTL_DSP_SPEED"); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | #define INPUT_BUFFER_SIZE (5*8192) | 169 | #define INPUT_BUFFER_SIZE (5*8192) |
196 | #define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */ | 170 | #define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */ |
197 | int mpeg_play(char* fname) | 171 | int mpeg_play(char* fname) |
@@ -203,22 +177,19 @@ int mpeg_play(char* fname) | |||
203 | int Status=0, | 177 | int Status=0, |
204 | i; | 178 | i; |
205 | unsigned long FrameCount=0; | 179 | unsigned long FrameCount=0; |
206 | int sound,fd; | 180 | sound_t sound; |
181 | int fd; | ||
207 | mp3entry mp3; | 182 | mp3entry mp3; |
208 | register signed int s0, s1; | 183 | register signed int s0, s1; |
209 | static struct dither d0, d1; | 184 | static struct dither d0, d1; |
210 | 185 | ||
211 | mp3info(&mp3, fname); | 186 | mp3info(&mp3, fname); |
212 | 187 | ||
213 | #undef open | 188 | init_sound(&sound); |
214 | sound=open("/dev/dsp", O_WRONLY); | ||
215 | |||
216 | if (sound < 0) { | ||
217 | fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound); | ||
218 | exit(-1); | ||
219 | } | ||
220 | 189 | ||
221 | init_oss(sound,mp3.frequency,2); | 190 | /* Configure sound device for this file - always select Stereo because |
191 | some sound cards don't support mono */ | ||
192 | config_sound(&sound,mp3.frequency,2); | ||
222 | 193 | ||
223 | fd=x11_open(fname,O_RDONLY); | 194 | fd=x11_open(fname,O_RDONLY); |
224 | if (fd < 0) { | 195 | if (fd < 0) { |
@@ -306,7 +277,7 @@ int mpeg_play(char* fname) | |||
306 | /* Flush the buffer if it is full. */ | 277 | /* Flush the buffer if it is full. */ |
307 | if(OutputPtr==OutputBufferEnd) | 278 | if(OutputPtr==OutputBufferEnd) |
308 | { | 279 | { |
309 | if(write(sound,OutputBuffer,OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) | 280 | if(output_sound(&sound,OutputBuffer,OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) |
310 | { | 281 | { |
311 | fprintf(stderr,"PCM write error.\n"); | 282 | fprintf(stderr,"PCM write error.\n"); |
312 | Status=2; | 283 | Status=2; |
@@ -348,7 +319,7 @@ int mpeg_play(char* fname) | |||
348 | fprintf(stderr,"%lu frames decoded (%s).\n",FrameCount,Buffer); | 319 | fprintf(stderr,"%lu frames decoded (%s).\n",FrameCount,Buffer); |
349 | } | 320 | } |
350 | 321 | ||
351 | close(sound); | 322 | close_sound(&sound); |
352 | /* That's the end of the world (in the H. G. Wells way). */ | 323 | /* That's the end of the world (in the H. G. Wells way). */ |
353 | return(Status); | 324 | return(Status); |
354 | } | 325 | } |