diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2015-11-07 00:50:58 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2015-11-07 00:50:58 +0300 |
commit | 66659c6386c792a3ae9f910578e1b671fd9213ad (patch) | |
tree | a1fbb2e7b24e331234e41c7ea953235dde53e61c /src | |
parent | ae793aaa94741b3ca25eff25dd3e7d0fc4f4417e (diff) | |
download | atracdenc-66659c6386c792a3ae9f910578e1b671fd9213ad.tar.gz |
changes aea header:
- write length in header (qhimdtransfer writes it, and we will)
- make first frame empty (it is a hack, but without it ffmpeg based
players detects aea file as mpeg. I need aea specification ;-))
Diffstat (limited to 'src')
-rw-r--r-- | src/aea.cpp | 18 | ||||
-rw-r--r-- | src/aea.h | 5 | ||||
-rw-r--r-- | src/main.cpp | 4 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/aea.cpp b/src/aea.cpp index fc041cb..f5c2514 100644 --- a/src/aea.cpp +++ b/src/aea.cpp @@ -24,7 +24,7 @@ TAea::TMeta TAea::ReadMeta(const string& filename) { } -TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, int channelNum) { +TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, int channelNum, uint32_t numFrames) { FILE* fp = fopen(filename.c_str(), "w"); if (!fp) throw TAeaIOError("Can't open file to write", errno); @@ -37,12 +37,20 @@ TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, int ch strncpy(&buf[4], title.c_str(), 16); buf[19] = 0; // buf[210] = 0x08; + *(uint32_t*)&buf[260] = numFrames; buf[264] = (char)channelNum; if (fwrite(&buf[0], TAea::AeaMetaSize, 1, fp) != 1) { const int errnum = errno; fclose(fp); throw TAeaIOError("Can't read AEA header", errnum); } + static char dummy[212]; + if (fwrite(&dummy[0], 212, 1, fp) != 1) { + const int errnum = errno; + fclose(fp); + throw TAeaIOError("Can't read AEA header", errnum); + } + return {fp, buf}; } @@ -51,8 +59,8 @@ TAea::TAea(const string& filename) : Meta(ReadMeta(filename)) { } -TAea::TAea(const string& filename, const string& title, int channelNum) - : Meta(CreateMeta(filename, title, channelNum)) { +TAea::TAea(const string& filename, const string& title, int channelNum, uint32_t numFrames) + : Meta(CreateMeta(filename, title, channelNum, numFrames)) { } TAea::~TAea() { @@ -82,6 +90,10 @@ void TAea::WriteFrame(std::unique_ptr<TAea::TFrame>&& frame) { } */ void TAea::WriteFrame(std::vector<char> data) { + if (FirstWrite) { + FirstWrite = false; + return; + } data.resize(212); if (fwrite(data.data(), data.size(), 1, Meta.AeaFile) != 1) { const int errnum = errno; @@ -30,11 +30,12 @@ class TAea { std::array<char, AeaMetaSize> AeaHeader; } Meta; static TAea::TMeta ReadMeta(const std::string& filename); - static TAea::TMeta CreateMeta(const std::string& filename, const std::string& title, int numChannel); + static TAea::TMeta CreateMeta(const std::string& filename, const std::string& title, int numChannel, uint32_t numFrames); + bool FirstWrite = true; public: typedef std::array<char, 212> TFrame; TAea(const std::string& filename); - TAea(const std::string& filename, const std::string& title, int numChannel); + TAea(const std::string& filename, const std::string& title, int numChannel, uint32_t numFrames); ~TAea(); std::unique_ptr<TFrame> ReadFrame(); // void WriteFrame(std::unique_ptr<TAea::TFrame>&& frame); diff --git a/src/main.cpp b/src/main.cpp index 71c8fb2..fc4bced 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,9 +89,9 @@ int main(int argc, char* const* argv) { wavIO = TWavPtr(new TWav(inFile)); const TWavHeader& wavHeader = wavIO->GetWavHeader(); const int numChannels = wavHeader.NumOfChan; - aeaIO = TAeaPtr(new TAea(outFile, "test", numChannels)); - pcmEngine = new TPCMEngine<double>(4096, numChannels, TPCMEngine<double>::TReaderPtr(wavIO->GetPCMReader<double>())); totalSamples = wavHeader.ChunkSize; + aeaIO = TAeaPtr(new TAea(outFile, "test", numChannels, totalSamples / 2 / 512)); + pcmEngine = new TPCMEngine<double>(4096, numChannels, TPCMEngine<double>::TReaderPtr(wavIO->GetPCMReader<double>())); cout << "Input file: " << inFile << "Channels: " << numChannels << "SampleRate: " << wavHeader.SamplesPerSec << "TotalSamples: " << totalSamples << endl; } else if (mode == E_DECODE) { aeaIO = TAeaPtr(new TAea(inFile)); |