summaryrefslogtreecommitdiffstats
path: root/uisimulator
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2002-05-15 07:27:48 +0000
committerDave Chapman <dave@dchapman.com>2002-05-15 07:27:48 +0000
commit553c2567f4e21df002f45e6ddc0234999e58ad69 (patch)
treef562bea092ace62458b08361a4d7b9306230c8e2 /uisimulator
parentdc6cd7dcb20f455f8c474b585c9bf98e79c9a2d8 (diff)
downloadrockbox-553c2567f4e21df002f45e6ddc0234999e58ad69.tar.gz
rockbox-553c2567f4e21df002f45e6ddc0234999e58ad69.tar.bz2
rockbox-553c2567f4e21df002f45e6ddc0234999e58ad69.zip
added playback simulator if /dev/dsp is unavailable
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@581 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/common/sound.h9
-rw-r--r--uisimulator/x11/oss_sound.c55
2 files changed, 43 insertions, 21 deletions
diff --git a/uisimulator/common/sound.h b/uisimulator/common/sound.h
index 4da5ce9f08..cb9afcb187 100644
--- a/uisimulator/common/sound.h
+++ b/uisimulator/common/sound.h
@@ -23,8 +23,13 @@
#ifdef LINUX
-/* The "sound device type" is simply the file descriptor */
-#define sound_t int
+/* The "sound device type" */
+
+typedef struct {
+ int fd;
+ int freq;
+ int channels;
+} sound_t;
#else
#ifdef WIN32
diff --git a/uisimulator/x11/oss_sound.c b/uisimulator/x11/oss_sound.c
index 853b70d57f..e69c403acd 100644
--- a/uisimulator/x11/oss_sound.c
+++ b/uisimulator/x11/oss_sound.c
@@ -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;
}