1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2002 Dave Chapman
11 * oss_sound - a sound driver for Linux (and others?) OSS audio
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.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
24 #include <linux/soundcard.h>
25 #include "../common/sound.h"
27 /* We want to use the "real" open in this file */
30 int init_sound(sound_t
* sound
) {
31 sound
->fd
=open("/dev/dsp", O_WRONLY
);
36 fprintf(stderr
,"Can not open /dev/dsp - simulating sound output\n");
41 int config_sound(sound_t
* sound
, int sound_freq
, int channels
) {
42 int format
=AFMT_U16_LE
;
43 int setting
=0x000C000D; // 12 fragments size 8kb ? WHAT IS THIS?
45 sound
->freq
=sound_freq
;
46 sound
->channels
=channels
;
49 if (ioctl(sound
->fd
,SNDCTL_DSP_SETFRAGMENT
,&setting
)==-1) {
50 perror("SNDCTL_DSP_SETFRAGMENT");
53 if (ioctl(sound
->fd
,SNDCTL_DSP_CHANNELS
,&channels
)==-1) {
54 perror("SNDCTL_DSP_STEREO");
56 if (channels
==0) { fprintf(stderr
,"Warning, only mono supported\n"); }
58 if (ioctl(sound
->fd
,SNDCTL_DSP_SETFMT
,&format
)==-1) {
59 perror("SNDCTL_DSP_SETFMT");
62 if (ioctl(sound
->fd
,SNDCTL_DSP_SPEED
,&sound_freq
)==-1) {
63 perror("SNDCTL_DSP_SPEED");
68 int output_sound(sound_t
* sound
,const void* buf
, int count
) {
72 return(write(sound
->fd
,buf
,count
));
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);
81 void close_sound(sound_t
* sound
) {
82 if (sound
->fd
) close(sound
->fd
);