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_hp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  3.8 KB  |  191 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_hp.c,v 1.17 1998/12/07 06:01:41 miod Exp $
  22.  
  23.   Mikmod driver for output to HP 9000 series /dev/audio
  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. #include <sys/ioctl.h>
  46.  
  47. #include <mikmod_internals.h>
  48.  
  49. #define BUFFERSIZE 32768
  50.  
  51. static    int fd=-1;
  52. static    SBYTE *audiobuffer=NULL;
  53.  
  54. static BOOL HP_IsThere(void)
  55. {
  56.     return 1;
  57. }
  58.  
  59. static BOOL HP_Init(void)
  60. {
  61.     int flags;
  62.     
  63.     if (!(md_mode&DMODE_16BITS)) {
  64.         _mm_errno=MMERR_16BIT_ONLY;
  65.         return 1;
  66.     }
  67.  
  68.     if ((fd=open("/dev/audio",O_WRONLY|O_NDELAY,0))<0) {
  69.         _mm_errno=MMERR_OPENING_AUDIO;
  70.         return 1;
  71.     }
  72.  
  73.     if ((flags=fcntl(fd,F_GETFL,0))<0) {
  74.         _mm_errno=MMERR_NON_BLOCK;
  75.         return 1;
  76.     }
  77.     flags|=O_NDELAY;
  78.     if (fcntl(fd,F_SETFL,flags)<0) {
  79.         _mm_errno=MMERR_NON_BLOCK;
  80.         return 1;
  81.     }
  82.     
  83.     if (ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_LINEAR16BIT)) {
  84.         _mm_errno=MMERR_HP_SETSAMPLESIZE;
  85.         return 1;
  86.     }
  87.     
  88.     if (ioctl(fd,AUDIO_SET_SAMPLE_RATE,md_mixfreq)) {
  89.         _mm_errno=MMERR_HP_SETSPEED;
  90.         return 1;
  91.     }
  92.     
  93.     if (ioctl(fd,AUDIO_SET_CHANNELS,(md_mode&DMODE_STEREO)?2:1)) {
  94.         _mm_errno=MMERR_HP_CHANNELS;
  95.         return 1;
  96.     }
  97.     
  98.     /* choose between:
  99.         AUDIO_OUT_SPEAKER
  100.         AUDIO_OUT_HEADPHONE
  101.         AUDIO_OUT_LINE       */
  102.     if (ioctl(fd,AUDIO_SET_OUTPUT,
  103.                  AUDIO_OUT_SPEAKER|AUDIO_OUT_HEADPHONE|AUDIO_OUT_LINE)) {
  104.         _mm_errno=MMERR_HP_AUDIO_OUTPUT;
  105.         return 1;
  106.     }
  107.  
  108. {
  109.     struct audio_describe description;
  110.     struct audio_gains gains;
  111.     float volume=1.0;
  112.  
  113.     if (ioctl(fd,AUDIO_DESCRIBE,&description)) {
  114.         _mm_errno=MMERR_HP_AUDIO_DESC;
  115.         return 1;
  116.     }
  117.     if (ioctl(fd,AUDIO_GET_GAINS,&gains)) {
  118.         _mm_errno=MMERR_HP_GETGAINS;
  119.         return 1;
  120.     }
  121.  
  122.     gains.transmit_gain=(int)((float)description.min_transmit_gain+
  123.       (float)(description.max_transmit_gain-description.min_transmit_gain)
  124.       * volume);
  125.     if (ioctl(fd,AUDIO_SET_GAINS,&gains)) {
  126.         _mm_errno=MMERR_HP_SETGAINS;
  127.         return 1;
  128.     }
  129. }
  130.     
  131.     if (ioctl(fd,AUDIO_SET_TXBUFSIZE,BUFFERSIZE*8)) {
  132.         _mm_errno=MMERR_HP_BUFFERSIZE;
  133.         return 1;
  134.     }
  135.  
  136.     if (!(audiobuffer=(SBYTE*)_mm_malloc(BUFFERSIZE))) return 1;
  137.     
  138.     return VC_Init();
  139. }
  140.  
  141. static void HP_Exit(void)
  142. {
  143.     VC_Exit();
  144.     if (fd>=0) {
  145.         close(fd);
  146.         fd=-1;
  147.     }
  148.     if (audiobuffer) {
  149.         free(audiobuffer);
  150.         audiobuffer=NULL;
  151.     }
  152. }
  153.  
  154. static BOOL HP_Reset(void)
  155. {
  156.     HP_Exit();
  157.     return HP_Init();
  158. }
  159.  
  160. static void HP_Update(void)
  161. {
  162.     write(fd,audiobuffer,VC_WriteBytes(audiobuffer,BUFFERSIZE));
  163. }
  164.  
  165. MDRIVER drv_hp={
  166.     NULL,
  167.     "HP-UX Audio",
  168.     "HP-UX Audio driver v1.2",
  169.     0,255,
  170.     HP_IsThere,
  171.     VC_SampleLoad,
  172.     VC_SampleUnload,
  173.     VC_SampleSpace,
  174.     VC_SampleLength,
  175.     HP_Init,
  176.     HP_Exit,
  177.     HP_Reset,
  178.     VC_SetNumVoices,
  179.     VC_PlayStart,
  180.     VC_PlayStop,
  181.     HP_Update,
  182.     VC_VoiceSetVolume,
  183.     VC_VoiceSetFrequency,
  184.     VC_VoiceSetPanning,
  185.     VC_VoicePlay,
  186.     VC_VoiceStop,
  187.     VC_VoiceStopped,
  188.     VC_VoiceGetPosition,
  189.     VC_VoiceRealVolume
  190. };
  191.