adpcm
Dimitri Diakopoulos 11 years ago
commit 2d8d4543b7

@ -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.

@ -81,7 +81,7 @@
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

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

@ -64,6 +64,7 @@ public:
~NyquistIO();
int Load(AudioData * data, const std::string & path);
int Load(AudioData *data, std::string extension, const std::vector<uint8_t> & buffer);
bool IsFileSupported(const std::string path) const;

@ -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 <map>

@ -87,7 +87,7 @@ void StereoToMono(const T * src, T * dest, size_t N)
template <typename T>
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];

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

@ -5,10 +5,18 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(ProjectDir)..\src\AudioDecoder.cpp" />
@ -19,7 +27,7 @@
<ClCompile Include="$(ProjectDir)..\src\AudioDevice.cpp" />
<ClCompile Include="$(ProjectDir)..\src\WavPackDecoder.cpp" />
<ClCompile Include="$(ProjectDir)..\src\CafDecoder.cpp" />
<ClCompile Include="$(ProjectDir)..\src\FlacDependencies.c" />
<ClCompile Include="..\src\FlacDependencies.c" />
<ClCompile Include="$(ProjectDir)..\src\OpusDependencies.c" />
<ClCompile Include="$(ProjectDir)..\src\VorbisDecoder.cpp" />
<ClCompile Include="$(ProjectDir)..\src\VorbisDependencies.c" />
@ -66,6 +74,12 @@
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
@ -73,15 +87,28 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@ -96,6 +123,18 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_MBCS;D_SCL_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNING;WIN32;_WIN32;USE_ALLOCA;OPUS_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(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)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@ -112,6 +151,22 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_MBCS;D_SCL_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNING;WIN32;_WIN32;USE_ALLOCA;OPUS_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(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)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

@ -46,9 +46,6 @@
<ClCompile Include="$(ProjectDir)..\src\OpusDependencies.c">
<Filter>src\deps</Filter>
</ClCompile>
<ClCompile Include="$(ProjectDir)..\src\FlacDependencies.c">
<Filter>src\deps</Filter>
</ClCompile>
<ClCompile Include="$(ProjectDir)..\src\AudioDecoder.cpp">
<Filter>src</Filter>
</ClCompile>
@ -82,6 +79,9 @@
<ClCompile Include="$(ProjectDir)..\src\RiffUtils.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\FlacDependencies.c">
<Filter>src\deps</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(ProjectDir)..\include\libnyquist\OpusDecoder.h">

@ -74,6 +74,35 @@ int NyquistIO::Load(AudioData * data, const std::string & path)
return IOError::UnknownError;
}
int NyquistIO::Load(AudioData * data, std::string extension, const std::vector<uint8_t> & 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);

@ -29,6 +29,7 @@ using namespace nqr;
NyquistFileBuffer nqr::ReadFile(std::string pathToFile)
{
//std::cout << "[Debug] Open: " << pathToFile << std::endl;
FILE * audioFile = fopen(pathToFile.c_str(), "rb");
if (!audioFile)

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

@ -27,6 +27,7 @@ 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)

@ -66,8 +66,6 @@ public:
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);
@ -89,13 +87,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)

@ -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);
@ -113,8 +113,6 @@ public:
//if (framesRead == 0)
// break;
std::cout << framesRead << std::endl;
totalFramesRead += framesRead;
framesRemaining -= framesRead;
}

Loading…
Cancel
Save