home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 February / PCO_0299.ISO / filesbbs / linux / mikmod-3.000 / mikmod-3 / mikmod-3.1.2 / drivers / drv_sgi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  4.3 KB  |  199 lines

  1. /*    MikMod sound library
  2.     (c) 1998 Miodrag Vallat and others - see file AUTHORS for complete list
  3.  
  4.     This library is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU Library General Public License as
  6.     published by the Free Software Foundation; either version 2 of
  7.     the License, or (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public
  15.     License along with this library; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.   
  19. /*==============================================================================
  20.  
  21.   $Id: drv_sgi.c,v 1.17 1998/12/07 06:01:47 miod Exp $
  22.  
  23.   Mikmod driver for output on SGI audio system (needs libaudio from the dmedia
  24.   package).
  25.  
  26. ==============================================================================*/
  27.  
  28. /*
  29.  
  30.     Written by Stephan Kanthak <kanthak@i6.informatik.rwth-aachen.de>
  31.  
  32.     Fragment configuration:
  33.     =======================
  34.  
  35.     You can use the environment variables 'MM_SGI_FRAGSIZE' and
  36.     'MM_SGI_BUFSIZE' to override the default size of the audio buffer. If you
  37.     experience crackles & pops, try experimenting with these values.
  38.  
  39.     Please read README.SGI first before contacting the author because there are
  40.     some things to know about the specials of the SGI audio driver.
  41.  
  42. */
  43.  
  44. #ifdef HAVE_CONFIG_H
  45. #include "config.h"
  46. #endif
  47.  
  48. #ifdef HAVE_UNISTD_H
  49. #include <unistd.h>
  50. #endif
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <dmedia/audio.h>
  54.  
  55. #include <mikmod_internals.h>
  56.  
  57. #define DEFAULT_SGI_FRAGSIZE  20000
  58. #define DEFAULT_SGI_BUFSIZE   40000
  59.  
  60. static    ALconfig sgi_config;
  61. static    ALport sgi_port;
  62. static    int sample_factor;
  63. static    int sgi_fragsize;
  64. static    int sgi_bufsize;
  65. static    SBYTE *audiobuffer=NULL;
  66.  
  67. static BOOL SGI_IsThere(void)
  68. {
  69.     ALseterrorhandler(0);
  70.     return(ALqueryparams(AL_DEFAULT_DEVICE,0,0))?1:0;
  71. }
  72.  
  73. static SGI_Init(void)
  74. {
  75.     char *env;
  76.     long chpars[] = { AL_OUTPUT_RATE, AL_RATE_22050 };
  77.  
  78.     switch(md_mixfreq) {
  79.         case 8000:
  80.             chpars[1] = AL_RATE_8000;
  81.             break;
  82.         case 11025:
  83.             chpars[1] = AL_RATE_11025;
  84.             break;
  85.         case 16000:
  86.             chpars[1] = AL_RATE_16000;
  87.             break;
  88.         case 22050:
  89.             chpars[1] = AL_RATE_22050;
  90.             break;
  91.         case 32000:
  92.             chpars[1] = AL_RATE_32000;
  93.             break;
  94.         case 44100:
  95.             chpars[1] = AL_RATE_44100;
  96.             break;
  97.         case 48000:
  98.             chpars[1] = AL_RATE_48000;
  99.             break;
  100.         default:
  101.             _mm_errno=MMERR_SGI_SPEED;
  102.             return 1;
  103.     }
  104.     ALseterrorhandler(0);
  105.     ALsetparams(AL_DEFAULT_DEVICE, chpars, 2);
  106.  
  107.     if (!(sgi_config=ALnewconfig())) {
  108.         _mm_errno=MMERR_OPENING_AUDIO;
  109.         return 1;
  110.     }
  111.     
  112.     if (md_mode&DMODE_16BITS) {
  113.         if (ALsetwidth(sgi_config,AL_SAMPLE_16)<0) {
  114.             _mm_errno=MMERR_SGI_16BIT;
  115.             return 1;
  116.         }
  117.         sample_factor = 2;
  118.     } else {
  119.         if (ALsetwidth(sgi_config,AL_SAMPLE_8)<0) {
  120.             _mm_errno=MMERR_SGI_8BIT;
  121.             return 1;
  122.         }
  123.         sample_factor = 1;
  124.     }
  125.  
  126.     if (md_mode&DMODE_STEREO) {
  127.         if (ALsetchannels(sgi_config,AL_STEREO)<0) {
  128.             _mm_errno=MMERR_SGI_STEREO;
  129.             return 1;
  130.         }
  131.     } else {
  132.         if (ALsetchannels(sgi_config,AL_MONO)<0) {
  133.             _mm_errno=MMERR_SGI_MONO;
  134.             return 1;
  135.         }
  136.     }
  137.  
  138.     sgi_fragsize=(env=getenv("MM_SGI_FRAGSIZE"))?atol(env):DEFAULT_SGI_BUFSIZE;
  139.     sgi_bufsize=(env=getenv("MM_SGI_BUFSIZE"))?atol(env):DEFAULT_SGI_BUFSIZE;
  140.  
  141.     ALsetqueuesize(sgi_config, sgi_bufsize);
  142.     if (!(sgi_port=ALopenport("MikMod","w",sgi_config))) {
  143.         _mm_errno=MMERR_OPENING_AUDIO;
  144.         return 1;
  145.     }
  146.  
  147.     if(!(audiobuffer=(SBYTE*)_mm_malloc(sgi_fragsize))) return 1;
  148.     
  149.     return VC_Init();
  150. }
  151.  
  152. static void SGI_Exit(void)
  153. {
  154.     VC_Exit();
  155.     if (audiobuffer) {
  156.         free(audiobuffer);
  157.         audiobuffer=NULL;
  158.     }
  159. }
  160.  
  161. static BOOL SGI_Reset(void)
  162. {
  163.     SGI_Exit();
  164.     return SGI_Init();
  165. }
  166.  
  167. static void SGI_Update(void)
  168. {
  169.     ALwritesamps(sgi_port,audiobuffer,
  170.                  VC_WriteBytes(audiobuffer,sgi_fragsize)/sample_factor);
  171. }
  172.  
  173. MDRIVER drv_sgi={
  174.     NULL,
  175.     "SGI Audio System",
  176.     "SGI Audio System driver v0.4",
  177.     0,255,
  178.     SGI_IsThere,
  179.     VC_SampleLoad,
  180.     VC_SampleUnload,
  181.     VC_SampleSpace,
  182.     VC_SampleLength,
  183.     SGI_Init,
  184.     SGI_Exit,
  185.     SGI_Reset,
  186.     VC_SetNumVoices,
  187.     VC_PlayStart,
  188.     VC_PlayStop,
  189.     SGI_Update,
  190.     VC_VoiceSetVolume,
  191.     VC_VoiceSetFrequency,
  192.     VC_VoiceSetPanning,
  193.     VC_VoicePlay,
  194.     VC_VoiceStop,
  195.     VC_VoiceStopped,
  196.     VC_VoiceGetPosition,
  197.     VC_VoiceRealVolume
  198. };
  199.