home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / audio / tracker / sgi_audio.c < prev    next >
Encoding:
C/C++ Source or Header  |  2014-05-19  |  3.3 KB  |  144 lines

  1. /* sgi_audio.c */
  2.  
  3. /* $Author: espie $
  4.  * $Id: sgi_audio.c,v 2.5 1991/12/04 08:28:53 espie Exp espie $
  5.  * $Revision: 2.5 $
  6.  * $Log: sgi_audio.c,v $
  7.  * Revision 2.5  1991/12/04  08:28:53  espie
  8.  * Separated mix/stereo stuff.
  9.  *
  10.  * Revision 2.4  1991/12/03  21:24:53  espie
  11.  * Checked buffer size.
  12.  *
  13.  * Revision 2.3  1991/12/03  20:43:46  espie
  14.  * Added possibility to get back to MONO for the sgi.
  15.  *
  16.  * Revision 2.2  1991/12/03  18:07:38  espie
  17.  * Added stereo capabilities to the indigo version.
  18.  *
  19.  * Revision 2.1  1991/11/18  01:10:45  espie
  20.  * Minor corrections.
  21.  *
  22.  * Revision 2.0  1991/11/17  21:42:08  espie
  23.  * New version.
  24.  *
  25.  * Revision 1.9  1991/11/17  17:09:53  espie
  26.  * Added missing prototypes.
  27.  *
  28.  * Revision 1.8  1991/11/16  15:42:43  espie
  29.  * Can't remember what.
  30.  *
  31.  * Revision 1.7  1991/11/08  14:25:55  espie
  32.  * Ask the frequency to the audio device.
  33.  *
  34.  * Revision 1.6  1991/11/07  20:12:34  espie
  35.  * Minor problem with version id.
  36.  *
  37.  * Revision 1.5  1991/11/07  20:11:10  espie
  38.  * Added embedded version id.
  39.  *
  40.  * Revision 1.4  1991/11/07  15:27:02  espie
  41.  * Corrected bug: when closing audio,
  42.  * we know wait for the samples queue to be empty.
  43.  *
  44.  * Revision 1.3  1991/11/05  22:49:03  espie
  45.  * Added a #define. We can now be non commited as
  46.  * far as the sampling rate is concerned.
  47.  *
  48.  * Revision 1.2  1991/11/04  13:23:59  espie
  49.  * Use HZ macro.
  50.  *
  51.  * Revision 1.1  1991/11/03  22:46:33  espie
  52.  * Initial revision
  53.  *
  54.  *
  55.  */
  56.  
  57. #include <audio.h>
  58. #include <malloc.h>
  59. #include <stdio.h>
  60. #include "machine.h"
  61. #include "extern.h"
  62.  
  63. extern int sginap(long ticks);
  64.      
  65. static char *id = "$Id: sgi_audio.c,v 2.5 1991/12/04 08:28:53 espie Exp espie $";
  66.  
  67. signed short *buffer;
  68. int index;
  69.  
  70.  
  71. ALport audio;
  72. ALconfig config;
  73.  
  74. long chpars[] = {AL_OUTPUT_RATE, 0};
  75.  
  76. static int stereo;  /* are we playing stereo or not ? */
  77. /* 256th of primary/secondary source for that side. */
  78. static int primary, secondary;
  79.  
  80. void set_mix(percent)
  81. int percent;
  82.     {
  83.     percent *= 256;
  84.     percent /= 100;
  85.     primary = percent;
  86.     secondary = 512 - percent;
  87.     }
  88.  
  89. int open_audio(frequency)
  90. int frequency;
  91.     {
  92.     int number;
  93.  
  94.     chpars[1] = frequency;
  95.     if (frequency == 0)
  96.         ALgetparams(AL_DEFAULT_DEVICE, chpars, 2);
  97.     else
  98.         ALsetparams(AL_DEFAULT_DEVICE, chpars, 2); 
  99.     config = ALnewconfig();
  100.     if (stereo = !getenv("MONO"))
  101.         {
  102.         ALsetchannels(config, AL_STEREO);
  103.         number = 2;
  104.         set_mix(30);
  105.         }
  106.     else
  107.         {
  108.         ALsetchannels(config, AL_MONO);
  109.         number = 1;
  110.         }
  111.     ALsetwidth(config, AL_SAMPLE_16);
  112.     audio = ALopenport("soundtracker mono", "w", config);
  113.     index = 0;
  114.     buffer = malloc(sizeof(signed short) * number * chpars[1]);
  115.     return chpars[1];
  116.     }
  117.  
  118. void output_samples(int left, int right)
  119.     {
  120.     if (stereo)
  121.         {
  122.         buffer[index++] = (left * primary + right * secondary)/256;
  123.         buffer[index++] = (right * primary + left * secondary)/256;
  124.         }
  125.     else
  126.         buffer[index++] = left + right;
  127.     }
  128.  
  129. void flush_buffer(void)
  130.     {
  131.     ALwritesamps(audio, buffer, index);
  132.     index = 0;
  133.     }
  134.  
  135.  
  136. void close_audio(void)
  137.     {
  138.     while(ALgetfilled(audio) != 0)
  139.         sginap(1);
  140.     ALcloseport(audio);
  141.     ALfreeconfig(config);
  142.     }
  143.  
  144.