tab->space file normalization

pull/38/head
dimitri 7 years ago
parent dafe5969ae
commit 49ab009115

@ -37,12 +37,12 @@ static int rt_callback(void * output_buffer, void * input_buffer, uint32_t num_b
{
if (status) std::cerr << "[rtaudio] buffer over or underflow" << std::endl;
// Playback
// Playback
if (buffer.getAvailableRead()) buffer.read((float*) output_buffer, BUFFER_LENGTH);
else memset(output_buffer, 0, BUFFER_LENGTH * sizeof(float));
// Recording
if (record_buffer.getAvailableWrite()) record_buffer.write((float*) input_buffer, BUFFER_LENGTH / 2);
// Recording
if (record_buffer.getAvailableWrite()) record_buffer.write((float*) input_buffer, BUFFER_LENGTH / 2);
return 0;
}
@ -62,9 +62,9 @@ AudioDevice::~AudioDevice()
{
rtaudio->stopStream();
if (rtaudio->isStreamOpen())
{
{
rtaudio->closeStream();
}
}
}
}
@ -77,7 +77,7 @@ bool AudioDevice::Open(const int deviceId)
outputParams.nChannels = info.numChannels;
outputParams.firstChannel = 0;
RtAudio::StreamParameters inputParams;
RtAudio::StreamParameters inputParams;
inputParams.deviceId = rtaudio->getDefaultInputDevice();
inputParams.nChannels = 1;
inputParams.firstChannel = 0;
@ -129,21 +129,21 @@ bool AudioDevice::Play(const std::vector<float> & data)
bool AudioDevice::Record(const uint32_t lengthInSamples, std::vector<float> & recordingBuffer)
{
uint64_t recordedSamples = 0;
uint64_t recordedSamples = 0;
// Allocate memory upfront (revisit this later...)
recordingBuffer.resize(lengthInSamples + (BUFFER_LENGTH)); // + a little padding
// Allocate memory upfront (revisit this later...)
recordingBuffer.resize(lengthInSamples + (BUFFER_LENGTH)); // + a little padding
while (recordedSamples < lengthInSamples)
{
if (record_buffer.getAvailableRead())
{
if (record_buffer.read(recordingBuffer.data() + recordedSamples, BUFFER_LENGTH / 2))
{
recordedSamples += (BUFFER_LENGTH / 2);
}
}
}
while (recordedSamples < lengthInSamples)
{
if (record_buffer.getAvailableRead())
{
if (record_buffer.read(recordingBuffer.data() + recordedSamples, BUFFER_LENGTH / 2))
{
recordedSamples += (BUFFER_LENGTH / 2);
}
}
}
return true;
return true;
}

@ -39,27 +39,27 @@ static const int32_t BUFFER_LENGTH = FRAME_SIZE * CHANNELS;
struct AudioDeviceInfo
{
uint32_t id;
uint32_t numChannels;
uint32_t sampleRate;
uint32_t frameSize;
bool isPlaying = false;
uint32_t id;
uint32_t numChannels;
uint32_t sampleRate;
uint32_t frameSize;
bool isPlaying = false;
};
class AudioDevice
{
std::unique_ptr<RtAudio> rtaudio;
std::unique_ptr<RtAudio> rtaudio;
protected:
AudioDevice(const AudioDevice& r) = delete;
AudioDevice & operator = (const AudioDevice& r) = delete;
AudioDevice(const AudioDevice& r) = delete;
AudioDevice & operator = (const AudioDevice& r) = delete;
public:
AudioDeviceInfo info;
AudioDevice(int numChannels, int sampleRate, int deviceId = -1);
~AudioDevice();
static void ListAudioDevices();
bool Open(const int deviceId);
bool Play(const std::vector<float> & data);
bool Record(const uint32_t lengthInSamples, std::vector<float> & recordingBuffer);
AudioDeviceInfo info;
AudioDevice(int numChannels, int sampleRate, int deviceId = -1);
~AudioDevice();
static void ListAudioDevices();
bool Open(const int deviceId);
bool Play(const std::vector<float> & data);
bool Record(const uint32_t lengthInSamples, std::vector<float> & recordingBuffer);
};
#endif

