space normalization

pull/18/head
Dimitri Diakopoulos 10 years ago
parent ce56c943b9
commit 97c2b2cd56

@ -1,3 +1,31 @@
Skip to content
This repository
Pull requests
Issues
Gist
@ddiakopoulos
5
22
3
ddiakopoulos / libnyquist
Code
Issues 6
Pull requests 0
Pulse
Graphs
Settings
libnyquist / examples / src / Main.cpp
ce56c94 2 minutes ago
@ddiakopoulos ddiakopoulos the most basic, generally not- correct linear interpolating resampling
@ddiakopoulos
@r-lyeh
150 lines(123 sloc) 5.71 KB
// Note to Visual Studio / Windows users: you must set the working directory manually on the project file
// to $(ProjectDir)../../../ since these settings are not saved directly in project. The loader
// will be unable to find the example assets unless the proper working directory is set.
@ -93,7 +121,6 @@ int main(int argc, const char **argv) try
fileData->frameSize = 32;
fileData->lengthSeconds = 2.0;
fileData->sampleRate = 44100;
std::cout << "Starting recording for two seconds..." << std::endl;
myDevice.Record(fileData->sampleRate * fileData->lengthSeconds, fileData->samples);
*/
@ -126,7 +153,7 @@ int main(int argc, const char **argv) try
}
fileData->samples = outputBuffer;
int encoderStatus = OggOpusEncoder::WriteFile({1, PCM_FLT, DITHER_NONE}, fileData.get(), "encoded.opus");
int encoderStatus = OggOpusEncoder::WriteFile({ 1, PCM_FLT, DITHER_NONE }, fileData.get(), "encoded.opus");
std::cout << "Encoder Status: " << encoderStatus << std::endl;
return EXIT_SUCCESS;
@ -147,3 +174,8 @@ catch (const std::exception & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
}
Contact GitHub API Training Shop Blog About
© 2016 GitHub, Inc.Terms Privacy Security Status Help

@ -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);

Loading…
Cancel
Save