1/* Simple wave sound file writer for use in demo programs. */
2
3#ifndef WAVE_WRITER_H
4#define WAVE_WRITER_H
5
6#ifdef __cplusplus
7 extern "C" {
8#endif
9
10/* If error occurs (out of memory, disk full, etc.), functions print cause
11then exit program. */
12
13/* Creates and opens sound file of given sample rate and filename. */
14int wave_open( int sample_rate, const char filename [] );
15
16/* Enables stereo output. */
17void wave_enable_stereo( void );
18
19/* Appends count samples to file. */
20void wave_write( const short in [], int count );
21
22/* Number of samples written so far. */
23int wave_sample_count( void );
24
25/* Finishes writing sound file and closes it. */
26int wave_close( void );
27
28#ifdef __cplusplus
29 }
30#endif
31
32#ifdef __cplusplus
33
34/* C++ interface */
35class Wave_Writer {
36public:
37 typedef short sample_t;
38 Wave_Writer( int rate, const char file [] = "out.wav" ) { wave_open( rate, file ); }
39 void enable_stereo() { wave_enable_stereo(); }
40 void write( const sample_t in [], int n ) { wave_write( in, n ); }
41 int sample_count() const { return wave_sample_count(); }
42 void close() { wave_close(); }
43 ~Wave_Writer() { wave_close(); }
44};
45#endif
46
47#endif
48