@ -17,77 +17,77 @@ using namespace nqr;
int main(int argc, const char **argv) try
{
AudioDevice::ListAudioDevices();
AudioDevice::ListAudioDevices();
const int desiredSampleRate = 44100;
const int desiredSampleRate = 44100;
const int desiredChannelCount = 2;
AudioDevice myDevice(desiredChannelCount, desiredSampleRate);
myDevice.Open(myDevice.info.id);
AudioDevice myDevice(desiredChannelCount, desiredSampleRate);
myDevice.Open(myDevice.info.id);
std::shared_ptr<AudioData> fileData = std::make_shared<AudioData>();
std::shared_ptr<AudioData> fileData = std::make_shared<AudioData>();
NyquistIO loader;
NyquistIO loader;
if (argc > 1)
{
std::string cli_arg = std::string(argv[1]);
loader.Load(fileData.get(), cli_arg);
}
else
{
// Circular libnyquist testing
//loader.Load(fileData.get(), "libnyquist_example_output.opus");
if (argc > 1)
{
std::string cli_arg = std::string(argv[1]);
loader.Load(fileData.get(), cli_arg);
}
else
{
// Circular libnyquist testing
//loader.Load(fileData.get(), "libnyquist_example_output.opus");
// 1-channel wave
//loader.Load(fileData.get(), "test_data/1ch/44100/8/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/16/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/24/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/64/test.wav");
// 1-channel wave
//loader.Load(fileData.get(), "test_data/1ch/44100/8/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/16/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/24/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/1ch/44100/64/test.wav");
// 2-channel wave
//loader.Load(fileData.get(), "test_data/2ch/44100/8/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/16/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/24/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/64/test.wav");
// 2-channel wave
//loader.Load(fileData.get(), "test_data/2ch/44100/8/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/16/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/24/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/32/test.wav");
//loader.Load(fileData.get(), "test_data/2ch/44100/64/test.wav");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_44_16_mono-ima4-reaper.wav");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_44_16_stereo-ima4-reaper.wav");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_44_16_mono-ima4-reaper.wav");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_44_16_stereo-ima4-reaper.wav");
// Multi-channel wave
//loader.Load(fileData.get(), "test_data/ad_hoc/6_channel_44k_16b.wav");
// Multi-channel wave
//loader.Load(fileData.get(), "test_data/ad_hoc/6_channel_44k_16b.wav");
// 1 + 2 channel ogg
//loader.Load(fileData.get(), "test_data/ad_hoc/LR_Stereo.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestLaugh_44k.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeatMono.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/BlockWoosh_Stereo.ogg");
// 1 + 2 channel ogg
//loader.Load(fileData.get(), "test_data/ad_hoc/LR_Stereo.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestLaugh_44k.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeatMono.ogg");
//loader.Load(fileData.get(), "test_data/ad_hoc/BlockWoosh_Stereo.ogg");
// 1 + 2 channel flac
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr8_Stereo_Dithered.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr16_Stereo.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr16_Mono.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr24_Stereo.flac");
// 1 + 2 channel flac
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr8_Stereo_Dithered.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr16_Stereo.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr16_Mono.flac");
//loader.Load(fileData.get(), "test_data/ad_hoc/KittyPurr24_Stereo.flac");
//auto memory = ReadFile("test_data/ad_hoc/KittyPurr24_Stereo.flac"); // broken
//loader.Load(fileData.get(), "flac", memory.buffer); // broken
// Single-channel opus
//loader.Load(fileData.get(), "test_data/ad_hoc/detodos.opus"); // "Firefox: From All, To All"
// Single-channel opus
//loader.Load(fileData.get(), "test_data/ad_hoc/detodos.opus"); // "Firefox: From All, To All"
// 1 + 2 channel wavpack
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Float32.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Float32_Mono.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int16.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int24.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int32.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int24_Mono.wv");
// 1 + 2 channel wavpack
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Float32.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Float32_Mono.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int16.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int24.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int32.wv");
//loader.Load(fileData.get(), "test_data/ad_hoc/TestBeat_Int24_Mono.wv");
// 1 + 2 channel musepack
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_stereo.mpc");
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_mono.mpc");
// 1 + 2 channel musepack
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_stereo.mpc");
//loader.Load(fileData.get(), "test_data/ad_hoc/44_16_mono.mpc");
// In-memory ogg
//auto memory = ReadFile("test_data/ad_hoc/BlockWoosh_Stereo.ogg");
@ -96,38 +96,38 @@ int main(int argc, const char **argv) try
// In-memory Mp3
auto memory = ReadFile("test_data/ad_hoc/acetylene.mp3");
loader.Load(fileData.get(), "mp3", memory.buffer);
}
}
/* Test Recording Capabilities of AudioDevice
fileData->samples.reserve(44100 * 5);
fileData->channelCount = 1;
fileData->frameSize = 32;
fileData->lengthSeconds = 5.0;
fileData->sampleRate = 44100;
std::cout << "Starting recording ..." << std::endl;
myDevice.Record(fileData->sampleRate * fileData->lengthSeconds, fileData->samples);
*/
/* Test Recording Capabilities of AudioDevice
fileData->samples.reserve(44100 * 5);
fileData->channelCount = 1;
fileData->frameSize = 32;
fileData->lengthSeconds = 5.0;
fileData->sampleRate = 44100;
std::cout << "Starting recording ..." << std::endl;
myDevice.Record(fileData->sampleRate * fileData->lengthSeconds, fileData->samples);
*/
if (fileData->sampleRate != desiredSampleRate)
{
std::cout << "[Warning - Sample Rate Mismatch] - file is sampled at " << fileData->sampleRate << " and output is " << desiredSampleRate << std::endl;
}
if (fileData->sampleRate != desiredSampleRate)
{
std::cout << "[Warning - Sample Rate Mismatch] - file is sampled at " << fileData->sampleRate << " and output is " << desiredSampleRate << std::endl;
}
std::cout << "Input Samples: " << fileData->samples.size() << std::endl;
std::cout << "Input Samples: " << fileData->samples.size() << std::endl;
// Convert mono to stereo for testing playback
if (fileData->channelCount == 1)
{
std::cout << "Playing MONO for: " << fileData->lengthSeconds << " seconds..." << std::endl;
std::vector<float> stereoCopy(fileData->samples.size() * 2);
MonoToStereo(fileData->samples.data(), stereoCopy.data(), fileData->samples.size());
myDevice.Play(stereoCopy);
}
else
{
std::cout << "Playing STEREO for: " << fileData->lengthSeconds << " seconds..." << std::endl;
myDevice.Play(fileData->samples);
}
// Convert mono to stereo for testing playback
if (fileData->channelCount == 1)
{
std::cout << "Playing MONO for: " << fileData->lengthSeconds << " seconds..." << std::endl;
std::vector<float> stereoCopy(fileData->samples.size() * 2);
MonoToStereo(fileData->samples.data(), stereoCopy.data(), fileData->samples.size());
myDevice.Play(stereoCopy);
}
else
{
std::cout << "Playing STEREO for: " << fileData->lengthSeconds << " seconds..." << std::endl;
myDevice.Play(fileData->samples);
}
// Test Opus Encoding
{
@ -143,21 +143,21 @@ int main(int argc, const char **argv) try
std::cout << "Encoder Status: " << encoderStatus << std::endl;
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
catch (const UnsupportedExtensionEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
std::cerr << "Caught: " << e.what() << std::endl;
}
catch (const LoadPathNotImplEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
std::cerr << "Caught: " << e.what() << std::endl;
}
catch (const LoadBufferNotImplEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
std::cerr << "Caught: " << e.what() << std::endl;
}
catch (const std::exception & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
std::cerr << "Caught: " << e.what() << std::endl;
}

@ -45,7 +45,7 @@ class RingBufferT
public:
// Constructs a RingBufferT with size = 0
RingBufferT() : mData(nullptr), mAllocatedSize(0), mWriteIndex(0), mReadIndex(0) {}
RingBufferT() : mData(nullptr), mAllocatedSize(0), mWriteIndex(0), mReadIndex(0) {}
// Constructs a RingBufferT with \a count maximum elements.
RingBufferT(size_t count) : mAllocatedSize(0) { resize(count); }

@ -1,44 +1,44 @@
/*
Copyright (c) 2019, Dimitri Diakopoulos All rights reserved.
copyright (c) 2019, dimitri diakopoulos all rights reserved.
Redistribution and use in source and binary forms, with or without
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
* redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* 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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
this software is provided by the copyright holders and contributors "as is"
and any express or implied warranties, including, but not limited to, the
implied warranties of merchantability and fitness for a particular purpose are
disclaimed. in no event shall the copyright holder or contributors be liable
for any direct, indirect, incidental, special, exemplary, or consequential
damages (including, but not limited to, procurement of substitute goods or
services; loss of use, data, or profits; or business interruption) however
caused and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
*/
#ifndef NYQUIST_ENCODERS_H
#define NYQUIST_ENCODERS_H
#ifndef nyquist_encoders_h
#define nyquist_encoders_h
#include "Common.h"
#include "common.h"
namespace nqr
{
// A simplistic encoder that takes a buffer of audio, conforms it to the user's
// EncoderParams preference, and writes to disk. Be warned, does not support resampling!
// @todo support dithering, samplerate conversion, etc.
int encode_wav_to_disk(const EncoderParams p, const AudioData * d, const std::string & path);
// a simplistic encoder that takes a buffer of audio, conforms it to the user's
// encoderparams preference, and writes to disk. be warned, does not support resampling!
// @todo support dithering, samplerate conversion, etc.
int encode_wav_to_disk(const encoderparams p, const audiodata * d, const std::string & path);
// Assume data adheres to EncoderParams, except for bit depth and fmt which are re-formatted
// to satisfy the Ogg/Opus spec.
int encode_opus_to_disk(const EncoderParams p, const AudioData * d, const std::string & path);
// assume data adheres to encoderparams, except for bit depth and fmt which are re-formatted
// to satisfy the ogg/opus spec.
int encode_opus_to_disk(const encoderparams p, const audiodata * d, const std::string & path);
} // end namespace nqr
#endif // end NYQUIST_ENCODERS_H
#endif // end nyquist_encoders_h

Loading…
Cancel
Save