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"
39 static int frame_size
;
46 usual channel mapping:
50 3 channel: left | right | center
51 quad: front left | front right | rear left | rear right
52 4 channel: left | center | right | surround
53 6 channel: left center | left | center | right center | right | surround
57 static void fput16(short int i
, FILE * f
)
60 fputc((i
& 0xff00) >> 8, f
);
64 static void fput32(int i
, FILE * f
)
66 fputc(i
& 0x000000ff, f
);
67 fputc((i
& 0x0000ff00) >> 8, f
);
68 fputc((i
& 0x00ff0000) >> 16, f
);
69 fputc((i
& 0xff000000) >> 24, f
);
73 static int _out_write_file(short int * buffer
, int size
)
86 static int _out_open_raw(char * file
)
88 if((f
=fopen(file
, "w"))==NULL
)
95 static int _out_close_raw(void)
104 static int _out_open_pipe(char * file
)
106 /* as there is no default pipe output,
107 file can arrive here as NULL; fail */
111 if((f
=popen(file
, "w"))==NULL
)
118 static int _out_close_pipe(void)
127 static int _out_open_wav(char * file
)
129 if((f
=fopen(file
, "w"))==NULL
)
132 frame_size
=ss_nchannels
* 2;
134 /* write wav header */
136 fwrite("RIFF",1,4,f
);
137 /* first checkpoint (offset: 4) */
139 fwrite("WAVE",1,4,f
);
140 fwrite("fmt ",1,4,f
);
141 fput32(16,f
); /* chunk size */
142 fput16(1, f
); /* 1: uncompressed PCM */
143 fput16(ss_nchannels
, f
); /* # of channels */
144 fput32(ss_frequency
, f
); /* sample rate */
145 fput32(ss_frequency
* frame_size
, f
); /* bytes per second */
146 fput16(frame_size
, f
); /* 'block align' */
147 fput16(16, f
); /* 16 bits per sample */
148 fwrite("data",1,4,f
);
149 /* second checkpoint (offset: 40) */
156 static int _out_close_wav(void)
158 /* rewind file and write total size */
159 fseek(f
, 4, SEEK_SET
);
160 fput32((ss_output_frames
* frame_size
) + 36, f
);
162 fseek(f
, 40, SEEK_SET
);
163 fput32(ss_output_frames
* frame_size
, f
);
173 struct _output_driver _out_driver_wav
=
174 { "wav", "output.wav", _out_open_wav
, _out_write_file
, _out_close_wav
};
176 struct _output_driver _out_driver_raw
=
177 { "raw", "output.raw", _out_open_raw
, _out_write_file
, _out_close_raw
};
179 struct _output_driver _out_driver_pipe
=
180 { "pipe", NULL
, _out_open_pipe
, _out_write_file
, _out_close_pipe
};