blob: 06d9c014ffa9b9edb498493bde9a08262af2f46e [file] [log] [blame]
Daniel Stenbergfebb52f2005-07-14 21:46:07 +00001/***************************************************************************
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
Dan Everton3ba00602006-02-13 21:46:28 +000024#include <stdbool.h>
Daniel Stenbergfebb52f2005-07-14 21:46:07 +000025#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>
Daniel Stenberg741a7152005-07-15 21:12:18 +000031#include <sys/soundcard.h>
Daniel Stenbergfebb52f2005-07-14 21:46:07 +000032
33#include "sound.h"
34
Dan Everton3ba00602006-02-13 21:46:28 +000035static bool playing = false;
36
Daniel Stenbergfebb52f2005-07-14 21:46:07 +000037int sim_sound_init(void)
38{
39 int fd;
40 int pcmbits;
41 int rc;
42 int channels;
43 int rate;
44
Stepan Moskovchenko2be160a2005-08-07 22:26:42 +000045 fd = open("/dev/dsp", O_WRONLY);
Daniel Stenbergfebb52f2005-07-14 21:46:07 +000046 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
64void sim_sound_play(int soundfd, char *buffer, long len)
65{
66 write(soundfd, buffer, len);
67}
68
69void 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 }
Daniel Stenbergee76cc32005-11-28 09:36:26 +000090 sim_sound_play(soundfd, (char *)buf, size);
Daniel Stenbergfebb52f2005-07-14 21:46:07 +000091 usleep(10000);
92 } while(size);
93
94 } while(1);
95
96}
97
Dan Everton3ba00602006-02-13 21:46:28 +000098/* Stubs for PCM audio playback. */
99bool pcm_is_playing(void)
100{
101 return playing;
102}
103
104void pcm_mute(bool state)
105{
106 (void)state;
107}
108
109void pcm_play_pause(bool state)
110{
111 (void)state;
112}
113
114bool pcm_is_paused(void)
115{
116 return false;
117}
118
119void pcm_play_stop(void)
120{
121 playing = false;
122}
123
124void pcm_init(void)
125{
126}
127
128void (*sound_get_pcm)(unsigned char** start, long* size);
129void pcm_play_data(void (*get_more)(unsigned char** start, long* size))
130{
131 sound_get_pcm = get_more;
132 playing = true;
133}
134
135long pcm_get_bytes_waiting(void)
136{
137 return 0;
138}
139
Daniel Stenbergfebb52f2005-07-14 21:46:07 +0000140#endif /* ROCKBOX_HAS_SIMSOUND */