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"
36 # define __USE_XOPEN // we need this for swab()
43 void tX_audiodevice :: init()
46 set_buffersize_near(globals.audiodevice_buffersize);
50 void tX_audiodevice :: set_latency_near(int milliseconds)
52 samples_per_buffer=(int) (((float) milliseconds) * 88.2);
55 int tX_audiodevice :: get_latency()
57 return ((int) (((float) samples_per_buffer) / 88.2));
60 void tX_audiodevice :: set_buffersize_near(int samples)
62 samples_per_buffer=samples;
65 int tX_audiodevice :: get_buffersize()
67 return samples_per_buffer;
70 int tX_audiodevice :: open()
72 fprintf(stderr, "tX: Error: tX_audiodevice::dev_open()\n");
76 int tX_audiodevice :: close()
78 fprintf(stderr, "tX: Error: tX_audiodevice::dev_close()\n");
82 void tX_audiodevice :: play(int16_t* dummy)
84 fprintf(stderr, "tX: Error: tX_audiodevice::play()\n");
89 int tX_audiodevice_oss :: open()
96 fd = ::open(globals.audio_device, O_WRONLY, 0);
98 /* setting buffer size */
99 buff_cfg=(globals.buff_no<<16) | globals.buff_size;
101 tX_debug("tX_adudiodevice_oss::open() - buff_no: %i, buff_size: %i, buff_cfg: %08x", globals.buff_no, globals.buff_size, buff_cfg);
105 i = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &p);
107 ioctl(fd, SNDCTL_DSP_RESET, 0);
113 i += ioctl(fd, SOUND_PCM_WRITE_BITS, &p);
118 i += ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &p);
123 i += ioctl(fd, SOUND_PCM_WRITE_RATE, &p);
125 i += ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blocksize);
127 tX_debug("tX_adudiodevice_oss::open() - blocksize: %i", blocksize);
129 samples_per_buffer=blocksize/sizeof(int16_t);
130 globals.true_block_size=samples_per_buffer/2;
132 ioctl(fd, SNDCTL_DSP_SYNC, 0);
137 int tX_audiodevice_oss :: close()
150 tX_audiodevice_oss :: tX_audiodevice_oss()
157 void tX_audiodevice_oss :: play(int16_t *buffer)
159 #ifdef BIG_ENDIAN_MACHINE
160 swapbuffer (buffer, samples_per_buffer);
162 write(fd, buffer, blocksize);
169 int tX_audiodevice_alsa :: open()
174 int tX_audiodevice_alsa :: close()
179 tX_audiodevice_alsa :: tX_audiodevice_alsa()
184 void tX_audiodevice_alsa :: play(int16_t *buffer)
186 #ifdef BIG_ENDIAN_MACHINE
187 swapbuffer (buffer, samples_per_buffer);