mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 21:25:19 -05:00
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
|
|
@ -23,8 +23,13 @@
|
||||||
|
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
|
|
||||||
/* The "sound device type" is simply the file descriptor */
|
/* The "sound device type" */
|
||||||
#define sound_t int
|
|
||||||
|
typedef struct {
|
||||||
|
int fd;
|
||||||
|
int freq;
|
||||||
|
int channels;
|
||||||
|
} sound_t;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
||||||
|
|
@ -24,15 +24,17 @@
|
||||||
#include <linux/soundcard.h>
|
#include <linux/soundcard.h>
|
||||||
#include "../common/sound.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
|
#undef open
|
||||||
|
|
||||||
int init_sound(sound_t* sound) {
|
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) {
|
if (sound->fd <= 0) {
|
||||||
fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound);
|
fprintf(stderr,"Can not open /dev/dsp - simulating sound output\n");
|
||||||
exit(-1);
|
sound->fd=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,28 +42,43 @@ int config_sound(sound_t* sound, int sound_freq, int channels) {
|
||||||
int format=AFMT_U16_LE;
|
int format=AFMT_U16_LE;
|
||||||
int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
|
int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
|
||||||
|
|
||||||
if (ioctl(*sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
|
sound->freq=sound_freq;
|
||||||
|
sound->channels=channels;
|
||||||
|
|
||||||
|
if (sound->fd) {
|
||||||
|
if (ioctl(sound->fd,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
|
||||||
perror("SNDCTL_DSP_SETFRAGMENT");
|
perror("SNDCTL_DSP_SETFRAGMENT");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) {
|
if (ioctl(sound->fd,SNDCTL_DSP_CHANNELS,&channels)==-1) {
|
||||||
perror("SNDCTL_DSP_STEREO");
|
perror("SNDCTL_DSP_STEREO");
|
||||||
}
|
}
|
||||||
if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
|
if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
|
||||||
|
|
||||||
if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) {
|
if (ioctl(sound->fd,SNDCTL_DSP_SETFMT,&format)==-1) {
|
||||||
perror("SNDCTL_DSP_SETFMT");
|
perror("SNDCTL_DSP_SETFMT");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
|
if (ioctl(sound->fd,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
|
||||||
perror("SNDCTL_DSP_SPEED");
|
perror("SNDCTL_DSP_SPEED");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int output_sound(sound_t* sound,const void* buf, int count) {
|
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) {
|
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