1 #ifndef _sox__hpp__included__
2 #define _sox__hpp__included__
16 * Create new dumper with specified sound sampling rate and channel count.
18 * parameter filename: The name of file to dump to.
19 * parameter samplerate: The sampling rate (must be positive)
20 * parameter channels: The channel count.
22 * throws std::bad_alloc: Not enough memory
23 * throws std::runtime_error: Error opening .sox file
25 sox_dumper(const std::string
& filename
, double samplerate
, uint32_t channels
) throw(std::bad_alloc
,
31 ~sox_dumper() throw();
36 * throws std::bad_alloc: Not enough memory
37 * throws std::runtime_error: Error fixing and closing .sox file
39 void close() throw(std::bad_alloc
, std::runtime_error
);
44 * parameters a: Sample channel values.
46 template<typename
... args
>
47 void sample(args
... a
)
55 for(size_t i
= o
; i
< samplebuffer
.size(); ++i
)
57 internal_dump_sample();
59 template<size_t o
, typename itype
, typename
... args
>
60 void sample2(itype v
, args
... a
)
62 if(o
< samplebuffer
.size())
67 void place_sample(size_t index
, int8_t v
)
69 samplebuffer
[index
] = static_cast<int32_t>(v
) << 24;
71 void place_sample(size_t index
, uint8_t v
)
73 place_sample(index
, static_cast<uint32_t>(v
) << 24);
75 void place_sample(size_t index
, int16_t v
)
77 samplebuffer
[index
] = static_cast<int32_t>(v
) << 16;
79 void place_sample(size_t index
, uint16_t v
)
81 place_sample(index
, static_cast<uint32_t>(v
) << 16);
83 void place_sample(size_t index
, int32_t v
)
85 samplebuffer
[index
] = v
;
87 void place_sample(size_t index
, uint32_t v
)
89 place_sample(index
, static_cast<int32_t>(v
+ 0x80000000U
));
92 void internal_dump_sample();
93 std::vector
<char> databuf
;
94 std::vector
<int32_t> samplebuffer
;
95 std::ofstream sox_file
;
96 uint64_t samples_dumped
;