diff --git a/include/libnyquist/Common.h b/include/libnyquist/Common.h index 7e9101d..54ec118 100644 --- a/include/libnyquist/Common.h +++ b/include/libnyquist/Common.h @@ -221,10 +221,11 @@ struct AudioData { int channelCount; int sampleRate; - int bitDepth; double lengthSeconds; size_t frameSize; // channels * bits per sample std::vector samples; + PCMFormat sourceFormat; + //@todo: add field: channel layout //@todo: add field: lossy / lossless //@todo: audio data loaded (for metadata only) @@ -247,6 +248,7 @@ struct NyquistFileBuffer NyquistFileBuffer ReadFile(std::string pathToFile); int GetFormatBitsPerSample(PCMFormat f); +PCMFormat MakeFormatForBits(int bits, bool floatingPt, bool isSigned); } // end namespace nqr diff --git a/src/Common.cpp b/src/Common.cpp index 33c5a60..4b6742c 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -167,3 +167,22 @@ int nqr::GetFormatBitsPerSample(PCMFormat f) return 0; } } + +PCMFormat nqr::MakeFormatForBits(int bits, bool floatingPt, bool isSigned) +{ + switch(bits) + { + case 8: + return (isSigned) ? PCM_S8 : PCM_U8; + case 16: + return PCM_16; + case 24: + return PCM_24; + case 32: + return (floatingPt) ? PCM_FLT : PCM_32; + case 64: + return (floatingPt) ? PCM_DBL : PCM_64; + default: + return PCM_END; + } +} diff --git a/src/FlacDecoder.cpp b/src/FlacDecoder.cpp index 7809220..a0970a0 100644 --- a/src/FlacDecoder.cpp +++ b/src/FlacDecoder.cpp @@ -78,7 +78,7 @@ public: // N.B.: "Currently the reference encoder and decoders only support up to 24 bits per sample." - PCMFormat internalFmt = PCMFormat::PCM_END; + d->sourceFormat = PCMFormat::PCM_END; switch (d->bitDepth) { @@ -97,7 +97,7 @@ public: } // Next, process internal buffer into the user-visible samples array - ConvertToFloat32(d->samples.data(), internalBuffer.data(), totalSamples, internalFmt); + ConvertToFloat32(d->samples.data(), internalBuffer.data(), totalSamples, d->sourceFormat); } else @@ -120,7 +120,7 @@ public: { d->sampleRate = info.sample_rate; d->channelCount = info.channels; // Assert 1 to 8 - d->bitDepth = info.bits_per_sample; // Assert 4 to 32 + d->sourceF = info.bits_per_sample; // Assert 4 to 32 d->frameSize = info.channels * info.bits_per_sample; const size_t bytesPerSample = d->bitDepth / 8; diff --git a/src/WavEncoder.cpp b/src/WavEncoder.cpp index 03a54aa..2784912 100644 --- a/src/WavEncoder.cpp +++ b/src/WavEncoder.cpp @@ -106,7 +106,7 @@ int WavEncoder::WriteFile(const EncoderParams p, const AudioData * d, const std: // Debugging -- assume IEEE_Float - auto LookupB + auto what = GetFormatBitsPerSample(d->sourceFmt); fout.write(reinterpret_cast(d->samples.data()), numSamplesBytes); // Find size