1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
* @(#) obuffer_aix.cc 1.1, last edit: 13 Feb 1995 13:13:05
* @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
* @(#) Berlin University of Technology
*
* AixObuffer class written by
* Nick Cremelie (cremelie@ibmsp.elis.rug.ac.be)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
// statics of class AixObuffer:
int AixObuffer::audio_fd = -1;
int AixObuffer::open_audio_device (void)
{
int fd;
if ((fd = open ("/dev/acpa0/1", O_WRONLY)) < 3)
if ((fd = open ("/dev/paud0/1", O_WRONLY)) < 3)
if ((fd = open ("/dev/baud0/1", O_WRONLY)) < 3)
{
cerr << "Sorry, no audio device is currently available!\n";
exit (1);
}
return ((fd<3)?-1:fd);
}
AixObuffer::AixObuffer (uint32 number_of_channels, Header *header, float volume)
{
struct _track_info
{
unsigned short master_volume;
unsigned short dither_percent;
unsigned short reserved[3];
} t_info;
audio_init a_init;
audio_control a_control;
audio_change a_change;
channels = number_of_channels;
for (int i = 0; i < number_of_channels; ++i)
bufferp[i] = buffer + i;
if (audio_fd < 0)
{
cerr << "Internal error, AixObuffer::audio_fd has to be initialized\n"
"by AixObuffer::class_suitable()!\n";
exit (1);
}
// configure the device:
int play_sample_rate = header->frequency ();
t_info.master_volume=0x7fff;
t_info.dither_percent=0;
a_init.srate=play_sample_rate;
a_init.bits_per_sample=16;
a_init.channels=channels;
a_init.mode=PCM;
a_init.flags=FIXED|BIG_ENDIAN|TWOS_COMPLEMENT;
a_init.operation=PLAY;
a_change.balance=0x3fff0000;
a_change.balance_delay=0;
a_change.volume=(int32)(volume * (float)0x7FFFFFFF);
a_change.volume_delay=0;
a_change.monitor=AUDIO_IGNORE;
a_change.input=AUDIO_IGNORE;
a_change.output=OUTPUT_1;
a_change.dev_info=&t_info;
a_control.ioctl_request=AUDIO_CHANGE;
a_control.position=0;
a_control.request_info=&a_change;
if (ioctl(audio_fd, AUDIO_INIT, &a_init) == -1 )
{
perror ("configuration (init) of audio device failed");
exit (1);
}
if (ioctl(audio_fd, AUDIO_CONTROL, &a_control) == -1 )
{
perror ("configuration (control) of audio device failed");
exit (1);
}
a_control.ioctl_request=AUDIO_START;
a_control.request_info=NULL;
if (ioctl(audio_fd, AUDIO_CONTROL, &a_control) == -1 )
{
perror ("configuration (start) of audio device failed");
exit (1);
}
}
AixObuffer::~AixObuffer (void)
{
if (ioctl(audio_fd, AUDIO_WAIT) == -1)
cerr << "could not wait on audio device!\n";
close (audio_fd);
}
void AixObuffer::append (uint32 channel, int16 value)
{
#ifdef DEBUG
if (channel >= channels)
{
cerr << "illegal channelnumber in AixObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
cerr << "buffer overflow!\n";
exit (1);
}
#endif
*bufferp[channel] = value;
bufferp[channel] += channels;
}
void AixObuffer::write_buffer (int)
{
int length = (int)((char *)bufferp[0] - (char *)buffer);
if (write (audio_fd, buffer, length) != length)
{
perror ("write to audio device failed");
exit (1);
}
for (int i = 0; i < channels; ++i)
bufferp[i] = buffer + i;
}
bool AixObuffer::class_suitable (uint32 number_of_channels)
{
// open the audio device:
audio_fd = open_audio_device ();
return True;
}
|