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
|
/*
* @(#) obuffer_irix.cc 1.1, last edit: 27 Oct 1994 15:12:54
* @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
* @(#) Berlin University of Technology
*
* 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.
*/
IndigoObuffer::IndigoObuffer (uint32 number_of_channels, Header *header)
{
#ifdef DEBUG
if (!number_of_channels || number_of_channels > MAXCHANNELS)
{
cerr << "IndigoObuffer: number of channels has to be in [1, " << MAXCHANNELS << "] !\n";
exit (1);
}
#endif
channels = number_of_channels;
for (int i = 0; i < number_of_channels; ++i)
bufferp[i] = buffer + i;
// open an audio port and configure it:
ALconfig config;
if (!(config = ALnewconfig ()))
{
cerr << "ALnewconfig failed!\n";
exit (1);
}
ALsetwidth (config, AL_SAMPLE_16);
if (channels == 1)
ALsetchannels (config, AL_MONO);
else
ALsetchannels (config, AL_STEREO);
if (!(port = ALopenport ("MPEG audio player", "w", config)))
{
cerr << "can't allocate an audio port!\n";
exit (1);
}
// set sample rate:
long pvbuffer[2] = { AL_OUTPUT_RATE, 0 };
pvbuffer[1] = header->frequency ();
ALsetparams (AL_DEFAULT_DEVICE, pvbuffer, 2);
ALfreeconfig (config);
}
IndigoObuffer::~IndigoObuffer (void)
{
while (ALgetfilled (port) > 0)
sleep (1);
ALcloseport (port);
}
void IndigoObuffer::append (uint32 channel, int16 value)
{
#ifdef DEBUG
if (channel >= channels)
{
cerr << "illegal channelnumber in IndigoObuffer::append()!\n";
exit (1);
}
if (bufferp[channel] - buffer >= OBUFFERSIZE)
{
cerr << "IndigoObuffer: buffer overflow!\n";
exit (1);
}
#endif
*bufferp[channel] = value;
bufferp[channel] += channels;
}
void IndigoObuffer::write_buffer (int)
{
ALwritesamps (port, buffer, (long)(bufferp[0] - buffer));
for (int i = 0; i < channels; ++i)
bufferp[i] = buffer + i;
}
|