LMMS
Loading...
Searching...
No Matches
Wave_Writer.h
Go to the documentation of this file.
1/* WAVE sound file writer for recording 16-bit output during program development */
2
3#ifndef WAVE_WRITER_H
4#define WAVE_WRITER_H
5
6#ifdef __cplusplus
7 extern "C" {
8#endif
9
10/* C interface */
11void wave_open( long sample_rate, const char* filename );
12void wave_enable_stereo( void );
13void wave_write( const short* buf, long count );
14long wave_sample_count( void );
15void wave_close( void );
16
17#ifdef __cplusplus
18 }
19#endif
20
21#ifdef __cplusplus
22#include <stddef.h>
23#include <stdio.h>
24
25/* C++ interface */
26class Wave_Writer {
27public:
28 typedef short sample_t;
29
30 // Create sound file with given sample rate (in Hz) and filename.
31 // Exits program if there's an error.
32 Wave_Writer( long sample_rate, char const* filename = "out.wav" );
33
34 // Enable stereo output
35 void enable_stereo();
36
37 // Append 'count' samples to file. Use every 'skip'th source sample; allows
38 // one channel of stereo sample pairs to be written by specifying a skip of 2.
39 void write( const sample_t*, long count, int skip = 1 );
40
41 // Append 'count' floating-point samples to file. Use every 'skip'th source sample;
42 // allows one channel of stereo sample pairs to be written by specifying a skip of 2.
43 void write( const float*, long count, int skip = 1 );
44
45 // Number of samples written so far
46 long sample_count() const;
47
48 // Finish writing sound file and close it
49 void close();
50
51 ~Wave_Writer();
52public:
53 // Deprecated
54 void stereo( bool b ) { chan_count = b ? 2 : 1; }
55private:
56 enum { buf_size = 32768 * 2 };
57 unsigned char* buf;
58 FILE* file;
59 long sample_count_;
60 long rate;
61 long buf_pos;
62 int chan_count;
63
64 void flush();
65};
66
67inline void Wave_Writer::enable_stereo() { chan_count = 2; }
68
69inline long Wave_Writer::sample_count() const { return sample_count_; }
70
71#endif
72
73#endif
LADSPA_Data sample_t
Definition basics.h:100
void wave_close(void)
Definition Wave_Writer.cpp:180
void wave_open(long sample_rate, const char *filename)
Definition Wave_Writer.cpp:168
long wave_sample_count(void)
Definition Wave_Writer.cpp:176
void wave_enable_stereo(void)
Definition Wave_Writer.cpp:174
void wave_write(const short *buf, long count)
Definition Wave_Writer.cpp:178
#define buf_size
static char filename[]
Definition features.c:5
b
Definition crypt.c:628
int flush(__G__ rawbuf, size, unshrink) __GDEF uch *rawbuf
struct zdirent * file
Definition win32.c:1500
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263