summaryrefslogtreecommitdiff
path: root/uisimulator/x11/oss_sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/x11/oss_sound.c')
-rw-r--r--uisimulator/x11/oss_sound.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/uisimulator/x11/oss_sound.c b/uisimulator/x11/oss_sound.c
new file mode 100644
index 0000000000..6827842689
--- /dev/null
+++ b/uisimulator/x11/oss_sound.c
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2002 Dave Chapman
10 *
11 * oss_sound - a sound driver for Linux (and others?) OSS audio
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <stdio.h>
22#include <fcntl.h>
23
24#include <linux/soundcard.h>
25#include "oss_sound.h"
26
27/* We want to use the "real" open in some cases */
28#undef open
29
30int init_sound(sound_t* sound) {
31 *sound=open("/dev/dsp", O_WRONLY);
32
33 if (sound < 0) {
34 fprintf(stderr,"Can not open /dev/dsp - Aborting - sound=%d\n",sound);
35 exit(-1);
36 }
37}
38
39int config_sound(sound_t* sound, int sound_freq, int channels) {
40 int format=AFMT_U16_LE;
41 int setting=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
42
43 if (ioctl(*sound,SNDCTL_DSP_SETFRAGMENT,&setting)==-1) {
44 perror("SNDCTL_DSP_SETFRAGMENT");
45 }
46
47 if (ioctl(*sound,SNDCTL_DSP_CHANNELS,&channels)==-1) {
48 perror("SNDCTL_DSP_STEREO");
49 }
50 if (channels==0) { fprintf(stderr,"Warning, only mono supported\n"); }
51
52 if (ioctl(*sound,SNDCTL_DSP_SETFMT,&format)==-1) {
53 perror("SNDCTL_DSP_SETFMT");
54 }
55
56 if (ioctl(*sound,SNDCTL_DSP_SPEED,&sound_freq)==-1) {
57 perror("SNDCTL_DSP_SPEED");
58 }
59}
60
61int output_sound(sound_t* sound,const void* buf, int count) {
62 return(write(*sound,buf,count));
63}
64
65void close_sound(sound_t* sound) {
66 if (*sound) close(*sound);
67}