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_raw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-07  |  2.7 KB  |  131 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_raw.c,v 1.16 1998/12/07 06:01:46 miod Exp $
  22.  
  23.   Mikmod driver for output to a file called MUSIC.RAW
  24.  
  25. ==============================================================================*/
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30.  
  31. #ifdef HAVE_UNISTD_H
  32. #include <unistd.h>
  33. #endif
  34. #ifdef HAVE_FCNTL_H
  35. #include <fcntl.h>
  36. #endif
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39.  
  40. #include <mikmod_internals.h>
  41.  
  42. #define BUFFERSIZE 32768
  43. #define FILENAME "music.raw"
  44.  
  45. static    int rawout=-1;
  46. static    SBYTE *audiobuffer=NULL;
  47.  
  48. static BOOL RAW_IsThere(void)
  49. {
  50.     return 1;
  51. }
  52.  
  53. static BOOL RAW_Init(void)
  54. {
  55.     if((rawout=open(FILENAME,O_RDWR|O_TRUNC|O_CREAT,S_IREAD|S_IWRITE))<0) {
  56.         _mm_errno=MMERR_OPENING_FILE;
  57.         return 1;
  58.     }
  59.     md_mode|=DMODE_SOFT_MUSIC|DMODE_SOFT_SNDFX;
  60.  
  61.     if (!(audiobuffer=(SBYTE*)_mm_malloc(BUFFERSIZE))) {
  62.         close(rawout);unlink(FILENAME);
  63.         rawout=-1;
  64.         return 1;
  65.     }
  66.  
  67.     if (VC_Init()) {
  68.         close(rawout);unlink(FILENAME);
  69.         rawout=-1;
  70.         return 1;
  71.     }
  72.     return 0;
  73. }
  74.  
  75. static void RAW_Exit(void)
  76. {
  77.     VC_Exit();
  78.     if (rawout!=-1) {
  79.         close(rawout);
  80.         rawout=-1;
  81.     }
  82.     if (audiobuffer) {
  83.         free(audiobuffer);
  84.         audiobuffer=NULL;
  85.     }
  86. }
  87.  
  88. static void RAW_Update(void)
  89. {
  90.     write(rawout,audiobuffer,VC_WriteBytes(audiobuffer,BUFFERSIZE));
  91. }
  92.  
  93. static BOOL RAW_Reset(void)
  94. {
  95.     close(rawout);
  96.     if((rawout=open(FILENAME,O_RDWR|O_TRUNC|O_CREAT,S_IREAD|S_IWRITE))<0) {
  97.         _mm_errno=MMERR_OPENING_FILE;
  98.         return 1;
  99.     }
  100.  
  101.     return 0;
  102. }
  103.  
  104. MDRIVER drv_raw={
  105.     NULL,
  106.     "Disk writer (raw data)",
  107.     "Raw disk writer (music.raw) v1.1",
  108.     0,255,
  109.     RAW_IsThere,
  110.     VC_SampleLoad,
  111.     VC_SampleUnload,
  112.     VC_SampleSpace,
  113.     VC_SampleLength,
  114.     RAW_Init,
  115.     RAW_Exit,
  116.     RAW_Reset,
  117.     VC_SetNumVoices,
  118.     VC_PlayStart,
  119.     VC_PlayStop,
  120.     RAW_Update,
  121.     VC_VoiceSetVolume,
  122.     VC_VoiceSetFrequency,
  123.     VC_VoiceSetPanning,
  124.     VC_VoicePlay,
  125.     VC_VoiceStop,
  126.     VC_VoiceStopped,
  127.     VC_VoiceGetPosition,
  128.     VC_VoiceRealVolume
  129. };
  130.  
  131.