mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-10 13:45:10 -05:00
abstracted the sound output interface
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@553 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
ac845a0226
commit
ef5f97b421
4 changed files with 105 additions and 39 deletions
|
|
@ -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)
|
button-x11.c io.c sleep.c $(APPS) $(FIRMSRCS)
|
||||||
|
|
||||||
ifdef MPEG_PLAY
|
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
|
DEFINES += -DMPEG_PLAY -DFPM_DEFAULT -DHAVE_CONFIG_H
|
||||||
INCLUDES += -I$(LIBMADDIR)
|
INCLUDES += -I$(LIBMADDIR)
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,8 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <mad.h>
|
#include <mad.h>
|
||||||
#include <linux/soundcard.h>
|
|
||||||
|
|
||||||
/* We want to use the "real" open in some cases */
|
#include "oss_sound.h"
|
||||||
#undef open
|
|
||||||
|
|
||||||
/* The "dither" code to convert the 24-bit samples produced by libmad was
|
/* The "dither" code to convert the 24-bit samples produced by libmad was
|
||||||
taken from the coolplayer project - coolplayer.sourceforge.net */
|
taken from the coolplayer project - coolplayer.sourceforge.net */
|
||||||
|
|
@ -52,7 +50,6 @@ struct mad_stream Stream;
|
||||||
struct mad_frame Frame;
|
struct mad_frame Frame;
|
||||||
struct mad_synth Synth;
|
struct mad_synth Synth;
|
||||||
mad_timer_t Timer;
|
mad_timer_t Timer;
|
||||||
int sound;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NAME: prng()
|
* 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 INPUT_BUFFER_SIZE (5*8192)
|
||||||
#define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */
|
#define OUTPUT_BUFFER_SIZE 8192 /* Must be an integer multiple of 4. */
|
||||||
int mpeg_play(char* fname)
|
int mpeg_play(char* fname)
|
||||||
|
|
@ -203,22 +177,19 @@ int mpeg_play(char* fname)
|
||||||
int Status=0,
|
int Status=0,
|
||||||
i;
|
i;
|
||||||
unsigned long FrameCount=0;
|
unsigned long FrameCount=0;
|
||||||
int sound,fd;
|
sound_t sound;
|
||||||
|
int fd;
|
||||||
mp3entry mp3;
|
mp3entry mp3;
|
||||||
register signed int s0, s1;
|
register signed int s0, s1;
|
||||||
static struct dither d0, d1;
|
static struct dither d0, d1;
|
||||||
|
|
||||||
mp3info(&mp3, fname);
|
mp3info(&mp3, fname);
|
||||||
|
|
||||||
#undef open
|
init_sound(&sound);
|
||||||
sound=open("/dev/dsp", O_WRONLY);
|
|
||||||
|
|
||||||
if (sound < 0) {
|
/* Configure sound device for this file - always select Stereo because
|
||||||
fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound);
|
some sound cards don't support mono */
|
||||||
exit(-1);
|
config_sound(&sound,mp3.frequency,2);
|
||||||
}
|
|
||||||
|
|
||||||
init_oss(sound,mp3.frequency,2);
|
|
||||||
|
|
||||||
fd=x11_open(fname,O_RDONLY);
|
fd=x11_open(fname,O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
|
@ -306,7 +277,7 @@ int mpeg_play(char* fname)
|
||||||
/* Flush the buffer if it is full. */
|
/* Flush the buffer if it is full. */
|
||||||
if(OutputPtr==OutputBufferEnd)
|
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");
|
fprintf(stderr,"PCM write error.\n");
|
||||||
Status=2;
|
Status=2;
|
||||||
|
|
@ -348,7 +319,7 @@ int mpeg_play(char* fname)
|
||||||
fprintf(stderr,"%lu frames decoded (%s).\n",FrameCount,Buffer);
|
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). */
|
/* That's the end of the world (in the H. G. Wells way). */
|
||||||
return(Status);
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
67
uisimulator/x11/oss_sound.c
Normal file
67
uisimulator/x11/oss_sound.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
28
uisimulator/x11/oss_sound.h
Normal file
28
uisimulator/x11/oss_sound.h
Normal file
|
|
@ -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);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue