From f273e7d98cae3c0b4ddf04f47084f9d98d8ba731 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Mon, 25 Jul 2016 16:04:12 -0700 Subject: [PATCH] ogg stream write function --- src/WavEncoder.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/WavEncoder.cpp b/src/WavEncoder.cpp index d5093a4..57e2202 100644 --- a/src/WavEncoder.cpp +++ b/src/WavEncoder.cpp @@ -388,7 +388,28 @@ public: ogg_stream_clear(&oss); } - bool write(char * data, std::streamsize length, size_t sample_count, bool end); + bool write(char * data, std::streamsize length, size_t sampleCount, bool end) + { + int err; + ogg_packet packet; + + granule += sampleCount; + + packet.packet = reinterpret_cast(data); + packet.bytes = static_cast(length); + packet.b_o_s = 0; + packet.e_o_s = end ? 1 : 0; + packet.granulepos = granule; + packet.packetno = packet_number++; + + err = ogg_stream_packetin(&oss, &packet); + + if (err) throw std::runtime_error("could not write packet to stream"); + + write_to_ostream(false); + + return true; + } };