diff options
Diffstat (limited to 'uisimulator/x11/sound.c')
-rw-r--r-- | uisimulator/x11/sound.c | 140 |
1 files changed, 0 insertions, 140 deletions
diff --git a/uisimulator/x11/sound.c b/uisimulator/x11/sound.c deleted file mode 100644 index 06d9c014ff..0000000000 --- a/uisimulator/x11/sound.c +++ /dev/null | |||
@@ -1,140 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "autoconf.h" | ||
21 | |||
22 | #ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ | ||
23 | |||
24 | #include <stdbool.h> | ||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <unistd.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <fcntl.h> | ||
30 | #include <sys/ioctl.h> | ||
31 | #include <sys/soundcard.h> | ||
32 | |||
33 | #include "sound.h" | ||
34 | |||
35 | static bool playing = false; | ||
36 | |||
37 | int sim_sound_init(void) | ||
38 | { | ||
39 | int fd; | ||
40 | int pcmbits; | ||
41 | int rc; | ||
42 | int channels; | ||
43 | int rate; | ||
44 | |||
45 | fd = open("/dev/dsp", O_WRONLY); | ||
46 | if(-1 == fd) | ||
47 | return 1; | ||
48 | |||
49 | pcmbits = 16; | ||
50 | rc = ioctl(fd, SOUND_PCM_WRITE_BITS, &pcmbits); | ||
51 | rc = ioctl(fd, SOUND_PCM_READ_BITS, &pcmbits); | ||
52 | |||
53 | channels = 2; /* Number of channels, 1=mono */ | ||
54 | rc = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &channels); | ||
55 | rc = ioctl(fd, SOUND_PCM_READ_CHANNELS, &channels); | ||
56 | |||
57 | rate = 44100; /* Yeah. sampling rate */ | ||
58 | rc = ioctl(fd, SOUND_PCM_WRITE_RATE, &rate); | ||
59 | rc = ioctl(fd, SOUND_PCM_READ_RATE, &rate); | ||
60 | |||
61 | return fd; | ||
62 | } | ||
63 | |||
64 | void sim_sound_play(int soundfd, char *buffer, long len) | ||
65 | { | ||
66 | write(soundfd, buffer, len); | ||
67 | } | ||
68 | |||
69 | void sound_playback_thread(void) | ||
70 | { | ||
71 | int soundfd = sim_sound_init(); | ||
72 | unsigned char *buf; | ||
73 | long size; | ||
74 | |||
75 | while(-1 == soundfd) | ||
76 | sleep(100000); /* wait forever, can't play sound! */ | ||
77 | |||
78 | do { | ||
79 | |||
80 | while(!sound_get_pcm) | ||
81 | /* TODO: fix a fine thread-synch mechanism here */ | ||
82 | usleep(10000); | ||
83 | |||
84 | do { | ||
85 | sound_get_pcm(&buf, &size); | ||
86 | if(!size) { | ||
87 | sound_get_pcm = NULL; | ||
88 | break; | ||
89 | } | ||
90 | sim_sound_play(soundfd, (char *)buf, size); | ||
91 | usleep(10000); | ||
92 | } while(size); | ||
93 | |||
94 | } while(1); | ||
95 | |||
96 | } | ||
97 | |||
98 | /* Stubs for PCM audio playback. */ | ||
99 | bool pcm_is_playing(void) | ||
100 | { | ||
101 | return playing; | ||
102 | } | ||
103 | |||
104 | void pcm_mute(bool state) | ||
105 | { | ||
106 | (void)state; | ||
107 | } | ||
108 | |||
109 | void pcm_play_pause(bool state) | ||
110 | { | ||
111 | (void)state; | ||
112 | } | ||
113 | |||
114 | bool pcm_is_paused(void) | ||
115 | { | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | void pcm_play_stop(void) | ||
120 | { | ||
121 | playing = false; | ||
122 | } | ||
123 | |||
124 | void pcm_init(void) | ||
125 | { | ||
126 | } | ||
127 | |||
128 | void (*sound_get_pcm)(unsigned char** start, long* size); | ||
129 | void pcm_play_data(void (*get_more)(unsigned char** start, long* size)) | ||
130 | { | ||
131 | sound_get_pcm = get_more; | ||
132 | playing = true; | ||
133 | } | ||
134 | |||
135 | long pcm_get_bytes_waiting(void) | ||
136 | { | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | #endif /* ROCKBOX_HAS_SIMSOUND */ | ||