Flangers are starting to sound like flangers.
[ahxm.git] / output.c
blobf48446dbe481d89b8a53e1f45755a98973216f34
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 "config.h"
27 #include <stdio.h>
28 #include <string.h>
30 #include "core.h"
31 #include "output.h"
33 /* output drivers */
34 #include "out_raw.h"
35 #include "out_wav.h"
36 #include "out_pipe.h"
37 #include "out_oss.h"
38 #include "out_sgi.h"
40 /*******************
41 Data
42 ********************/
44 static struct
46 char * name;
47 int (* open)(char *);
48 int (* write)(int, int);
49 int (* close)(void);
50 } _drivers[]={
51 { "raw", _out_open_raw, _out_write_raw, _out_close_raw },
52 { "wav", _out_open_wav, _out_write_wav, _out_close_wav },
53 { "pipe", _out_open_pipe, _out_write_pipe, _out_close_pipe },
54 #ifdef LINUX_OSS
55 { "oss", _out_open_oss, _out_write_oss, _out_close_oss },
56 #endif
57 #ifdef SGI
58 { "sgi", _out_open_sgi, _out_write_sgi, _out_close_sgi },
59 #endif
60 { NULL, NULL, NULL, NULL }
63 /* driver in use */
64 static int _driver=-1;
66 /*******************
67 Code
68 ********************/
70 void fput16(short int i, FILE * f)
72 fputc(i & 0x00ff, f);
73 fputc((i & 0xff00) >> 8, f);
77 void fput32(int i, FILE * f)
79 fputc(i & 0x000000ff, f);
80 fputc((i & 0x0000ff00) >> 8, f);
81 fputc((i & 0x00ff0000) >> 16, f);
82 fputc((i & 0xff000000) >> 24, f);
86 void trim_samples(int * left, int * right)
88 if(*left < -32768) *left=-32768;
89 if(*left > 32767) *left=32767;
90 if(*right < -32768) *right=-32768;
91 if(*right > 32767) *right=32767;
95 int output_open(char * name, char * filename)
97 int n;
99 if(_driver != -1)
100 return(-1);
102 for(n=0;;n++)
104 if(_drivers[n].name == NULL)
105 return(-2);
107 if(strcmp(name, _drivers[n].name)==0)
108 break;
111 _driver=n;
113 return(_drivers[_driver].open(filename));
117 int output_write(int lsample, int rsample)
119 trim_samples(&lsample, &rsample);
121 return(_drivers[_driver].write(lsample, rsample));
125 int output_close(void)
127 int r;
129 r=_drivers[_driver].close();
130 _driver=-1;
132 return(r);