From b7298ebcb5867b53fe53ed5987a6c2f1288d1fc1 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Tue, 26 May 2015 11:10:12 -0700 Subject: [PATCH 1/7] verify encoding on windows; fixup a few warnings --- include/libnyquist/PostProcess.h | 2 +- src/OpusDecoder.cpp | 4 ++-- src/WavPackDecoder.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/libnyquist/PostProcess.h b/include/libnyquist/PostProcess.h index 8d3d3cd..0ce39e5 100644 --- a/include/libnyquist/PostProcess.h +++ b/include/libnyquist/PostProcess.h @@ -87,7 +87,7 @@ void StereoToMono(const T * src, T * dest, size_t N) template void MonoToStereo(const T * src, T * dest, size_t N) { - for(int i = 0, j = 0; i < N; ++i, j += 2) + for(size_t i = 0, j = 0; i < N; ++i, j += 2) { dest[j] = src[i]; dest[j + 1] = src[i]; diff --git a/src/OpusDecoder.cpp b/src/OpusDecoder.cpp index dd45acd..221240b 100644 --- a/src/OpusDecoder.cpp +++ b/src/OpusDecoder.cpp @@ -89,13 +89,13 @@ public: size_t readInternal(size_t requestedFrameCount, size_t frameOffset = 0) { - float *buffer = (float *) d->samples.data(); + float * buffer = (float *) d->samples.data(); size_t framesRemaining = requestedFrameCount; size_t totalFramesRead = 0; while(0 < framesRemaining) { - int64_t framesRead = op_read_float(fileHandle, buffer, (int)(framesRemaining * d->channelCount), nullptr); + auto framesRead = size_t(op_read_float(fileHandle, buffer, (int)(framesRemaining * d->channelCount), nullptr)); // EOF if(!framesRead) diff --git a/src/WavPackDecoder.cpp b/src/WavPackDecoder.cpp index 63d4160..f078a82 100644 --- a/src/WavPackDecoder.cpp +++ b/src/WavPackDecoder.cpp @@ -56,7 +56,7 @@ public: auto totalSamples = size_t(getTotalSamples()); int mode = WavpackGetMode(context); - int isFloatingPoint = (MODE_FLOAT & mode); + bool isFloatingPoint = (MODE_FLOAT & mode); d->sourceFormat = MakeFormatForBits(bitdepth, isFloatingPoint, false); From b386bbf4d5aedc88e9a5b247e082561bd0c61bf3 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Tue, 26 May 2015 13:10:36 -0700 Subject: [PATCH 2/7] fix flac export symbol issue --- .../libnyquist-examples.vcxproj/libnyquist-examples.vcxproj | 2 +- examples/src/Main.cpp | 4 ++-- include/libnyquist/FlacDecoder.h | 3 +++ libnyquist.vcxproj/libnyquist.vcxproj | 2 +- libnyquist.vcxproj/libnyquist.vcxproj.filters | 6 +++--- src/FlacDecoder.cpp | 2 ++ src/FlacDependencies.c | 3 ++- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/libnyquist-examples.vcxproj/libnyquist-examples.vcxproj b/examples/libnyquist-examples.vcxproj/libnyquist-examples.vcxproj index 96e9a56..2f29138 100644 --- a/examples/libnyquist-examples.vcxproj/libnyquist-examples.vcxproj +++ b/examples/libnyquist-examples.vcxproj/libnyquist-examples.vcxproj @@ -81,7 +81,7 @@ true false true - true + false diff --git a/examples/src/Main.cpp b/examples/src/Main.cpp index 567a578..f7c9a4f 100644 --- a/examples/src/Main.cpp +++ b/examples/src/Main.cpp @@ -33,7 +33,7 @@ int main() //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/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"); @@ -51,7 +51,7 @@ int main() //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_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"); diff --git a/include/libnyquist/FlacDecoder.h b/include/libnyquist/FlacDecoder.h index 2ea2fba..392478f 100644 --- a/include/libnyquist/FlacDecoder.h +++ b/include/libnyquist/FlacDecoder.h @@ -26,6 +26,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef FLAC_DECODER_H #define FLAC_DECODER_H +// http://lists.xiph.org/pipermail/flac-dev/2012-March/003276.html +#define FLAC__NO_DLL + #include "AudioDecoder.h" #include diff --git a/libnyquist.vcxproj/libnyquist.vcxproj b/libnyquist.vcxproj/libnyquist.vcxproj index 0571693..1d2bd59 100644 --- a/libnyquist.vcxproj/libnyquist.vcxproj +++ b/libnyquist.vcxproj/libnyquist.vcxproj @@ -19,7 +19,7 @@ - + diff --git a/libnyquist.vcxproj/libnyquist.vcxproj.filters b/libnyquist.vcxproj/libnyquist.vcxproj.filters index f8e001d..c1df4ee 100644 --- a/libnyquist.vcxproj/libnyquist.vcxproj.filters +++ b/libnyquist.vcxproj/libnyquist.vcxproj.filters @@ -46,9 +46,6 @@ src\deps - - src\deps - src @@ -82,6 +79,9 @@ src + + src\deps + diff --git a/src/FlacDecoder.cpp b/src/FlacDecoder.cpp index f2b6ea6..f626154 100644 --- a/src/FlacDecoder.cpp +++ b/src/FlacDecoder.cpp @@ -25,6 +25,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FlacDecoder.h" #include "flac/all.h" +#include "flac/stream_decoder.h" + #include "AudioDecoder.h" using namespace nqr; diff --git a/src/FlacDependencies.c b/src/FlacDependencies.c index 16d9b01..772075a 100644 --- a/src/FlacDependencies.c +++ b/src/FlacDependencies.c @@ -27,7 +27,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define VERSION "1.3.1" #define FLAC__NO_DLL 1 - +#define FLAC__USE_VISIBILITY_ATTR 1 + #if (_MSC_VER) #pragma warning (push) #pragma warning (disable: 181 111 4267 4996 4244 4701 4702 4133 4100 4127 4206 4312 4505 4365 4005 4013 4334) From b5ffea133ba47bb4d859382c82c52934001ce373 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Tue, 26 May 2015 14:27:15 -0700 Subject: [PATCH 3/7] comment out debug information --- src/Common.cpp | 2 +- src/OpusDecoder.cpp | 4 +--- src/WavDecoder.cpp | 8 ++++---- src/WavPackDecoder.cpp | 2 -- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Common.cpp b/src/Common.cpp index b087981..a76092b 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -29,7 +29,7 @@ using namespace nqr; NyquistFileBuffer nqr::ReadFile(std::string pathToFile) { - std::cout << "[Debug] Open: " << pathToFile << std::endl; + //std::cout << "[Debug] Open: " << pathToFile << std::endl; FILE * audioFile = fopen(pathToFile.c_str(), "rb"); diff --git a/src/OpusDecoder.cpp b/src/OpusDecoder.cpp index 221240b..3693cc5 100644 --- a/src/OpusDecoder.cpp +++ b/src/OpusDecoder.cpp @@ -65,9 +65,7 @@ public: const OpusHead *header = op_head(fileHandle, 0); int originalSampleRate = header->input_sample_rate; - - std::cout << "Original Sample Rate: " << originalSampleRate << std::endl; - + d->sampleRate = OPUS_SAMPLE_RATE; d->channelCount = (uint32_t) header->channel_count; d->sourceFormat = MakeFormatForBits(32, true, false); diff --git a/src/WavDecoder.cpp b/src/WavDecoder.cpp index e1c8c2b..493f6b7 100644 --- a/src/WavDecoder.cpp +++ b/src/WavDecoder.cpp @@ -98,24 +98,24 @@ int WavDecoder::LoadFromBuffer(AudioData * data, const std::vector & me data->sampleRate = wavHeader.sample_rate; data->frameSize = wavHeader.frame_size; - std::cout << wavHeader << std::endl; + //std::cout << wavHeader << std::endl; bool scanForFact = false; bool grabExtensibleData = false; if (wavHeader.format == WaveFormatCode::FORMAT_PCM) { - std::cout << "[format id] pcm" << std::endl; + //std::cout << "[format id] pcm" << std::endl; } else if (wavHeader.format == WaveFormatCode::FORMAT_IEEE) { - std::cout << "[format id] ieee" << std::endl; + //std::cout << "[format id] ieee" << std::endl; scanForFact = true; } else if (wavHeader.format == WaveFormatCode::FORMAT_EXT) { // Used when (1) PCM data has more than 16 bits; (2) channels > 2; (3) bits/sample !== container size; (4) channel/speaker mapping specified - std::cout << "[format id] extended" << std::endl; + //std::cout << "[format id] extended" << std::endl; scanForFact = true; grabExtensibleData = true; } diff --git a/src/WavPackDecoder.cpp b/src/WavPackDecoder.cpp index f078a82..db1961d 100644 --- a/src/WavPackDecoder.cpp +++ b/src/WavPackDecoder.cpp @@ -113,8 +113,6 @@ public: //if (framesRead == 0) // break; - std::cout << framesRead << std::endl; - totalFramesRead += framesRead; framesRemaining -= framesRead; } From 9961412bdf8bc3780ce6dba8131cc00612232c3b Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Tue, 23 Jun 2015 18:45:24 -0700 Subject: [PATCH 4/7] x64 target for windows --- libnyquist.vcxproj/libnyquist.sln | 6 +++ libnyquist.vcxproj/libnyquist.vcxproj | 55 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/libnyquist.vcxproj/libnyquist.sln b/libnyquist.vcxproj/libnyquist.sln index 98bb8c6..f811bbe 100644 --- a/libnyquist.vcxproj/libnyquist.sln +++ b/libnyquist.vcxproj/libnyquist.sln @@ -8,13 +8,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 Release|Win32 = Release|Win32 + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Debug|Win32.ActiveCfg = Debug|Win32 {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Debug|Win32.Build.0 = Debug|Win32 + {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Debug|x64.ActiveCfg = Debug|x64 + {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Debug|x64.Build.0 = Debug|x64 {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Release|Win32.ActiveCfg = Release|Win32 {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Release|Win32.Build.0 = Release|Win32 + {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Release|x64.ActiveCfg = Release|x64 + {0EEC3739-F60A-4B90-8B75-9E1AFF28106A}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/libnyquist.vcxproj/libnyquist.vcxproj b/libnyquist.vcxproj/libnyquist.vcxproj index 1d2bd59..89238f5 100644 --- a/libnyquist.vcxproj/libnyquist.vcxproj +++ b/libnyquist.vcxproj/libnyquist.vcxproj @@ -5,10 +5,18 @@ Debug Win32 + + Debug + x64 + Release Win32 + + Release + x64 + @@ -66,6 +74,12 @@ v120 MultiByte + + StaticLibrary + true + v120 + MultiByte + StaticLibrary false @@ -73,15 +87,28 @@ true MultiByte + + StaticLibrary + false + v120 + true + MultiByte + + + + + + + @@ -96,6 +123,18 @@ true + + + Level3 + Disabled + true + _CRT_SECURE_NO_WARNINGS;_MBCS;D_SCL_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNING;WIN32;_WIN32;USE_ALLOCA;OPUS_BUILD;%(PreprocessorDefinitions) + $(ProjectDir)..\third_party\;$(ProjectDir)..\include\libnyquist\;$(ProjectDir)..\third_party\libvorbis\include;$(ProjectDir)..\third_party\libogg\include;$(ProjectDir)..\third_party\wavpack\include;$(ProjectDir)..\third_party\flac\src\include;$(ProjectDir)..\third_party\opus\celt;$(ProjectDir)..\third_party\opus\libopus\include;$(ProjectDir)..\third_party\opus\libopus\src;$(ProjectDir)..\third_party\opus\opusfile\include;$(ProjectDir)..\third_party\opus\opusfile\src;$(ProjectDir)..\third_party\opus\opusfile\src\include;$(ProjectDir)..\third_party\opus\silk;$(ProjectDir)..\third_party\opus\silk\float;%(AdditionalIncludeDirectories) + + + true + + Level3 @@ -112,6 +151,22 @@ true + + + Level3 + MaxSpeed + true + true + true + _CRT_SECURE_NO_WARNINGS;_MBCS;D_SCL_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNING;WIN32;_WIN32;USE_ALLOCA;OPUS_BUILD;%(PreprocessorDefinitions) + $(ProjectDir)..\third_party\;$(ProjectDir)..\include\libnyquist\;$(ProjectDir)..\third_party\libvorbis\include;$(ProjectDir)..\third_party\libogg\include;$(ProjectDir)..\third_party\wavpack\include;$(ProjectDir)..\third_party\flac\src\include;$(ProjectDir)..\third_party\opus\celt;$(ProjectDir)..\third_party\opus\libopus\include;$(ProjectDir)..\third_party\opus\libopus\src;$(ProjectDir)..\third_party\opus\opusfile\include;$(ProjectDir)..\third_party\opus\opusfile\src;$(ProjectDir)..\third_party\opus\opusfile\src\include;$(ProjectDir)..\third_party\opus\silk;$(ProjectDir)..\third_party\opus\silk\float;%(AdditionalIncludeDirectories) + + + true + true + true + + From 4c5c8e1737d843f5ec98c5bdb2250a75ce80bc9e Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Wed, 15 Jul 2015 13:59:59 -0700 Subject: [PATCH 5/7] support for NyquistIO loading from buffer (if the decoder supports it) --- include/libnyquist/AudioDecoder.h | 1 + src/AudioDecoder.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libnyquist/AudioDecoder.h b/include/libnyquist/AudioDecoder.h index a9cdd7f..0e9fdcd 100644 --- a/include/libnyquist/AudioDecoder.h +++ b/include/libnyquist/AudioDecoder.h @@ -64,6 +64,7 @@ public: ~NyquistIO(); int Load(AudioData * data, const std::string & path); + int Load(AudioData *data, std::string extension, std::vector & buffer); bool IsFileSupported(const std::string path) const; diff --git a/src/AudioDecoder.cpp b/src/AudioDecoder.cpp index 450590f..3ace882 100644 --- a/src/AudioDecoder.cpp +++ b/src/AudioDecoder.cpp @@ -74,6 +74,35 @@ int NyquistIO::Load(AudioData * data, const std::string & path) return IOError::UnknownError; } +int NyquistIO::Load(AudioData *data, std::string extension, std::vector & buffer) +{ + if (decoderTable.find(extension) == decoderTable.end()) + { + return IOError::ExtensionNotSupported; + } + + if (decoderTable.size() > 0) + { + auto decoder = GetDecoderForExtension(extension); + + try + { + return decoder->LoadFromBuffer(data, buffer); + } + catch (std::exception e) + { + std::cerr << "Caught fatal exception: " << e.what() << std::endl; + } + } + else + { + return IOError::NoDecodersLoaded; + } + + // Should never be reached + return IOError::UnknownError; +} + bool NyquistIO::IsFileSupported(const std::string path) const { auto fileExtension = ParsePathForExtension(path); From 63f6799ec76a9690a65f3751181cc447f0f5d507 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Wed, 15 Jul 2015 14:21:21 -0700 Subject: [PATCH 6/7] fix const --- include/libnyquist/AudioDecoder.h | 2 +- src/AudioDecoder.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libnyquist/AudioDecoder.h b/include/libnyquist/AudioDecoder.h index 0e9fdcd..a1ef51c 100644 --- a/include/libnyquist/AudioDecoder.h +++ b/include/libnyquist/AudioDecoder.h @@ -64,7 +64,7 @@ public: ~NyquistIO(); int Load(AudioData * data, const std::string & path); - int Load(AudioData *data, std::string extension, std::vector & buffer); + int Load(AudioData *data, std::string extension, const std::vector & buffer); bool IsFileSupported(const std::string path) const; diff --git a/src/AudioDecoder.cpp b/src/AudioDecoder.cpp index 3ace882..4b48bfd 100644 --- a/src/AudioDecoder.cpp +++ b/src/AudioDecoder.cpp @@ -74,7 +74,7 @@ int NyquistIO::Load(AudioData * data, const std::string & path) return IOError::UnknownError; } -int NyquistIO::Load(AudioData *data, std::string extension, std::vector & buffer) +int NyquistIO::Load(AudioData * data, std::string extension, const std::vector & buffer) { if (decoderTable.find(extension) == decoderTable.end()) { From e90a861b63243db1ed8bad66abeafaa1d00838e4 Mon Sep 17 00:00:00 2001 From: Dimitri Diakopoulos Date: Thu, 8 Oct 2015 21:32:45 -0700 Subject: [PATCH 7/7] Update README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6abd646..cc49f96 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ # Libnyquist Libnyquist is a small C++11 library for reading sampled audio data from disk or memory. It's ideal to use as an audio asset frontend for games, audio sequencers, music players, and more. -*The library is under active development and the API should be considered unstable. Check the Github issues queue for the state of the alpha.* - The library steers away from patent-encumbered formats and those with non-BSD licensed codec implementations (such as MP3 and AAC, respectively). Libnyquist is meant to be statically linked, which is not the case with other popular libraries like libsndfile (LGPL). Furthermore, the library is not concerned with legacy format support (for instance, A-law PCM encoding or SND files). -While untested, there are no technical conditions that preclude compilation on other platforms with C++11 support (Android 4.4+, Linux, iOS, etc). +While untested, there are no technical conditions that preclude compilation on other platforms with C++11 support (Android NDK r10e+, Linux, iOS, etc). ## Format Support @@ -20,16 +18,16 @@ Regardless of input bit depth, the library hands over an interleaved float array * WavPack * Core Audio Format (Apple Lossless / AIFF) (WIP) -## Platform Support -* Windows & Visual Studio 2013+ -* OSX & XCode 5+ +## Supported Project Files +* Visual Studio 2013 +* XCode 6 ## Known Issues * Ogg and Opus have conflicting mdct files. Their sources were modified such that they compile cleanly together in the same project. * Streaming is not supported for any file formats. ## Encoding -WIP for 1.0-beta +Simple but robust WAV format encoder now included. Extentions in the near future might include Ogg. ## License Libyquist is released under the 2-Clause BSD license. All dependencies and codecs are under similar open licenses.