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_aix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  3.9 KB  |  192 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_aix.c,v 1.16 1998/12/07 06:01:37 miod Exp $
  22.  
  23.   Mikmod driver for output to AIX series audio device
  24.  
  25. ==============================================================================*/
  26.  
  27. /*
  28.  
  29.     Written by Lutz Vieweg <lkv@mania.robin.de>
  30.  
  31. */
  32.  
  33. #ifdef HAVE_CONFIG_H
  34. #include "config.h"
  35. #endif
  36.  
  37. #ifdef HAVE_UNISTD_H
  38. #include <unistd.h>
  39. #endif
  40. #ifdef HAVE_FCNTL_H
  41. #include <fcntl.h>
  42. #endif
  43. #include <stdlib.h>
  44. #include <sys/audio.h>
  45.  
  46. #include <mikmod_internals.h>
  47.  
  48. struct _track_info
  49. {
  50.     unsigned short master_volume;
  51.     unsigned short dither_percent;
  52.     unsigned short reserved[3];
  53. } t_info;
  54.  
  55. static    audio_init a_init;
  56. static    audio_control a_control;
  57. static    audio_change a_change;
  58.  
  59. #define BUFFERSIZE 32768
  60.  
  61. static    int fd=-1;
  62. static    SBYTE *audiobuffer=NULL;
  63.  
  64. static BOOL AIX_IsThere(void)
  65. {
  66.     return 1;
  67. }
  68.  
  69. static BOOL AIX_Init(void)
  70. {
  71.     float volume=(float)1.0;
  72.     int flags;
  73.     
  74.     if (!(md_mode&DMODE_16BITS)) {
  75.         _mm_errno=MMERR_16BIT_ONLY;
  76.         return 1;
  77.     }
  78.     
  79.     if((fd=open("/dev/acpa0/1",O_WRONLY))<0)
  80.         if((fd=open("/dev/paud0/1",O_WRONLY))<0)
  81.             if((fd=open("/dev/baud0/1",O_WRONLY))<0) {
  82.                 _mm_errno=MMERR_OPENING_AUDIO;
  83.                 return 1;
  84.             }
  85.     
  86.     t_info.master_volume=0x7fff;
  87.     t_info.dither_percent=0;
  88.     
  89.     a_init.srate=md_mixfreq;
  90.     a_init.bits_per_sample=16;
  91.     a_init.channels=(md_mode&DMODE_STEREO)?2:1;
  92.     a_init.mode=PCM;
  93.     a_init.flags=FIXED|BIG_ENDIAN|TWOS_COMPLEMENT;
  94.     a_init.operation=PLAY;
  95.     
  96.     a_change.balance=0x3fff0000;
  97.     a_change.balance_delay=0;
  98.     a_change.volume=(long)(volume*(float)0x7FFFFFFF);
  99.     a_change.volume_delay=0;
  100.     a_change.monitor=AUDIO_IGNORE;
  101.     a_change.input=AUDIO_IGNORE;
  102.     a_change.output=OUTPUT_1;
  103.     a_change.dev_info=&t_info;
  104.  
  105.     a_control.ioctl_request=AUDIO_CHANGE;
  106.     a_control.position=0;
  107.     a_control.request_info=&a_change;
  108.  
  109.     if (ioctl(fd,AUDIO_INIT,&a_init)==-1) {
  110.         _mm_errno=MMERR_AIX_CONFIG_INIT;
  111.         return 1;
  112.     }
  113.     if (ioctl(fd,AUDIO_CONTROL,&a_control)==-1) {
  114.         _mm_errno=MMERR_AIX_CONFIG_CONTROL;
  115.         return 1;
  116.     }
  117.  
  118.     a_control.ioctl_request=AUDIO_START;
  119.     a_control.request_info=NULL;
  120.     if (ioctl(fd,AUDIO_CONTROL,&a_control)==-1) {
  121.         _mm_errno=MMERR_AIX_CONFIG_START;
  122.         return 1;
  123.     }
  124.     
  125. #if 0
  126.     if ((flags=fcntl(fd,F_GETFL,0))<0) {
  127.         _mm_errno=MMERR_NON_BLOCK;
  128.         return 1;
  129.     }
  130.     flags|=O_NDELAY;
  131.     if (fcntl(fd,F_SETFL,flags)<0) {
  132.         _mm_errno=MMERR_NON_BLOCK;
  133.         return 1;
  134.     }
  135. #endif
  136.  
  137.     if (!(audiobuffer=(SBYTE*)_mm_malloc(BUFFERSIZE))) return 1;
  138.     
  139.     return VC_Init();
  140. }
  141.  
  142. static void AIX_Exit(void)
  143. {
  144.     VC_Exit();
  145.     if (fd>=0) {
  146.         close(fd);
  147.         fd=-1;
  148.     }
  149.     if (audiobuffer) {
  150.         free(audiobuffer);
  151.         audiobuffer=NULL;
  152.     }
  153. }
  154.  
  155. static BOOL AIX_Reset(void)
  156. {
  157.     AIX_Exit();
  158.     return AIX_Init();
  159. }
  160.  
  161. static void AIX_Update(void)
  162. {
  163.     write(fd,audiobuffer,VC_WriteBytes(audiobuffer,BUFFERSIZE));
  164. }
  165.  
  166. MDRIVER drv_aix={
  167.     NULL,
  168.     "AIX Audio",
  169.     "AIX Audio driver v1.2",
  170.     0,255,
  171.     AIX_IsThere,
  172.     VC_SampleLoad,
  173.     VC_SampleUnload,
  174.     VC_SampleSpace,
  175.     VC_SampleLength,
  176.     AIX_Init,
  177.     AIX_Exit,
  178.     AIX_Reset,
  179.     VC_SetNumVoices,
  180.     VC_PlayStart,
  181.     VC_PlayStop,
  182.     AIX_Update,
  183.     VC_VoiceSetVolume,
  184.     VC_VoiceSetFrequency,
  185.     VC_VoiceSetPanning,
  186.     VC_VoicePlay,
  187.     VC_VoiceStop,
  188.     VC_VoiceStopped,
  189.     VC_VoiceGetPosition,
  190.     VC_VoiceRealVolume
  191. };
  192.