home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets / Secrets2.iso / Audio / WAV / MaplayP / _SETUP.1 / hpux_obuffer.cc.old < prev    next >
Encoding:
Text File  |  1997-07-08  |  4.4 KB  |  170 lines

  1. /* hpux_obuffer.cc
  2.  
  3.     HP-UX output buffer written by John Fehr (jfehr@themall.net)
  4.  
  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.
  9.  
  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.
  14.  
  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. */
  18.  
  19. #ifdef _HPUX_SOURCE
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <errno.h>
  25. #include <unistd.h>
  26. #include <fcntl.h>
  27. #include <sys/ioctl.h>
  28. #include <iostream.h>
  29.  
  30. #include "obuffer.h"
  31. #include "header.h"
  32.  
  33. HPUXObuffer::HPUXObuffer (uint32 number_of_channels)
  34. {
  35.   char ServerName[10];
  36.   ServerName[0] = 0;
  37.   audio=AOpenAudio(ServerName,NULL);
  38.   if (audio)
  39.   {
  40.     audio->simple_player_gm->gain_entries->u.o.out_ch=AOCTMono;
  41.       audio->simple_player_gm->gain_entries->u.o.out_dst=AODTMonoJack;
  42.   }
  43.     FileFormat=AFFRawLin16;
  44.     Attribs.type=ATSampled;
  45.     Attribs.attr.sampled_attr.data_format=ADFLin16;
  46.     Attribs.attr.sampled_attr.bits_per_sample=16;
  47.     Attribs.attr.sampled_attr.sampling_rate=44100;
  48.     Attribs.attr.sampled_attr.channels=number_of_channels;
  49.     Attribs.attr.sampled_attr.interleave=1;
  50.     Attribs.attr.sampled_attr.duration.type=ATTSamples;
  51.     Attribs.attr.sampled_attr.duration.u.samples=5000000;
  52.  
  53.     /* Setup the playback parameters.
  54.      * Use ASimplePlayer() to get the simplest output gain matrix
  55.      * supported by the audio hardware.
  56.      */
  57.     playParams.gain_matrix = *ASimplePlayer(audio);
  58.     playParams.play_volume = AUnityGain;     /* no change to play volume */
  59.     playParams.priority    = APriorityNormal;         /* normal priority */
  60.     playParams.event_mask  = 0;              /* don't solicit any events */
  61.  
  62.     /* Create an audio stream using the desired audio attributes and play
  63.      * parameters.  Set all values in AttribsMask to 1 to tell
  64.      * Audio library to use all the values in Attrib.
  65.      */
  66.     AttribsMask = ~0;       /* set all values to 1 (set all to NOT zero) */
  67.     xid = APlaySStream( audio, AttribsMask, &Attribs, &playParams,
  68.                        &audioStream, NULL );
  69.  
  70.     /* Create a stream socket */
  71.  
  72.     streamSocket = socket( AF_INET, SOCK_STREAM, 0 );
  73.     if( streamSocket < 0 ) {
  74.       perror( "Socket creation failed" );
  75.       exit(1);
  76.     }
  77.  
  78.     /* Connect the stream socket to the audio stream port. */
  79.  
  80.     status = connect( streamSocket,
  81.                      (struct sockaddr *)&audioStream.tcp_sockaddr,
  82.                       sizeof(struct sockaddr_in) );
  83.     if( status < 0 ) {
  84.       perror( "Connect failed" );
  85.       exit(1);
  86.     }
  87.  
  88.     /* Start the stream paused so we can transfer enough data
  89.      * (3 seconds worth) before playing starts to prevent
  90.      * stream from running out.
  91.      */
  92.     APauseAudio( audio, xid, NULL, NULL );
  93.     pauseCount = 3 * Attribs.attr.sampled_attr.channels
  94.                * Attribs.attr.sampled_attr.sampling_rate
  95.                * (Attribs.attr.sampled_attr.bits_per_sample >> 3);
  96.     audioPaused = True;
  97.  
  98.   channels = number_of_channels;
  99.   for (int i = 0; i < number_of_channels; ++i)
  100.     bufferp[i] = buffer + i;
  101. }
  102.  
  103.  
  104. HPUXObuffer::~HPUXObuffer (void)
  105. {
  106.    close( streamSocket );
  107.  
  108.   /* Set close mode to prevent playback from stopping
  109.    * when we close the audio connection.
  110.    */
  111.   ASetCloseDownMode( audio, AKeepTransactions, NULL );
  112.  
  113.   /* That's all, folks!
  114.    */
  115.   ACloseAudio( audio, NULL );
  116. }
  117.  
  118. #ifdef SEEK_STOP
  119. void HPUXObuffer::clear_buffer(void)
  120. {
  121. }
  122.  
  123. void HPUXObuffer::set_stop_flag(void)
  124. {
  125. }
  126. #endif // SEEK_STOP
  127.  
  128. void HPUXObuffer::append (uint32 channel, int32 value)
  129. {
  130.   *bufferp[channel] = value;
  131.   bufferp[channel] += channels;
  132. }
  133.  
  134.  
  135. void HPUXObuffer::write_buffer (int)
  136. {
  137.    int length = (int)((char *)bufferp[0] - (char *)buffer);
  138.     int len=length;
  139.     char *buf=(char *)buffer;
  140.     while (len)
  141.     {
  142.         if ((len_written=write(streamSocket,buf,len))<0)
  143.         {
  144.             perror("write failed");
  145.             exit(0);
  146.         }
  147.         buf+=len_written;
  148.         len-=len_written;
  149.         if (audioPaused)
  150.         {
  151.             pauseCount-=len_written;
  152.             if ((len_written==0) || (pauseCount<=0)) {
  153.                 AResumeAudio(audio,xid,NULL,NULL);
  154.                 audioPaused=False;
  155.             }
  156.         }
  157.     }
  158.   for (int i = 0; i < channels; ++i)
  159.     bufferp[i] = buffer + i;
  160. }
  161.  
  162.  
  163. BOOL HPUXObuffer::class_suitable (uint32 number_of_channels)
  164. {
  165.   return True;
  166. }
  167.  
  168. #endif
  169.  
  170.