Note fscommand support in MovieClip.getURL
[gnash.git] / libsound / WAVWriter.h
blobc17bbcdfab6727032329e4e99ac6c01591042733
1 // WAVWriter.h: .wav audio writer
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef GNASH_SOUND_WAVWRITER_H
21 #define GNASH_SOUND_WAVWRITER_H
23 #include <fstream> // for composition (file_stream)
24 #include <cstdint>
26 #include "dsodefs.h"
28 namespace gnash {
29 namespace sound {
31 /// WAV writer class
32 class DSOEXPORT WAVWriter {
34 public:
36 WAVWriter(const std::string& outfile);
38 ~WAVWriter();
40 /// Write samples to file
42 /// @param from
43 /// The buffer to read samples from.
44 /// Buffer must be big enough to hold nSamples samples.
45 ///
46 /// @param nSamples
47 /// The amount of samples to read.
48 /// NOTE: this number currently refers to "mono" samples
49 /// due to some bad design decision. It is so expected
50 /// that the user fetches 44100 * 2 samples which has to
51 /// be interpreted as series of left,right channel couples.
52 /// TODO: use actual number of samples so that it's expected
53 /// to fetch 44100 per second and let expose a function
54 /// to give interpretation of what comes back (how many
55 /// bytes per channel, which format).
56 ///
57 void pushSamples(std::int16_t* from, unsigned int nSamples);
59 private:
61 /// File stream for dump file
63 /// TODO: move to base class ?
64 ///
65 std::ofstream file_stream;
67 /// Current audio data size
68 uint32_t data_size;
70 // write a .WAV file header
71 void write_wave_header(std::ofstream& outfile);
73 // write an unsigned 32-bit integer in little-endian order
74 inline void write_uint32(std::ofstream& outfile, uint32_t number)
76 outfile.put(number & 0xFF);
77 outfile.put((number >> 8) & 0xFF);
78 outfile.put((number >> 16) & 0xFF);
79 outfile.put((number >> 24) & 0xFF);
82 // write an unsigned 16-bit integer in little-endian order
83 inline void write_uint16(std::ofstream& outfile, uint16_t number)
85 outfile.put(number & 0xFF);
86 outfile.put((number >> 8) & 0xFF);
91 } // gnash.sound namespace
92 } // namespace gnash
94 #endif // GNASH_SOUND_WAVWRITER_H