2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2002 Alexander König
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 File: tX_aduiodevice.cc
21 Description: Implements Audiodevice handling...
24 #include "tX_audiodevice.h"
26 #include <sys/types.h>
28 #include <sys/ioctl.h>
30 #include <sys/soundcard.h>
33 #include "tX_endian.h"
35 #define __USE_XOPEN // we need this for swab()
39 void tX_audiodevice :: init()
42 set_buffersize_near(globals.audiodevice_buffersize);
46 void tX_audiodevice :: set_latency_near(int milliseconds)
48 samples_per_buffer=(int) (((float) milliseconds) * 88.2);
51 int tX_audiodevice :: get_latency()
53 return ((int) (((float) samples_per_buffer) / 88.2));
56 void tX_audiodevice :: set_buffersize_near(int samples)
58 samples_per_buffer=samples;
61 int tX_audiodevice :: get_buffersize()
63 return samples_per_buffer;
66 int tX_audiodevice :: open()
68 fprintf(stderr, "tX: Error: tX_audiodevice::dev_open()\n");
72 int tX_audiodevice :: close()
74 fprintf(stderr, "tX: Error: tX_audiodevice::dev_close()\n");
78 void tX_audiodevice :: play(int16_t* dummy)
80 fprintf(stderr, "tX: Error: tX_audiodevice::play()\n");
85 int tX_audiodevice_oss :: open()
92 fd = ::open(globals.audio_device, O_WRONLY, 0);
94 /* setting buffer size */
95 buff_cfg=(globals.buff_no<<16) | globals.buff_size;
97 tX_debug("tX_adudiodevice_oss::open() - buff_no: %i, buff_size: %i, buff_cfg: %08x", globals.buff_no, globals.buff_size, buff_cfg);
101 i = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &p);
103 ioctl(fd, SNDCTL_DSP_RESET, 0);
109 i += ioctl(fd, SOUND_PCM_WRITE_BITS, &p);
114 i += ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &p);
119 i += ioctl(fd, SOUND_PCM_WRITE_RATE, &p);
121 i += ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
123 tX_debug("tX_adudiodevice_oss::open() - blocksize: %i", blocksize);
125 samples_per_buffer=blocksize/sizeof(int16_t);
126 globals.true_block_size=samples_per_buffer/2;
128 ioctl(fd, SNDCTL_DSP_SYNC, 0);
133 int tX_audiodevice_oss :: close()
146 tX_audiodevice_oss :: tX_audiodevice_oss()
153 void tX_audiodevice_oss :: play(int16_t *buffer)
155 #ifdef BIG_ENDIAN_MACHINE
156 swapbuffer (buffer, samples_per_buffer);
158 write(fd, buffer, blocksize);
165 int tX_audiodevice_alsa :: open()
170 int tX_audiodevice_alsa :: close()
175 tX_audiodevice_alsa :: tX_audiodevice_alsa()
180 void tX_audiodevice_alsa :: play(int16_t *buffer)
182 #ifdef BIG_ENDIAN_MACHINE
183 swapbuffer (buffer, samples_per_buffer);