home *** CD-ROM | disk | FTP | other *** search
- /* hpux_obuffer.cc
-
- HP-UX output buffer written by John Fehr (jfehr@themall.net)
-
- 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. */
-
- #ifdef _HPUX_SOURCE
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <iostream.h>
-
- #include "obuffer.h"
- #include "header.h"
-
- HPUXObuffer::HPUXObuffer (uint32 number_of_channels)
- {
- char ServerName[10];
- ServerName[0] = 0;
- audio=AOpenAudio(ServerName,NULL);
- if (audio)
- {
- audio->simple_player_gm->gain_entries->u.o.out_ch=AOCTMono;
- audio->simple_player_gm->gain_entries->u.o.out_dst=AODTMonoJack;
- }
- FileFormat=AFFRawLin16;
- Attribs.type=ATSampled;
- Attribs.attr.sampled_attr.data_format=ADFLin16;
- Attribs.attr.sampled_attr.bits_per_sample=16;
- Attribs.attr.sampled_attr.sampling_rate=44100;
- Attribs.attr.sampled_attr.channels=number_of_channels;
- Attribs.attr.sampled_attr.interleave=1;
- Attribs.attr.sampled_attr.duration.type=ATTSamples;
- Attribs.attr.sampled_attr.duration.u.samples=5000000;
-
- /* Setup the playback parameters.
- * Use ASimplePlayer() to get the simplest output gain matrix
- * supported by the audio hardware.
- */
- playParams.gain_matrix = *ASimplePlayer(audio);
- playParams.play_volume = AUnityGain; /* no change to play volume */
- playParams.priority = APriorityNormal; /* normal priority */
- playParams.event_mask = 0; /* don't solicit any events */
-
- /* Create an audio stream using the desired audio attributes and play
- * parameters. Set all values in AttribsMask to 1 to tell
- * Audio library to use all the values in Attrib.
- */
- AttribsMask = ~0; /* set all values to 1 (set all to NOT zero) */
- xid = APlaySStream( audio, AttribsMask, &Attribs, &playParams,
- &audioStream, NULL );
-
- /* Create a stream socket */
-
- streamSocket = socket( AF_INET, SOCK_STREAM, 0 );
- if( streamSocket < 0 ) {
- perror( "Socket creation failed" );
- exit(1);
- }
-
- /* Connect the stream socket to the audio stream port. */
-
- status = connect( streamSocket,
- (struct sockaddr *)&audioStream.tcp_sockaddr,
- sizeof(struct sockaddr_in) );
- if( status < 0 ) {
- perror( "Connect failed" );
- exit(1);
- }
-
- /* Start the stream paused so we can transfer enough data
- * (3 seconds worth) before playing starts to prevent
- * stream from running out.
- */
- APauseAudio( audio, xid, NULL, NULL );
- pauseCount = 3 * Attribs.attr.sampled_attr.channels
- * Attribs.attr.sampled_attr.sampling_rate
- * (Attribs.attr.sampled_attr.bits_per_sample >> 3);
- audioPaused = True;
-
- channels = number_of_channels;
- for (int i = 0; i < number_of_channels; ++i)
- bufferp[i] = buffer + i;
- }
-
-
- HPUXObuffer::~HPUXObuffer (void)
- {
- close( streamSocket );
-
- /* Set close mode to prevent playback from stopping
- * when we close the audio connection.
- */
- ASetCloseDownMode( audio, AKeepTransactions, NULL );
-
- /* That's all, folks!
- */
- ACloseAudio( audio, NULL );
- }
-
- #ifdef SEEK_STOP
- void HPUXObuffer::clear_buffer(void)
- {
- }
-
- void HPUXObuffer::set_stop_flag(void)
- {
- }
- #endif // SEEK_STOP
-
- void HPUXObuffer::append (uint32 channel, int32 value)
- {
- *bufferp[channel] = value;
- bufferp[channel] += channels;
- }
-
-
- void HPUXObuffer::write_buffer (int)
- {
- int length = (int)((char *)bufferp[0] - (char *)buffer);
- int len=length;
- char *buf=(char *)buffer;
- while (len)
- {
- if ((len_written=write(streamSocket,buf,len))<0)
- {
- perror("write failed");
- exit(0);
- }
- buf+=len_written;
- len-=len_written;
- if (audioPaused)
- {
- pauseCount-=len_written;
- if ((len_written==0) || (pauseCount<=0)) {
- AResumeAudio(audio,xid,NULL,NULL);
- audioPaused=False;
- }
- }
- }
- for (int i = 0; i < channels; ++i)
- bufferp[i] = buffer + i;
- }
-
-
- BOOL HPUXObuffer::class_suitable (uint32 number_of_channels)
- {
- return True;
- }
-
- #endif
-
-