1
/* cdrdao - write audio CD-Rs in disc-at-once mode
3
* Copyright (C) 1998, 1999 Andreas Mueller <mueller@daneb.ping.de>
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.
20
* $Log: SoundIF-solaris.cc,v $
21
* Revision 1.2 2004/02/12 01:13:32 poolshark
22
* Merge from gnome2 branch
24
* Revision 1.1.1.1.6.2 2004/01/12 20:50:26 poolshark
25
* Added _( and N_( intl macros
27
* Revision 1.1.1.1.6.1 2004/01/05 00:34:03 poolshark
28
* First checking of gnome2 port
30
* Revision 1.1.1.1 2003/12/09 05:32:28 denis
33
* Revision 1.1.1.1 2000/02/05 01:40:00 llanero
34
* Uploaded cdrdao 1.1.3 with pre10 patch applied.
36
* Revision 1.1 1999/05/24 18:07:37 mueller
42
* Sound interface for Solaris. Thanks to Tobias Oetiker <oetiker@ee.ethz.ch>.
45
#include <sys/audioio.h>
52
#include <sys/ioctl.h>
53
#include <sys/types.h>
64
SoundIFImpl() { dspFd_ = -1; }
70
int dspFd_; // sound device
75
impl_ = new SoundIFImpl;
84
// Initializes sound interface.
86
// 1: sounde device not found
87
// 2: cannot setup sound device
90
if (impl_->openDevice() != 0)
93
if (impl_->setupDevice() != 0) {
102
// Acquires sound device for playing.
107
if (impl_->dspFd_ >= 0)
108
return 0; // already opened
110
if (impl_->openDevice() != 0)
113
if (impl_->setupDevice() != 0) {
114
impl_->closeDevice();
121
// Playes given sample buffer.
124
int SoundIF::play(Sample *sbuf, long nofSamples)
126
if (impl_->dspFd_ < 0)
130
long len = nofSamples * sizeof(Sample);
132
char *buf = (char *)sbuf;
135
ret = write(impl_->dspFd_, buf + nwritten, len);
147
unsigned long SoundIF::getDelay()
152
// Finishs playing, sound device is released.
155
impl_->closeDevice();
159
int SoundIFImpl::openDevice()
162
return 0; // already open
164
if ((dspFd_ = open("/dev/audio", O_WRONLY | O_NONBLOCK)) < 0) {
165
message(-1, _("Cannot open \"/dev/audio\": %s"), strerror(errno));
168
/* Clear the non-blocking flag */
169
(void) fcntl(dspFd_, F_SETFL,
170
(fcntl(dspFd_, F_GETFL, 0) & ~(O_NDELAY | O_NONBLOCK)));
175
void SoundIFImpl::closeDevice()
183
int SoundIFImpl::setupDevice()
185
struct audio_info auinf;
190
if (ioctl(dspFd_, AUDIO_GETINFO, &auinf) < 0) {
191
message(-1, _("Cannot get state of audio interface: %s"), strerror(errno));
194
auinf.play.sample_rate=44100;
195
auinf.play.channels=2;
196
auinf.play.precision=16;
197
auinf.play.encoding=AUDIO_ENCODING_LINEAR;
199
if (ioctl(dspFd_, AUDIO_SETINFO, &auinf) < 0) {
200
message(-1, _("Cannot setup audio interface: %s"), strerror(errno));