cleanup example main file a bit

pull/15/head
Dimitri 10 years ago
parent dd9b4f9075
commit 68fd66a1fc

@ -1,3 +1,7 @@
// 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.
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma comment(lib, "dsound.lib") #pragma comment(lib, "dsound.lib")
#endif #endif
@ -11,96 +15,89 @@
using namespace nqr; using namespace nqr;
int main( int argc, const char **argv ) try int main(int argc, const char **argv) try
{ {
AudioDevice::ListAudioDevices(); AudioDevice::ListAudioDevices();
int desiredSampleRate = 44100; int desiredSampleRate = 44100;
AudioDevice myDevice(2, desiredSampleRate); AudioDevice myDevice(2, desiredSampleRate);
myDevice.Open(myDevice.info.id); myDevice.Open(myDevice.info.id);
AudioData * fileData = new AudioData();
NyquistIO loader;
WavEncoder encoder;
try
{
// Circular libnyquist testing!
//auto result = loader.Load(fileData, "encoded.wav");
//auto result = loader.Load(fileData, "test_data/1ch/44100/8/test.wav");
//auto result = loader.Load(fileData, "test_data/1ch/44100/16/test.wav");
//auto result = loader.Load(fileData, "test_data/1ch/44100/24/test.wav");
//auto result = loader.Load(fileData, "test_data/1ch/44100/32/test.wav");
//auto result = loader.Load(fileData, "test_data/1ch/44100/64/test.wav");
//auto result = loader.Load(fileData, "test_data/2ch/44100/8/test.wav");
//auto result = loader.Load(fileData, "test_data/2ch/44100/16/test.wav");
//auto result = loader.Load(fileData, "test_data/2ch/44100/24/test.wav");
//auto result = loader.Load(fileData, "test_data/2ch/44100/32/test.wav");
//auto result = loader.Load(fileData, "test_data/2ch/44100/64/test.wav");
//auto result = loader.Load(fileData, "test_data/ad_hoc/6_channel_44k_16b.wav");
//auto result = loader.Load(fileData, "test_data/ad_hoc/LR_Stereo.ogg");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestLaugh_44k.ogg");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat.ogg");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeatMono.ogg");
//auto result = loader.Load(fileData, "test_data/ad_hoc/BlockWoosh_Stereo.ogg");
//auto result = loader.Load(fileData, "test_data/ad_hoc/KittyPurr8_Stereo_Dithered.flac");
//auto result = loader.Load(fileData, "test_data/ad_hoc/KittyPurr16_Stereo.flac");
//auto result = loader.Load(fileData, "test_data/ad_hoc/KittyPurr16_Mono.flac");
//auto result = loader.Load(fileData, "test_data/ad_hoc/KittyPurr24_Stereo.flac");
//auto result = loader.Load(fileData, "test_data/ad_hoc/detodos.opus"); // "Firefox: From All, To All"
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Float32.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Float32_Mono.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int16.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int24.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int32.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int24_Mono.wv");
//auto result = loader.Load(fileData, "test_data/ad_hoc/44_16_stereo.mpc");
//auto result = loader.Load(fileData, "test_data/ad_hoc/44_16_mono.mpc");
//Block-split-stereo-ima4-reaper.wav
//auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_44_16_mono-ima4-reaper.wav");
loader.Load(fileData, argc > 1 ? argv[1] : "test_data/ad_hoc/TestBeat_44_16_stereo-ima4-reaper.wav");
}
catch(const UnsupportedExtensionEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
}
catch(const LoadPathNotImplEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
}
catch(const LoadBufferNotImplEx & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
}
catch (const std::exception & e)
{
std::cerr << "Caught: " << e.what() << std::endl;
std::exit(1);
}
// Libnyquist does not do sample rate conversion AudioData * fileData = new AudioData();
NyquistIO loader;
if (argc > 1)
{
std::string cli_arg = std::string(argv[1]);
loader.Load(fileData, cli_arg);
}
else
{
// Circular libnyquist testing
//loader.Load(fileData, "encoded.wav");
// 1-channel wave
//loader.Load(fileData, "test_data/1ch/44100/8/test.wav");
//loader.Load(fileData, "test_data/1ch/44100/16/test.wav");
//loader.Load(fileData, "test_data/1ch/44100/24/test.wav");
//loader.Load(fileData, "test_data/1ch/44100/32/test.wav");
//loader.Load(fileData, "test_data/1ch/44100/64/test.wav");
// 2-channel wave
//loader.Load(fileData, "test_data/2ch/44100/8/test.wav");
//loader.Load(fileData, "test_data/2ch/44100/16/test.wav");
//loader.Load(fileData, "test_data/2ch/44100/24/test.wav");
//loader.Load(fileData, "test_data/2ch/44100/32/test.wav");
//loader.Load(fileData, "test_data/2ch/44100/64/test.wav");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_44_16_mono-ima4-reaper.wav");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_44_16_stereo-ima4-reaper.wav");
// Multi-channel wave
//loader.Load(fileData, "test_data/ad_hoc/6_channel_44k_16b.wav");
// 1 + 2 channel ogg
//loader.Load(fileData, "test_data/ad_hoc/LR_Stereo.ogg");
//loader.Load(fileData, "test_data/ad_hoc/TestLaugh_44k.ogg");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat.ogg");
//loader.Load(fileData, "test_data/ad_hoc/TestBeatMono.ogg");
//loader.Load(fileData, "test_data/ad_hoc/BlockWoosh_Stereo.ogg");
// 1 + 2 channel flac
//loader.Load(fileData, "test_data/ad_hoc/KittyPurr8_Stereo_Dithered.flac");
//loader.Load(fileData, "test_data/ad_hoc/KittyPurr16_Stereo.flac");
//loader.Load(fileData, "test_data/ad_hoc/KittyPurr16_Mono.flac");
//loader.Load(fileData, "test_data/ad_hoc/KittyPurr24_Stereo.flac");
// 2-channel opus
//loader.Load(fileData, "test_data/ad_hoc/detodos.opus"); // "Firefox: From All, To All"
// 1 + 2 channel wavepack
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Float32.wv");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Float32_Mono.wv");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int16.wv");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int24.wv");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int32.wv");
//loader.Load(fileData, "test_data/ad_hoc/TestBeat_Int24_Mono.wv");
// 1 + 2 channel musepack
loader.Load(fileData, "test_data/ad_hoc/44_16_stereo.mpc");
//loader.Load(fileData, "test_data/ad_hoc/44_16_mono.mpc");
}
// Libnyquist does not (currently) perform sample rate conversion
if (fileData->sampleRate != desiredSampleRate) if (fileData->sampleRate != desiredSampleRate)
{ {
std::cout << "[Warning - Sample Rate Mismatch] - file is sampled at " << fileData->sampleRate << " and output is " << desiredSampleRate << std::endl; std::cout << "[Warning - Sample Rate Mismatch] - file is sampled at " << fileData->sampleRate << " and output is " << desiredSampleRate << std::endl;
} }
// Convert mono to stereo for testing playback // Convert mono to stereo for testing playback
if (fileData->channelCount == 1) if (fileData->channelCount == 1)
{ {
std::cout << "Playing MONO for: " << fileData->lengthSeconds << " seconds..." << std::endl; std::cout << "Playing MONO for: " << fileData->lengthSeconds << " seconds..." << std::endl;
std::vector<float> stereoCopy(fileData->samples.size() * 2); std::vector<float> stereoCopy(fileData->samples.size() * 2);
MonoToStereo(fileData->samples.data(), stereoCopy.data(), fileData->samples.size()); MonoToStereo(fileData->samples.data(), stereoCopy.data(), fileData->samples.size());
myDevice.Play(stereoCopy); myDevice.Play(stereoCopy);
} }
else else
@ -108,27 +105,28 @@ int main( int argc, const char **argv ) try
std::cout << "Playing for: " << fileData->lengthSeconds << " seconds..." << std::endl; std::cout << "Playing for: " << fileData->lengthSeconds << " seconds..." << std::endl;
myDevice.Play(fileData->samples); myDevice.Play(fileData->samples);
} }
// Test wav file encoder {
int encoderStatus = encoder.WriteFile({2, PCM_16, DITHER_NONE}, fileData, "encoded.wav"); WavEncoder enc;
std::cout << "Encoder Status: " << encoderStatus << std::endl; int encoderStatus = enc.WriteFile({2, PCM_16, DITHER_NONE }, fileData, "encoded.wav");
std::cout << "Encoder Status: " << encoderStatus << std::endl;
return 0; }
return EXIT_SUCCESS;
} }
catch(const UnsupportedExtensionEx & e) catch (const UnsupportedExtensionEx & e)
{ {
std::cerr << "Caught: " << e.what() << std::endl; std::cerr << "Caught: " << e.what() << std::endl;
} }
catch(const LoadPathNotImplEx & e) catch (const LoadPathNotImplEx & e)
{ {
std::cerr << "Caught: " << e.what() << std::endl; std::cerr << "Caught: " << e.what() << std::endl;
} }
catch(const LoadBufferNotImplEx & e) catch (const LoadBufferNotImplEx & e)
{ {
std::cerr << "Caught: " << e.what() << std::endl; std::cerr << "Caught: " << e.what() << std::endl;
} }
catch (const std::exception & e) catch (const std::exception & e)
{ {
std::cerr << "Caught: " << e.what() << std::endl; std::cerr << "Caught: " << e.what() << std::endl;
std::exit(1);
} }

Loading…
Cancel
Save