adpcm
Dimitri Diakopoulos 10 years ago
parent f3e03876a0
commit 0f5d5069db

@ -65,7 +65,9 @@ int main()
//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");
//auto result = loader.Load(fileData, "test_data/ad_hoc/44_16_mono.mpc");
auto result = loader.Load(fileData, "test_data/ad_hoc/TestBeat_44_16_stereo-ima4.wav");
std::cout << "[Debug] Loader Status: " << result << std::endl;
}

@ -204,7 +204,7 @@ inline std::array<uint8_t, 3> Unpack(uint32_t a)
//////////////////////////
// Signed maxes, defined for readabilty/convenience
#define NQR_INT16_MAX 32768.f
#define NQR_INT16_MAX 32767.f
#define NQR_INT24_MAX 8388608.f
#define NQR_INT32_MAX 2147483648.f
@ -236,6 +236,8 @@ enum PCMFormat
PCM_END
};
template<class T> T clamp(T a, T mn, T mx) { return std::max(std::min(a, mx), mn); }
// Src data is aligned to PCMFormat
// @todo normalize?
void ConvertToFloat32(float * dst, const uint8_t * src, const size_t N, PCMFormat f);
@ -243,6 +245,9 @@ void ConvertToFloat32(float * dst, const uint8_t * src, const size_t N, PCMForma
// Src data is always aligned to 4 bytes (WavPack, primarily)
void ConvertToFloat32(float * dst, const int32_t * src, const size_t N, PCMFormat f);
// Src data is always aligned to 2 bytes (IMA ADPCM, primarily)
void ConvertToFloat32(float * dst, const int16_t * src, const size_t N, PCMFormat f);
void ConvertFromFloat32(uint8_t * dst, const float * src, const size_t N, PCMFormat f, DitherType t = DITHER_NONE);
//////////////////////////

@ -104,6 +104,7 @@
08B91D971AC73B8A00335131 /* OpusDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OpusDecoder.cpp; path = src/OpusDecoder.cpp; sourceTree = SOURCE_ROOT; };
08B91D981AC73B8A00335131 /* WavDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WavDecoder.cpp; path = src/WavDecoder.cpp; sourceTree = SOURCE_ROOT; };
08B91D991AC73B8A00335131 /* WavPackDecoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WavPackDecoder.cpp; path = src/WavPackDecoder.cpp; sourceTree = SOURCE_ROOT; };
08C83B7C1C25D7780071EED6 /* IMA4Util.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = IMA4Util.h; path = include/libnyquist/IMA4Util.h; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -237,6 +238,7 @@
083DB3F41B091C1E00FB0661 /* WavEncoder.h */,
08B91D8E1AC73B8000335131 /* WavDecoder.h */,
08B91D8F1AC73B8000335131 /* WavPackDecoder.h */,
08C83B7C1C25D7780071EED6 /* IMA4Util.h */,
);
name = include;
sourceTree = "<group>";

@ -40,16 +40,13 @@ NyquistIO::NyquistIO()
BuildDecoderTable();
}
NyquistIO::~NyquistIO()
{
}
NyquistIO::~NyquistIO() { }
int NyquistIO::Load(AudioData * data, const std::string & path)
{
if (IsFileSupported(path))
{
if (decoderTable.size() > 0)
if (decoderTable.size())
{
auto fileExtension = ParsePathForExtension(path);
auto decoder = GetDecoderForExtension(fileExtension);
@ -82,7 +79,7 @@ int NyquistIO::Load(AudioData * data, std::string extension, const std::vector<u
return IOError::ExtensionNotSupported;
}
if (decoderTable.size() > 0)
if (decoderTable.size())
{
auto decoder = GetDecoderForExtension(extension);
try

@ -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");
if (!audioFile)
@ -145,9 +145,18 @@ void nqr::ConvertToFloat32(float * dst, const int32_t * src, const size_t N, PCM
}
}
void nqr::ConvertToFloat32(float * dst, const int16_t * src, const size_t N, PCMFormat f)
{
assert(f != PCM_END);
if (f == PCM_16)
{
for (size_t i = 0; i < N; ++i)
dst[i] = int16_to_float32(Read16(src[i]));
}
}
void nqr::ConvertFromFloat32(uint8_t * dst, const float * src, const size_t N, PCMFormat f, DitherType t)
{
assert(f != PCM_END);
Dither dither(t);

Loading…
Cancel
Save