3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 Angel Ortega <angel@triptico.com>
6 out_common.c - Driver for output not depending on external libraries
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
28 #include "ss_output.h"
38 /* file positions where total number of samples is stored */
42 static int frame_size
;
49 usual channel mapping:
53 3 channel: left | right | center
54 quad: front left | front right | rear left | rear right
55 4 channel: left | center | right | surround
56 6 channel: left center | left | center | right center | right | surround
60 static void fput16(short int i
, FILE * f
)
63 fputc((i
& 0xff00) >> 8, f
);
67 static void fput32(int i
, FILE * f
)
69 fputc(i
& 0x000000ff, f
);
70 fputc((i
& 0x0000ff00) >> 8, f
);
71 fputc((i
& 0x00ff0000) >> 16, f
);
72 fputc((i
& 0xff000000) >> 24, f
);
76 static int _out_write_file(short int * buffer
, int size
)
89 static int _out_open_raw(char * file
)
91 if((f
=fopen(file
, "w"))==NULL
)
98 static int _out_close_raw(void)
107 static int _out_open_pipe(char * file
)
109 /* as there is no default pipe output,
110 file can arrive here as NULL; fail */
114 if((f
=popen(file
, "w"))==NULL
)
121 static int _out_close_pipe(void)
130 static int _out_open_wav(char * file
)
132 if((f
=fopen(file
, "w"))==NULL
)
135 frame_size
=ss_nchannels
* 2;
137 /* write wav header */
139 fwrite("RIFF",1,4,f
);
142 fwrite("WAVE",1,4,f
);
143 fwrite("fmt ",1,4,f
);
144 fput32(16,f
); /* chunk size */
145 fput16(1, f
); /* 1: uncompressed PCM */
146 fput16(ss_nchannels
, f
); /* # of channels */
147 fput32(ss_frequency
, f
); /* sample rate */
148 fput32(ss_frequency
* frame_size
, f
); /* bytes per second */
149 fput16(frame_size
, f
); /* 'block align' */
150 fput16(16, f
); /* 16 bits per sample */
151 fwrite("data",1,4,f
);
159 static int _out_close_wav(void)
161 /* rewind file and write total size */
162 fseek(f
, _p1
, SEEK_SET
);
163 fput32((ss_output_frames
* frame_size
) + 36, f
);
165 fseek(f
, _p2
, SEEK_SET
);
166 fput32(ss_output_frames
* frame_size
, f
);
176 struct _output_driver _out_driver_wav
=
177 { "wav", "output.wav", _out_open_wav
, _out_write_file
, _out_close_wav
};
179 struct _output_driver _out_driver_raw
=
180 { "raw", "output.raw", _out_open_raw
, _out_write_file
, _out_close_raw
};
182 struct _output_driver _out_driver_pipe
=
183 { "pipe", NULL
, _out_open_pipe
, _out_write_file
, _out_close_pipe
};