diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2025-05-31 22:39:38 +0200 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2025-05-31 22:39:38 +0200 |
commit | 1c7f2f821fb965af468cdf2a14df3ff75cc1c352 (patch) | |
tree | 1bc92237122b75c67afc326af207cf3cc9eb3d6c /src/main.cpp | |
parent | 272af27a3d148bd13e8f15640e53ca70c64ccb9b (diff) | |
parent | 6dfc60e9d4791c3385908c61ad75c4a0093ea1eb (diff) | |
download | atracdenc-1c7f2f821fb965af468cdf2a14df3ff75cc1c352.tar.gz |
Merge branch 'at3plus-dev'
It looks like we are able to encode ATRAC3PLUS compatible bitstream so we can merge at3p development branch in to the main branch.
Current limitation for AT3P mode:
- Only 352 Kbps (proper bit allocation and some psychoacoustic must be implemented)
- GHA sometime works with error (but huge bitrate hide it)
- No VLC, VQ, delta encoding
- No noise substitution
- No gain control
- No window shape switching
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index faf88e9..861495f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ #include "config.h" #include "atrac1denc.h" #include "atrac3denc.h" +#include "atrac3p.h" #ifdef PLATFORM_WINDOWS #include <windows.h> @@ -89,6 +90,13 @@ static int checkedStoi(const char* data, int min, int max, int def) } } +enum EMode { + E_ENCODE = 1, + E_DECODE = 2, + E_ATRAC3 = 4, + E_ATRAC3PLUS = 8 +}; + enum EOptions { O_ENCODE = 'e', @@ -102,6 +110,7 @@ enum EOptions O_NOSTDOUT = '4', O_NOTONAL = 5, O_NOGAINCONTROL = 6, + O_ADVANCED_OPT = 7, }; static void CheckInputFormat(const TWav* p) @@ -243,9 +252,68 @@ static void PrepareAtrac3Encoder(const string& inFile, atracProcessor->reset(new TAtrac3Encoder(std::move(omaIO), std::move(encoderSettings))); } +static void PrepareAtrac3PEncoder(const string& inFile, + const string& outFile, + const bool noStdOut, + int numChannels, + uint64_t* totalSamples, + const TWavPtr& wavIO, + TPcmEnginePtr* pcmEngine, + TAtracProcessorPtr* atracProcessor, + const char* advancedOpt) +{ + *totalSamples = wavIO->GetTotalSamples(); + const uint64_t numFrames = (*totalSamples) / 2048; + if (numFrames >= UINT32_MAX) { + std::cerr << "Number of input samples exceeds output format limitation," + "the result will be incorrect" << std::endl; + } + + const string ext = GetFileExt(outFile); + + TCompressedOutputPtr omaIO; + + string contName; + if (ext == "wav" || ext == "at3") { + throw std::runtime_error("Not implemented"); + } else if (ext == "rm") { + throw std::runtime_error("RealMedia container is not supported for ATRAC3PLUS"); + } else { + contName = "OMA"; + omaIO.reset(new TOma(outFile, + "test", + numChannels, + (int32_t)numFrames, OMAC_ID_ATRAC3PLUS, + 2048, + false)); + } + + if (!noStdOut) + cout << "Input:\n Filename: " << inFile + << "\n Channels: " << (int)numChannels + << "\n SampleRate: " << wavIO->GetSampleRate() + << "\n Duration (sec): " << *totalSamples / wavIO->GetSampleRate() + << "\nOutput:\n Filename: " << outFile + << "\n Codec: ATRAC3Plus" + << "\n Container: " << contName + //<< "\n Bitrate: " << encoderSettings.ConteinerParams->Bitrate + << endl; + + pcmEngine->reset(new TPCMEngine(4096, + numChannels, + TPCMEngine::TReaderPtr(wavIO->GetPCMReader()))); + TAt3PEnc::TSettings settings; + if (advancedOpt) { + TAt3PEnc::ParseAdvancedOpt(advancedOpt, settings); + } + atracProcessor->reset(new TAt3PEnc(std::move(omaIO), numChannels, settings)); +} + + int main_(int argc, char* const* argv) { const char* myName = argv[0]; + const char* advancedOpt = nullptr; static struct option longopts[] = { { "encode", optional_argument, NULL, O_ENCODE }, { "decode", no_argument, NULL, O_DECODE }, @@ -256,6 +324,7 @@ int main_(int argc, char* const* argv) { "notransient", optional_argument, NULL, O_NOTRANSIENT}, { "nostdout", no_argument, NULL, O_NOSTDOUT}, { "nogaincontrol", no_argument, NULL, O_NOGAINCONTROL}, + { "advanced", required_argument, NULL, O_ADVANCED_OPT}, { NULL, 0, NULL, 0} }; @@ -282,6 +351,8 @@ int main_(int argc, char* const* argv) } else if (strcmp(optarg, "atrac3_lp4") == 0) { mode |= E_ATRAC3; bitrate = 64; + } else if (strcmp(optarg, "atrac3plus") == 0) { + mode |= E_ATRAC3PLUS; } else if (strcmp(optarg, "atrac1") == 0) { // this is the default } else { @@ -336,6 +407,9 @@ int main_(int argc, char* const* argv) case O_NOGAINCONTROL: noGainControl = true; break; + case O_ADVANCED_OPT: + advancedOpt = optarg; + break; default: printUsage(myName); return 1; @@ -399,6 +473,14 @@ int main_(int argc, char* const* argv) pcmFrameSz = TAtrac3Data::NumSamples;; } break; + case (E_ENCODE | E_ATRAC3PLUS): + { + wavIO = OpenWavFile(inFile); + PrepareAtrac3PEncoder(inFile, outFile, noStdOut, wavIO->GetChannelNum(), + &totalSamples, wavIO, &pcmEngine, &atracProcessor, advancedOpt); + pcmFrameSz = 2048; + } + break; default: { throw std::runtime_error("Processing mode was not specified"); |