|
|
|
|
@ -5,11 +5,11 @@ Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
@ -30,18 +30,18 @@ using namespace nqr;
|
|
|
|
|
|
|
|
|
|
static inline void to_bytes(uint8_t value, char * arr)
|
|
|
|
|
{
|
|
|
|
|
arr[0] = (value) & 0xFF;
|
|
|
|
|
arr[0] = (value)& 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void to_bytes(uint16_t value, char * arr)
|
|
|
|
|
{
|
|
|
|
|
arr[0] = (value) & 0xFF;
|
|
|
|
|
arr[0] = (value)& 0xFF;
|
|
|
|
|
arr[1] = (value >> 8) & 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void to_bytes(uint32_t value, char * arr)
|
|
|
|
|
{
|
|
|
|
|
arr[0] = (value) & 0xFF;
|
|
|
|
|
arr[0] = (value)& 0xFF;
|
|
|
|
|
arr[1] = (value >> 8) & 0xFF;
|
|
|
|
|
arr[2] = (value >> 16) & 0xFF;
|
|
|
|
|
arr[3] = (value >> 24) & 0xFF;
|
|
|
|
|
@ -234,18 +234,18 @@ class OggWriter
|
|
|
|
|
{
|
|
|
|
|
std::vector<char> header;
|
|
|
|
|
|
|
|
|
|
std::array<char, 9> steam_count = {{ 0x0, 0x1, 0x1, 0x2, 0x2, 0x3, 0x4, 0x5, 0x5 }};
|
|
|
|
|
std::array<char, 9> coupled_streacount = {{ 0x0, 0x0, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2, 0x3 }};
|
|
|
|
|
std::array<char, 9> steam_count = { { 0x0, 0x1, 0x1, 0x2, 0x2, 0x3, 0x4, 0x5, 0x5 } };
|
|
|
|
|
std::array<char, 9> coupled_streacount = { { 0x0, 0x0, 0x1, 0x1, 0x2, 0x2, 0x2, 0x2, 0x3 } };
|
|
|
|
|
|
|
|
|
|
std::array<char, 1> chan_map_1 = {{ 0x0 }};
|
|
|
|
|
std::array<char, 2> chan_map_2 = {{ 0x0, 0x1 }};
|
|
|
|
|
std::array<char, 1> chan_map_1 = { { 0x0 } };
|
|
|
|
|
std::array<char, 2> chan_map_2 = { { 0x0, 0x1 } };
|
|
|
|
|
|
|
|
|
|
std::array<char, 9> _preamble = {{ 'O', 'p', 'u', 's', 'H', 'e', 'a', 'd', 0x1 }};
|
|
|
|
|
std::array<char, 9> _preamble = { { 'O', 'p', 'u', 's', 'H', 'e', 'a', 'd', 0x1 } };
|
|
|
|
|
std::array<char, 1> _channel_count;
|
|
|
|
|
std::array<char, 2> _preskip;
|
|
|
|
|
std::array<char, 4> _sample_rate;
|
|
|
|
|
std::array<char, 2> _gain;
|
|
|
|
|
std::array<char, 1> _channel_family = {{ 0x1 }};
|
|
|
|
|
std::array<char, 1> _channel_family = { { 0x1 } };
|
|
|
|
|
|
|
|
|
|
to_bytes(uint8_t(channel_count), _channel_count.data());
|
|
|
|
|
to_bytes(uint16_t(preskip), _preskip.data());
|
|
|
|
|
@ -275,17 +275,17 @@ class OggWriter
|
|
|
|
|
{
|
|
|
|
|
std::vector<char> tags;
|
|
|
|
|
|
|
|
|
|
std::array<char, 8> _preamble = {{ 'O', 'p', 'u', 's', 'T', 'a', 'g', 's' }};
|
|
|
|
|
std::array<char, 8> _preamble = { { 'O', 'p', 'u', 's', 'T', 'a', 'g', 's' } };
|
|
|
|
|
std::array<char, 4> _vendor_length;
|
|
|
|
|
std::array<char, 4> _metadata_count;
|
|
|
|
|
|
|
|
|
|
to_bytes(uint32_t(vendor.size()), _vendor_length.data());
|
|
|
|
|
to_bytes(uint32_t(metadata.size()), _metadata_count.data());
|
|
|
|
|
|
|
|
|
|
tags.insert(tags.end(), _preamble.cbegin() , _preamble.cend());
|
|
|
|
|
tags.insert(tags.end(), _vendor_length.cbegin() , _vendor_length.cend());
|
|
|
|
|
tags.insert(tags.end(), vendor.cbegin() , vendor.cend());
|
|
|
|
|
tags.insert(tags.end(), _metadata_count.cbegin() , _metadata_count.cend());
|
|
|
|
|
tags.insert(tags.end(), _preamble.cbegin(), _preamble.cend());
|
|
|
|
|
tags.insert(tags.end(), _vendor_length.cbegin(), _vendor_length.cend());
|
|
|
|
|
tags.insert(tags.end(), vendor.cbegin(), vendor.cend());
|
|
|
|
|
tags.insert(tags.end(), _metadata_count.cbegin(), _metadata_count.cend());
|
|
|
|
|
|
|
|
|
|
// Process metadata.
|
|
|
|
|
for (const auto & metadata_entry : metadata)
|
|
|
|
|
@ -294,7 +294,7 @@ class OggWriter
|
|
|
|
|
std::string entry = metadata_entry.first + "=" + metadata_entry.second;
|
|
|
|
|
to_bytes(uint32_t(entry.size()), _metadata_entry_length.data());
|
|
|
|
|
tags.insert(tags.end(), _metadata_entry_length.cbegin(), _metadata_entry_length.cend());
|
|
|
|
|
tags.insert(tags.end(), entry.cbegin() , entry.cend());
|
|
|
|
|
tags.insert(tags.end(), entry.cbegin(), entry.cend());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tags;
|
|
|
|
|
@ -319,7 +319,7 @@ public:
|
|
|
|
|
this->channel_count = channel_count;
|
|
|
|
|
this->sample_rate = sample_rate;
|
|
|
|
|
this->bits_per_sample = bits_per_sample;
|
|
|
|
|
this-> ostream = &stream;
|
|
|
|
|
this->ostream = &stream;
|
|
|
|
|
this->metadata = md;
|
|
|
|
|
|
|
|
|
|
int oggInitErr, packetErr;
|
|
|
|
|
@ -420,7 +420,7 @@ int OggOpusEncoder::WriteFile(const EncoderParams p, const AudioData * d, const
|
|
|
|
|
|
|
|
|
|
std::ofstream fout(path.c_str(), std::ios::out | std::ios::binary);
|
|
|
|
|
|
|
|
|
|
std::vector<metadata_t> oggMetadata = {{"artist", "dimitri"}};
|
|
|
|
|
std::vector<metadata_t> oggMetadata = { { "artist", "dimitri" } };
|
|
|
|
|
OggWriter writer(d->channelCount, d->sampleRate, GetFormatBitsPerSample(d->sourceFormat), fout, oggMetadata);
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> outBuffer(OPUS_MAX_PACKET_SIZE);
|
|
|
|
|
|