Several bugfixes.
[ahxm.git] / output.c
blob284349359935b2eec9f627d910567c37682d86b3
1 /*
3 output.c
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
25 #include <stdio.h>
26 #include <string.h>
27 #include "output.h"
29 /* output drivers */
30 #include "out_raw.h"
31 #include "out_wav.h"
32 #include "out_pipe.h"
33 #include "out_oss.h"
35 /*******************
36 Data
37 ********************/
39 static struct
41 char * name;
42 int (* open)(char *);
43 int (* write)(int, int);
44 int (* close)(void);
45 } _drivers[]={
46 { "raw", _out_open_raw, _out_write_raw, _out_close_raw },
47 { "wav", _out_open_wav, _out_write_wav, _out_close_wav },
48 { "pipe", _out_open_pipe, _out_write_pipe, _out_close_pipe },
49 #ifdef LINUX_OSS
50 { "oss", _out_open_oss, _out_write_oss, _out_close_oss },
51 #endif
52 { NULL, NULL, NULL, NULL }
55 /* driver in use */
56 static int _driver=-1;
58 /*******************
59 Code
60 ********************/
62 int fget16(FILE * f)
64 int c;
66 c=fgetc(f);
67 c+=(fgetc(f) * 256);
69 return(c);
73 void fput16(short int i, FILE * f)
75 fputc(i & 0x00ff, f);
76 fputc((i & 0xff00) >> 8, f);
80 int fget32(FILE * f)
82 int c;
84 c=fgetc(f);
85 c+=(fgetc(f) * 256);
86 c+=(fgetc(f) * 65536);
87 c+=(fgetc(f) * 16777216);
89 return(c);
93 void fput32(int i, FILE * f)
95 fputc(i & 0x000000ff, f);
96 fputc((i & 0x0000ff00) >> 8, f);
97 fputc((i & 0x00ff0000) >> 16, f);
98 fputc((i & 0xff000000) >> 24, f);
102 int output_open(char * name, char * filename)
104 int n;
106 if(_driver != -1)
107 return(-1);
109 for(n=0;;n++)
111 if(_drivers[n].name == NULL)
112 return(-2);
114 if(strcmp(name, _drivers[n].name)==0)
115 break;
118 _driver=n;
120 return(_drivers[_driver].open(filename));
124 int output_write(int lsample, int rsample)
126 return(_drivers[_driver].write(lsample, rsample));
130 int output_close(void)
132 int r;
134 r=_drivers[_driver].close();
135 _driver=-1;
137 return(r);