summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2002-05-12 12:30:14 +0000
committerDave Chapman <dave@dchapman.com>2002-05-12 12:30:14 +0000
commitef5f97b4216042121a114afd5a9f1380283fb095 (patch)
tree2048fd699cba83edc8104c6ccadaee2e5d7b7a7d
parentac845a022698e3ba6cf2e089c89216b8a8544aef (diff)
downloadrockbox-ef5f97b4216042121a114afd5a9f1380283fb095.tar.gz
rockbox-ef5f97b4216042121a114afd5a9f1380283fb095.zip
abstracted the sound output interface
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@553 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/x11/Makefile2
-rw-r--r--uisimulator/x11/mpegplay.c47
-rw-r--r--uisimulator/x11/oss_sound.c67
-rw-r--r--uisimulator/x11/oss_sound.h28
4 files changed, 105 insertions, 39 deletions
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile
index ae19b38862..6bbebd6c5d 100644
--- a/uisimulator/x11/Makefile
+++ b/uisimulator/x11/Makefile
@@ -61,7 +61,7 @@ SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c \
61 button-x11.c io.c sleep.c $(APPS) $(FIRMSRCS) 61 button-x11.c io.c sleep.c $(APPS) $(FIRMSRCS)
62 62
63ifdef MPEG_PLAY 63ifdef MPEG_PLAY
64 SRCS += mpegplay.c bit.c decoder.c fixed.c frame.c huffman.c layer12.c layer3.c stream.c synth.c timer.c version.c 64 SRCS += mpegplay.c oss_sound.c bit.c decoder.c fixed.c frame.c huffman.c layer12.c layer3.c stream.c synth.c timer.c version.c
65 DEFINES += -DMPEG_PLAY -DFPM_DEFAULT -DHAVE_CONFIG_H 65 DEFINES += -DMPEG_PLAY -DFPM_DEFAULT -DHAVE_CONFIG_H
66 INCLUDES += -I$(LIBMADDIR) 66 INCLUDES += -I$(LIBMADDIR)
67endif 67endif
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;
52struct mad_frame Frame; 50struct mad_frame Frame;
53struct mad_synth Synth; 51struct mad_synth Synth;
54mad_timer_t Timer; 52mad_timer_t Timer;
55int 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
172void 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. */
197int mpeg_play(char* fname) 171int 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}
diff --git a/uisimulator/x11/oss_sound.c b/uisimulator/x11/oss_sound.c
new file mode 100644
index 0000000000..6827842689
--- /dev/null
+++ b/uisimulator/x11/oss_sound.c
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2002 Dave Chapman
10 *
11 * oss_sound - a sound driver for Linux (and others?) OSS audio
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <stdio.h>
22#include <fcntl.h>
23
24#include <linux/soundcard.h>
25#include "oss_sound.h"
26
27/* We want to use the "real" open in some cases */
28#undef open
29
30int init_sound(sound_t* sound) {
31 *sound=open("/dev/dsp", O_WRONLY);
32
33 if (sound < 0) {
34 fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound);
35 exit(-1);
36 }
37}
38
39int config_sound(sound_t* sound, int sound_freq, int channels) {
40 int format=AFMT_U16_LE;
41 int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
42
43 if (ioctl(*sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
44 perror("SNDCTL_DSP_SETFRAGMENT");
45 }
46
47 if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) {
48 perror("SNDCTL_DSP_STEREO");
49 }
50 if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
51
52 if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) {
53 perror("SNDCTL_DSP_SETFMT");
54 }
55
56 if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
57 perror("SNDCTL_DSP_SPEED");
58 }
59}
60
61int output_sound(sound_t* sound,const void* buf, int count) {
62 return(write(*sound,buf,count));
63}
64
65void close_sound(sound_t* sound) {
66 if (*sound) close(*sound);
67}
diff --git a/uisimulator/x11/oss_sound.h b/uisimulator/x11/oss_sound.h
new file mode 100644
index 0000000000..919ce1aab5
--- /dev/null
+++ b/uisimulator/x11/oss_sound.h
@@ -0,0 +1,28 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2002 Dave Chapman
10 *
11 * oss_sound - a sound driver for Linux (and others?) OSS audio
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21
22/* The "sound device type" is simply the file descriptor */
23#define sound_t int
24
25int init_sound(sound_t* sound);
26int config_sound(sound_t* sound, int sound_freq, int channels);
27void close_sound(sound_t* sound);
28int output_sound(sound_t* sound,const void* buf, int count);