forked from len0rd/rockbox
added playback simulator if /dev/dsp is unavailable
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@581 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
dc6cd7dcb2
commit
553c2567f4
2 changed files with 43 additions and 21 deletions
|
|
@ -24,15 +24,17 @@
|
|||
#include <linux/soundcard.h>
|
||||
#include "../common/sound.h"
|
||||
|
||||
/* We want to use the "real" open in some cases */
|
||||
/* We want to use the "real" open in this file */
|
||||
#undef open
|
||||
|
||||
int init_sound(sound_t* sound) {
|
||||
*sound=open("/dev/dsp", O_WRONLY);
|
||||
sound->fd=open("/dev/dsp", O_WRONLY);
|
||||
sound->freq=-1;
|
||||
sound->channels=-1;
|
||||
|
||||
if (sound < 0) {
|
||||
fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound);
|
||||
exit(-1);
|
||||
if (sound->fd <= 0) {
|
||||
fprintf(stderr,"Can not open /dev/dsp - simulating sound output\n");
|
||||
sound->fd=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,28 +42,43 @@ 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");
|
||||
}
|
||||
sound->freq=sound_freq;
|
||||
sound->channels=channels;
|
||||
|
||||
if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) {
|
||||
perror("SNDCTL_DSP_STEREO");
|
||||
}
|
||||
if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
|
||||
if (sound->fd) {
|
||||
if (ioctl(sound->fd,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
|
||||
perror("SNDCTL_DSP_SETFRAGMENT");
|
||||
}
|
||||
|
||||
if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) {
|
||||
perror("SNDCTL_DSP_SETFMT");
|
||||
}
|
||||
if (ioctl(sound->fd,SNDCTL_DSP_CHANNELS,&channels)==-1) {
|
||||
perror("SNDCTL_DSP_STEREO");
|
||||
}
|
||||
if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
|
||||
|
||||
if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
|
||||
perror("SNDCTL_DSP_SPEED");
|
||||
if (ioctl(sound->fd,SNDCTL_DSP_SETFMT,&format)==-1) {
|
||||
perror("SNDCTL_DSP_SETFMT");
|
||||
}
|
||||
|
||||
if (ioctl(sound->fd,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));
|
||||
unsigned long long t;
|
||||
|
||||
if (sound->fd) {
|
||||
return(write(sound->fd,buf,count));
|
||||
} else {
|
||||
t=(unsigned int)(((unsigned int)(1000000/sound->channels)*count)/sound->freq);
|
||||
// fprintf(stderr,"writing %d bytes at %d frequency - sleeping for %u microseconds\n",count,sound->freq,t);
|
||||
usleep(t);
|
||||
return(count);
|
||||
}
|
||||
}
|
||||
|
||||
void close_sound(sound_t* sound) {
|
||||
if (*sound) close(*sound);
|
||||
if (sound->fd) close(sound->fd);
|
||||
sound->fd=-1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue