diff options
-rw-r--r-- | uisimulator/x11/Makefile | 2 | ||||
-rw-r--r-- | uisimulator/x11/mpegplay.c | 47 | ||||
-rw-r--r-- | uisimulator/x11/oss_sound.c | 67 | ||||
-rw-r--r-- | uisimulator/x11/oss_sound.h | 28 |
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 \ button-x11.c io.c sleep.c $(APPS) $(FIRMSRCS) ifdef MPEG_PLAY - 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 + 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 DEFINES += -DMPEG_PLAY -DFPM_DEFAULT -DHAVE_CONFIG_H INCLUDES += -I$(LIBMADDIR) endif 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 @@ #include <stdio.h> #include <mad.h> -#include <linux/soundcard.h> -/* We want to use the "real" open in some cases */ -#undef open +#include "oss_sound.h" /* The "dither" code to convert the 24-bit samples produced by libmad was taken from the coolplayer project - coolplayer.sourceforge.net */ @@ -52,7 +50,6 @@ struct mad_stream Stream; struct mad_frame Frame; struct mad_synth Synth; mad_timer_t Timer; -int sound; /* * NAME: prng() @@ -169,29 +166,6 @@ void pack_pcm(unsigned char **pcm, unsigned int nsamples, } } -void init_oss(int sound, int sound_freq, int channels) { - int format=AFMT_U16_LE; - int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS? - - if (ioctl(sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) { - perror("SNDCTL_DSP_SETFRAGMENT"); - } - - if (ioctl(sound,SNDCTL_DSP_STEREO,&channels)==-1) { - perror("SNDCTL_DSP_STEREO"); - } - if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); } - - if (ioctl(sound,SNDCTL_DSP_SETFMT,&format)==-1) { - perror("SNDCTL_DSP_SETFMT"); - } - -// fprintf(stderr,"SETTING /dev/dsp to %dHz\n",sound_freq); - if (ioctl(sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) { - perror("SNDCTL_DSP_SPEED"); - } -} - #define INPUT_BUFFER_SIZE (5*8192) #define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */ int mpeg_play(char* fname) @@ -203,22 +177,19 @@ int mpeg_play(char* fname) int Status=0, i; unsigned long FrameCount=0; - int sound,fd; + sound_t sound; + int fd; mp3entry mp3; register signed int s0, s1; static struct dither d0, d1; mp3info(&mp3, fname); - #undef open - sound=open("/dev/dsp", O_WRONLY); - - if (sound < 0) { - fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound); - exit(-1); - } + init_sound(&sound); - init_oss(sound,mp3.frequency,2); + /* Configure sound device for this file - always select Stereo because + some sound cards don't support mono */ + config_sound(&sound,mp3.frequency,2); fd=x11_open(fname,O_RDONLY); if (fd < 0) { @@ -306,7 +277,7 @@ int mpeg_play(char* fname) /* Flush the buffer if it is full. */ if(OutputPtr==OutputBufferEnd) { - if(write(sound,OutputBuffer,OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) + if(output_sound(&sound,OutputBuffer,OUTPUT_BUFFER_SIZE)!=OUTPUT_BUFFER_SIZE) { fprintf(stderr,"PCM write error.\n"); Status=2; @@ -348,7 +319,7 @@ int mpeg_play(char* fname) fprintf(stderr,"%lu frames decoded (%s).\n",FrameCount,Buffer); } - close(sound); + close_sound(&sound); /* That's the end of the world (in the H. G. Wells way). */ return(Status); } 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2002 Dave Chapman + * + * oss_sound - a sound driver for Linux (and others?) OSS audio + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include <stdio.h> +#include <fcntl.h> + +#include <linux/soundcard.h> +#include "oss_sound.h" + +/* We want to use the "real" open in some cases */ +#undef open + +int init_sound(sound_t* sound) { + *sound=open("/dev/dsp", O_WRONLY); + + if (sound < 0) { + fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound); + exit(-1); + } +} + +int config_sound(sound_t* sound, int sound_freq, int channels) { + int format=AFMT_U16_LE; + int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS? + + if (ioctl(*sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) { + perror("SNDCTL_DSP_SETFRAGMENT"); + } + + if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) { + perror("SNDCTL_DSP_STEREO"); + } + if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); } + + if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) { + perror("SNDCTL_DSP_SETFMT"); + } + + if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) { + perror("SNDCTL_DSP_SPEED"); + } +} + +int output_sound(sound_t* sound,const void* buf, int count) { + return(write(*sound,buf,count)); +} + +void close_sound(sound_t* sound) { + if (*sound) close(*sound); +} 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2002 Dave Chapman + * + * oss_sound - a sound driver for Linux (and others?) OSS audio + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +/* The "sound device type" is simply the file descriptor */ +#define sound_t int + +int init_sound(sound_t* sound); +int config_sound(sound_t* sound, int sound_freq, int channels); +void close_sound(sound_t* sound); +int output_sound(sound_t* sound,const void* buf, int count); |