summaryrefslogtreecommitdiff
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
parentdc6cd7dcb20f455f8c474b585c9bf98e79c9a2d8 (diff)
downloadrockbox-553c2567f4e21df002f45e6ddc0234999e58ad69.tar.gz
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
-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 @@
23 23
24#ifdef LINUX 24#ifdef LINUX
25 25
26/* The "sound device type" is simply the file descriptor */ 26/* The "sound device type" */
27#define sound_t int 27
28typedef struct {
29 int fd;
30 int freq;
31 int channels;
32} sound_t;
28 33
29#else 34#else
30 #ifdef WIN32 35 #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 @@
24#include <linux/soundcard.h> 24#include <linux/soundcard.h>
25#include "../common/sound.h" 25#include "../common/sound.h"
26 26
27/* We want to use the "real" open in some cases */ 27/* We want to use the "real" open in this file */
28#undef open 28#undef open
29 29
30int init_sound(sound_t* sound) { 30int init_sound(sound_t* sound) {
31 *sound=open("/dev/dsp", O_WRONLY); 31 sound->fd=open("/dev/dsp", O_WRONLY);
32 sound->freq=-1;
33 sound->channels=-1;
32 34
33 if (sound < 0) { 35 if (sound->fd <= 0) {
34 fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound); 36 fprintf(stderr,"Can not open /dev/dsp - simulating sound output\n");
35 exit(-1); 37 sound->fd=0;
36 } 38 }
37} 39}
38 40
@@ -40,28 +42,43 @@ int config_sound(sound_t* sound, int sound_freq, int channels) {
40 int format=AFMT_U16_LE; 42 int format=AFMT_U16_LE;
41 int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS? 43 int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
42 44
43 if (ioctl(*sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) { 45 sound->freq=sound_freq;
44 perror("SNDCTL_DSP_SETFRAGMENT"); 46 sound->channels=channels;
45 }
46 47
47 if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) { 48 if (sound->fd) {
48 perror("SNDCTL_DSP_STEREO"); 49 if (ioctl(sound->fd,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
49 } 50 perror("SNDCTL_DSP_SETFRAGMENT");
50 if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); } 51 }
51 52
52 if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) { 53 if (ioctl(sound->fd,SNDCTL_DSP_CHANNELS,&channels)==-1) {
53 perror("SNDCTL_DSP_SETFMT"); 54 perror("SNDCTL_DSP_STEREO");
54 } 55 }
56 if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
55 57
56 if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) { 58 if (ioctl(sound->fd,SNDCTL_DSP_SETFMT,&format)==-1) {
57 perror("SNDCTL_DSP_SPEED"); 59 perror("SNDCTL_DSP_SETFMT");
60 }
61
62 if (ioctl(sound->fd,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
63 perror("SNDCTL_DSP_SPEED");
64 }
58 } 65 }
59} 66}
60 67
61int output_sound(sound_t* sound,const void* buf, int count) { 68int output_sound(sound_t* sound,const void* buf, int count) {
62 return(write(*sound,buf,count)); 69 unsigned long long t;
70
71 if (sound->fd) {
72 return(write(sound->fd,buf,count));
73 } else {
74 t=(unsigned int)(((unsigned int)(1000000/sound->channels)*count)/sound->freq);
75// fprintf(stderr,"writing %d bytes at %d frequency - sleeping for %u microseconds\n",count,sound->freq,t);
76 usleep(t);
77 return(count);
78 }
63} 79}
64 80
65void close_sound(sound_t* sound) { 81void close_sound(sound_t* sound) {
66 if (*sound) close(*sound); 82 if (sound->fd) close(sound->fd);
83 sound->fd=-1;
67} 84}