diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2020-01-12 22:20:51 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2020-01-12 22:20:51 +0300 |
commit | 83d5e5d3652608478b5f18212bd3fec2338ae954 (patch) | |
tree | f8565d3d74bc68ae1b7c0710ceeb1a2bb57303e5 | |
parent | 5ae5ed6b6c6f0a49372288e309244ccd0b54060f (diff) | |
download | atracdenc-83d5e5d3652608478b5f18212bd3fec2338ae954.tar.gz |
[atrac3] Initial joint stereo mode support.
-rw-r--r-- | src/atrac/atrac3_bitstream.cpp | 24 | ||||
-rw-r--r-- | src/atrac1denc.h | 1 | ||||
-rw-r--r-- | src/atrac3denc.cpp | 23 | ||||
-rw-r--r-- | src/atrac3denc.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/oma.cpp | 6 | ||||
-rw-r--r-- | src/oma.h | 5 | ||||
-rw-r--r-- | src/oma/liboma/src/liboma.c | 1 |
8 files changed, 50 insertions, 16 deletions
diff --git a/src/atrac/atrac3_bitstream.cpp b/src/atrac/atrac3_bitstream.cpp index b0995fc..8164258 100644 --- a/src/atrac/atrac3_bitstream.cpp +++ b/src/atrac/atrac3_bitstream.cpp @@ -455,6 +455,14 @@ vector<uint32_t> TAtrac3BitStreamWriter::CalcBitsAllocation(const std::vector<TS return bitsPerEachBlock; } +void WriteJsParams(NBitStream::TBitStream* bs) +{ + bs->Write(0, 1); + bs->Write(7, 3); + for (int i = 0; i < 4; i++) { + bs->Write(3, 2); + } +} void TAtrac3BitStreamWriter::WriteSoundUnit(const vector<TSingleChannelElement>& singleChannelElements) { @@ -468,12 +476,13 @@ void TAtrac3BitStreamWriter::WriteSoundUnit(const vector<TSingleChannelElement>& NBitStream::TBitStream* bitStream = &bitStreams[channel]; - if (Params.Js) { - //TODO - abort(); + if (Params.Js && channel == 1) { + WriteJsParams(bitStream); + bitStream->Write(3, 2); } else { bitStream->Write(0x28, 6); //0x28 - id } + const uint8_t numQmfBand = subbandInfo.GetQmfNum(); bitStream->Write(numQmfBand - 1, 2); @@ -504,8 +513,13 @@ void TAtrac3BitStreamWriter::WriteSoundUnit(const vector<TSingleChannelElement>& abort(); std::vector<char> channelData = bitStream->GetBytes(); assert(bitStream->GetSizeInBits() <= 8 * (size_t)Params.FrameSz / 2); - channelData.resize(Params.FrameSz >> 1); - OutBuffer.insert(OutBuffer.end(), channelData.begin(), channelData.end()); + if (Params.Js && channel == 1) { + channelData.resize(Params.FrameSz >> 1); + OutBuffer.insert(OutBuffer.end(), channelData.rbegin(), channelData.rend()); + } else { + channelData.resize(Params.FrameSz >> 1); + OutBuffer.insert(OutBuffer.end(), channelData.begin(), channelData.end()); + } } //No mone mode for atrac3, just make duplicate of first channel diff --git a/src/atrac1denc.h b/src/atrac1denc.h index 33bbc76..8468c74 100644 --- a/src/atrac1denc.h +++ b/src/atrac1denc.h @@ -19,7 +19,6 @@ #pragma once #include "pcmengin.h" #include "aea.h" -#include "oma.h" #include "transient_detector.h" #include "atrac/atrac1.h" #include "atrac/atrac1_qmf.h" diff --git a/src/atrac3denc.cpp b/src/atrac3denc.cpp index 9bb7eb2..f6d8758 100644 --- a/src/atrac3denc.cpp +++ b/src/atrac3denc.cpp @@ -274,6 +274,19 @@ void TAtrac3Processor::CreateSubbandInfo(TFloat* in[4], } } +void TAtrac3Processor::Matrixing() +{ + for (uint32_t subband = 0; subband < 4; subband++) { + TFloat* pair[2] = {PcmBuffer.GetSecond(subband * 2), PcmBuffer.GetSecond(subband * 2 + 1)}; + TFloat tmp[2]; + for (uint32_t sample = 0; sample < 256; sample++) { + tmp[0] = pair[0][sample]; + tmp[1] = pair[1][sample]; + pair[0][sample] = (tmp[0] + tmp[1]) / 2.0; + pair[1][sample] = (tmp[0] - tmp[1]) / 2.0; + } + } +} TPCMEngine<TFloat>::TProcessLambda TAtrac3Processor::GetEncodeLambda() { @@ -289,7 +302,6 @@ TPCMEngine<TFloat>::TProcessLambda TAtrac3Processor::GetEncodeLambda() assert(SingleChannelElements.size() == meta.Channels); for (uint32_t channel = 0; channel < SingleChannelElements.size(); channel++) { - vector<TFloat> specs(1024); TFloat src[NumSamples]; for (size_t i = 0; i < NumSamples; ++i) { @@ -300,7 +312,14 @@ TPCMEngine<TFloat>::TProcessLambda TAtrac3Processor::GetEncodeLambda() TFloat* p[4] = {PcmBuffer.GetSecond(channel), PcmBuffer.GetSecond(channel+2), PcmBuffer.GetSecond(channel+4), PcmBuffer.GetSecond(channel+6)}; SplitFilterBank[channel].Split(&src[0], p); } - + } + + if (Params.ConteinerParams->Js) { + Matrixing(); + } + + for (uint32_t channel = 0; channel < SingleChannelElements.size(); channel++) { + vector<TFloat> specs(1024); TSce* sce = &SingleChannelElements[channel]; sce->SubbandInfo.Reset(); diff --git a/src/atrac3denc.h b/src/atrac3denc.h index f9a9c61..163ecfd 100644 --- a/src/atrac3denc.h +++ b/src/atrac3denc.h @@ -19,7 +19,6 @@ #pragma once #include "config.h" #include "pcmengin.h" -#include "oma.h" #include "aea.h" #include "atrac/atrac3.h" #include "atrac/atrac3_qmf.h" @@ -113,6 +112,7 @@ public: void ResetTransientParamsHistory(int channel, int band); void SetTransientParamsHistory(int channel, int band, const TTransientParam& params); const TTransientParam& GetTransientParamsHistory(int channel, int band) const; + void Matrixing(); public: TAtrac3Processor(TCompressedIOPtr&& oma, NAtrac3::TAtrac3EncoderSettings&& encoderSettings); diff --git a/src/main.cpp b/src/main.cpp index f4d0f6b..a036d1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -206,7 +206,8 @@ static void PrepareAtrac3Encoder(const string& inFile, "test", numChannels, (int32_t)numFrames, OMAC_ID_ATRAC3, - encoderSettings.ConteinerParams->FrameSz)); + encoderSettings.ConteinerParams->FrameSz, + encoderSettings.ConteinerParams->Js)); pcmEngine->reset(new TPCMEngine<TFloat>(4096, numChannels, TPCMEngine<TFloat>::TReaderPtr(wavIO->GetPCMReader<TFloat>()))); @@ -275,7 +276,6 @@ int main_(int argc, char* const* argv) break; case O_BITRATE: bitrate = checkedStoi(optarg, 32, 384, 0); - std::cout << "BITRATE" << bitrate << std::endl; break; case O_BFUIDXCONST: bfuIdxConst = checkedStoi(optarg, 1, 32, 0); diff --git a/src/oma.cpp b/src/oma.cpp index 4aed863..2f55173 100644 --- a/src/oma.cpp +++ b/src/oma.cpp @@ -17,17 +17,19 @@ */ #include "oma.h" + #include <stdlib.h> using std::string; using std::vector; using std::unique_ptr; -TOma::TOma(const string& filename, const string& title, uint8_t numChannel, uint32_t numFrames, int cid, uint32_t framesize) { +TOma::TOma(const string& filename, const string& title, uint8_t numChannel, + uint32_t numFrames, int cid, uint32_t framesize, bool jointStereo) { oma_info_t info; info.codec = cid; info.samplerate = 44100; - info.channel_format = OMA_STEREO; + info.channel_format = jointStereo ? OMA_STEREO_JS : OMA_STEREO; info.framesize = framesize; File = oma_open(filename.c_str(), OMAM_W, &info); if (!File) @@ -19,13 +19,14 @@ #pragma once #include "compressed_io.h" + #include "oma/liboma/include/oma.h" class TOma : public ICompressedIO { OMAFILE* File; public: - TOma(const std::string& filename, const std::string& title, uint8_t numChannel, uint32_t numFrames, int cid, - uint32_t framesize); + TOma(const std::string& filename, const std::string& title, uint8_t numChannel, + uint32_t numFrames, int cid, uint32_t framesize, bool jointStereo); ~TOma(); std::unique_ptr<TFrame> ReadFrame() override; void WriteFrame(std::vector<char> data) override; diff --git a/src/oma/liboma/src/liboma.c b/src/oma/liboma/src/liboma.c index d09a964..6efff72 100644 --- a/src/oma/liboma/src/liboma.c +++ b/src/oma/liboma/src/liboma.c @@ -118,7 +118,6 @@ static int oma_write_atrac3_header(uint32_t *params, oma_info_t *info) { if (samplerate_idx == -1) return -1; const uint32_t framesz = info->framesize / 8; - fprintf(stderr, "framesize: %d\n", framesz); if (framesz > 0x3FF) return -1; *params = swapbyte32_on_le((OMAC_ID_ATRAC3 << 24) | (js << 17) | ((uint32_t)samplerate_idx << 13) | framesz); |