diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2019-05-17 01:21:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2019-05-17 01:21:41 +0300 |
commit | 72c3f6ec998e8acfade1e1b40abf32af21eb282b (patch) | |
tree | 2e5444a0711aa29a24e39ae2404d5c5f562af19b | |
parent | ed9629395ce9696164c1d617d573a47982e82169 (diff) | |
download | atracdenc-72c3f6ec998e8acfade1e1b40abf32af21eb282b.tar.gz |
Fix some VS compilation warnings0.0.1
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/aea.cpp | 38 | ||||
-rw-r--r-- | src/aea.h | 20 | ||||
-rw-r--r-- | src/atrac/atrac3_bitstream.cpp | 9 | ||||
-rw-r--r-- | src/atrac3denc.h | 4 | ||||
-rw-r--r-- | src/compressed_io.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 21 | ||||
-rw-r--r-- | src/oma.cpp | 16 | ||||
-rw-r--r-- | src/oma.h | 8 | ||||
-rw-r--r-- | src/oma/liboma/include/oma.h | 2 | ||||
-rw-r--r-- | src/wav.cpp | 10 | ||||
-rw-r--r-- | src/wav.h | 6 |
13 files changed, 81 insertions, 60 deletions
@@ -5,7 +5,7 @@ Building: You need: * C++11 compiler. -* cmake > 2.8 +* cmake >= 3.0 * libsndfiles binary: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 146b670..019acf3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") if (WIN32) add_compile_definitions(PLATFORM_WINDOWS) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) include_directories("platform/win/getopt") set(SOURCE_PCM_IO_LIB platform/win/pcm_io_mf/pcm_io_mf.cpp diff --git a/src/aea.cpp b/src/aea.cpp index 4387825..4589a60 100644 --- a/src/aea.cpp +++ b/src/aea.cpp @@ -23,12 +23,15 @@ #include <string.h> using std::string; +using std::array; +using std::vector; +using std::unique_ptr; TAea::TMeta TAea::ReadMeta(const string& filename) { FILE* fp = fopen(filename.c_str(), "rb"); if (!fp) throw TAeaIOError("Can't open file to read", errno); - std::array<char, AeaMetaSize> buf; + array<char, AeaMetaSize> buf; if (fread(&buf[0], TAea::AeaMetaSize, 1, fp) != 1) { const int errnum = errno; fclose(fp); @@ -42,11 +45,11 @@ TAea::TMeta TAea::ReadMeta(const string& filename) { } -TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, int channelNum, uint32_t numFrames) { +TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, uint8_t channelNum, uint32_t numFrames) { FILE* fp = fopen(filename.c_str(), "wb"); if (!fp) throw TAeaIOError("Can't open file to write", errno); - std::array<char, AeaMetaSize> buf; + array<char, AeaMetaSize> buf; memset(&buf[0], 0, AeaMetaSize); buf[0] = 0x00; buf[1] = 0x08; @@ -74,23 +77,23 @@ TAea::TMeta TAea::CreateMeta(const string& filename, const string& title, int ch TAea::TAea(const string& filename) - : Meta(ReadMeta(filename)) { - } + : Meta(ReadMeta(filename)) +{} -TAea::TAea(const string& filename, const string& title, int channelNum, uint32_t numFrames) - : Meta(CreateMeta(filename, title, channelNum, numFrames)) { - } +TAea::TAea(const string& filename, const string& title, uint8_t channelNum, uint32_t numFrames) + : Meta(CreateMeta(filename, title, channelNum, numFrames)) +{} TAea::~TAea() { fclose(Meta.AeaFile); } -std::string TAea::GetName() const { +string TAea::GetName() const { return string(&Meta.AeaHeader[4]); } -std::unique_ptr<TAea::TFrame> TAea::ReadFrame() { - std::unique_ptr<TAea::TFrame>frame(new TFrame(212)); +unique_ptr<TAea::TFrame> TAea::ReadFrame() { + unique_ptr<TAea::TFrame>frame(new TFrame(212)); if(fread(frame->Get(), frame->Size(), 1, Meta.AeaFile) != 1) { const int errnum = errno; fclose(Meta.AeaFile); @@ -107,7 +110,7 @@ void TAea::WriteFrame(std::unique_ptr<TAea::TFrame>&& frame) { } } */ -void TAea::WriteFrame(std::vector<char> data) { +void TAea::WriteFrame(vector<char> data) { if (FirstWrite) { FirstWrite = false; return; @@ -120,13 +123,18 @@ void TAea::WriteFrame(std::vector<char> data) { } } -int TAea::GetChannelNum() const { +uint8_t TAea::GetChannelNum() const { return Meta.AeaHeader[264]; } -long long TAea::GetLengthInSamples() const { + +uint64_t TAea::GetLengthInSamples() const { +#ifdef PLATFORM_WINDOWS + const int fd = _fileno(Meta.AeaFile); +#else const int fd = fileno(Meta.AeaFile); +#endif struct stat sb; fstat(fd, &sb); const uint32_t nChannels = Meta.AeaHeader[264] ? Meta.AeaHeader[264] : 1; - return 512 * ((sb.st_size - TAea::AeaMetaSize) / 212 / nChannels - 5); + return (uint64_t)512 * ((sb.st_size - TAea::AeaMetaSize) / 212 / nChannels - 5); } @@ -53,17 +53,15 @@ class TAea : public IAtrac1IO { 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, uint32_t numFrames); + static TAea::TMeta CreateMeta(const std::string& filename, const std::string& title, uint8_t numChannel, uint32_t numFrames); bool FirstWrite = true; public: - TAea(const std::string& filename); - TAea(const std::string& filename, const std::string& title, int numChannel, uint32_t numFrames); - ~TAea(); - std::unique_ptr<TFrame> ReadFrame() override; - void WriteFrame(std::vector<char> data) override; - std::string GetName() const override; - int GetChannelNum() const override; - long long GetLengthInSamples() const override; + TAea(const std::string& filename); + TAea(const std::string& filename, const std::string& title, uint8_t numChannel, uint32_t numFrames); + ~TAea(); + std::unique_ptr<TFrame> ReadFrame() override; + void WriteFrame(std::vector<char> data) override; + std::string GetName() const override; + uint8_t GetChannelNum() const override; + uint64_t GetLengthInSamples() const override; }; - - diff --git a/src/atrac/atrac3_bitstream.cpp b/src/atrac/atrac3_bitstream.cpp index d39faa2..8b7ede9 100644 --- a/src/atrac/atrac3_bitstream.cpp +++ b/src/atrac/atrac3_bitstream.cpp @@ -276,7 +276,7 @@ uint16_t TAtrac3BitStreamWriter::EncodeTonalComponents(const TSingleChannelEleme const vector<uint32_t>& allocTable, NBitStream::TBitStream* bitStream) { - const uint16_t bitsUsedOld = bitStream ? bitStream->GetSizeInBits() : 0; + const uint16_t bitsUsedOld = bitStream ? (uint16_t)bitStream->GetSizeInBits() : 0; const std::vector<TTonalBlock>& tonalComponents = sce.TonalBlocks; const TAtrac3Data::SubbandInfo& subbandInfo = sce.SubbandInfo; const uint8_t numQmfBand = subbandInfo.GetQmfNum(); @@ -317,13 +317,14 @@ uint16_t TAtrac3BitStreamWriter::EncodeTonalComponents(const TSingleChannelEleme continue; } assert(curGroup.SubGroupMap.size()); + assert(curGroup.SubGroupMap.size() < UINT8_MAX); for (uint8_t subgroup = 0; subgroup < curGroup.SubGroupMap.size(); ++subgroup) { const uint8_t subGroupStartPos = curGroup.SubGroupMap[subgroup]; const uint8_t subGroupEndPos = (subgroup < curGroup.SubGroupMap.size() - 1) ? - curGroup.SubGroupMap[subgroup+1] : curGroup.SubGroupPtr.size(); + curGroup.SubGroupMap[subgroup+1] : (uint8_t)curGroup.SubGroupPtr.size(); assert(subGroupEndPos > subGroupStartPos); //number of coded values are same in group - const uint8_t codedValues = curGroup.SubGroupPtr[0]->ScaledBlock.Values.size(); + const uint8_t codedValues = (uint8_t)curGroup.SubGroupPtr[0]->ScaledBlock.Values.size(); //Number of tonal component for each 64spec block. Used to set qmf band flags and simplify band encoding loop union { @@ -394,7 +395,7 @@ uint16_t TAtrac3BitStreamWriter::EncodeTonalComponents(const TSingleChannelEleme const TFloat mul = MaxQuant[std::min((uint32_t)(i>>3), (uint32_t)7)]; assert(codedValues == curGroup.SubGroupPtr[k]->ScaledBlock.Values.size()); for (uint32_t z = 0; z < curGroup.SubGroupPtr[k]->ScaledBlock.Values.size(); ++z) { - mantisas[z] = round(curGroup.SubGroupPtr[k]->ScaledBlock.Values[z] * mul); + mantisas[z] = lrint(curGroup.SubGroupPtr[k]->ScaledBlock.Values[z] * mul); } //VLCEnc diff --git a/src/atrac3denc.h b/src/atrac3denc.h index adf6df6..f9a9c61 100644 --- a/src/atrac3denc.h +++ b/src/atrac3denc.h @@ -43,10 +43,10 @@ namespace NAtracDEnc { inline uint16_t RelationToIdx(TFloat x) { if (x <= 0.5) { x = 1.0 / std::max(x, (TFloat)0.00048828125); - return 4 + GetFirstSetBit(std::trunc(x)); + return 4 + GetFirstSetBit((int32_t)std::trunc(x)); } else { x = std::min(x, (TFloat)16.0); - return 4 - GetFirstSetBit(std::trunc(x)); + return 4 - GetFirstSetBit((int32_t)std::trunc(x)); } } diff --git a/src/compressed_io.h b/src/compressed_io.h index 7fca4f1..090ddf4 100644 --- a/src/compressed_io.h +++ b/src/compressed_io.h @@ -44,8 +44,8 @@ public: virtual void WriteFrame(std::vector<char> data) = 0; virtual std::unique_ptr<TFrame> ReadFrame() = 0; virtual std::string GetName() const = 0; - virtual int GetChannelNum() const = 0; - virtual long long GetLengthInSamples() const = 0; + virtual uint8_t GetChannelNum() const = 0; + virtual uint64_t GetLengthInSamples() const = 0; virtual ~ICompressedIO() {} }; diff --git a/src/main.cpp b/src/main.cpp index 4fb1ee9..bd961ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,17 +139,21 @@ static void PrepareAtrac1Encoder(const string& inFile, CheckInputFormat(wavPtr); wavIO->reset(wavPtr); } - const int numChannels = (*wavIO)->GetChannelNum(); + const uint8_t numChannels = (*wavIO)->GetChannelNum(); *totalSamples = (*wavIO)->GetTotalSamples(); //TODO: recheck it - const uint32_t numFrames = numChannels * (*totalSamples) / TAtrac1Data::NumSamples; - TCompressedIOPtr aeaIO = TCompressedIOPtr(new TAea(outFile, "test", numChannels, numFrames)); + const uint64_t numFrames = numChannels * (*totalSamples) / TAtrac1Data::NumSamples; + if (numFrames >= UINT32_MAX) { + std::cerr << "Number of input samples exceeds output format limitation," + "the result will be incorrect" << std::endl; + } + TCompressedIOPtr aeaIO = TCompressedIOPtr(new TAea(outFile, "test", numChannels, (uint32_t)numFrames)); pcmEngine->reset(new TPCMEngine<TFloat>(4096, numChannels, TPCMEngine<TFloat>::TReaderPtr((*wavIO)->GetPCMReader<TFloat>()))); if (!noStdOut) cout << "Input file: " << inFile - << "\n Channels: " << numChannels + << "\n Channels: " << (int)numChannels << "\n SampleRate: " << (*wavIO)->GetSampleRate() << "\n TotalSamples: " << totalSamples << endl; @@ -166,7 +170,7 @@ static void PrepareAtrac1Decoder(const string& inFile, { TCompressedIOPtr aeaIO = TCompressedIOPtr(new TAea(inFile)); *totalSamples = aeaIO->GetLengthInSamples(); - uint32_t length = aeaIO->GetLengthInSamples(); + uint64_t length = aeaIO->GetLengthInSamples(); if (!noStdOut) cout << "Name: " << aeaIO->GetName() << "\n Channels: " << aeaIO->GetChannelNum() @@ -193,10 +197,15 @@ static void PrepareAtrac3Encoder(const string& inFile, std::cout << "bitrate " << encoderSettings.ConteinerParams->Bitrate << std::endl; const int numChannels = encoderSettings.SourceChannels; *totalSamples = wavIO->GetTotalSamples(); + const uint64_t numFrames = numChannels * ((*totalSamples) / 512); + if (numFrames >= UINT32_MAX) { + std::cerr << "Number of input samples exceeds output format limitation," + "the result will be incorrect" << std::endl; + } TCompressedIOPtr omaIO = TCompressedIOPtr(new TOma(outFile, "test", numChannels, - numChannels * (*totalSamples) / 512, OMAC_ID_ATRAC3, + (int32_t)numFrames, OMAC_ID_ATRAC3, encoderSettings.ConteinerParams->FrameSz)); pcmEngine->reset(new TPCMEngine<TFloat>(4096, numChannels, diff --git a/src/oma.cpp b/src/oma.cpp index ceeaf69..4aed863 100644 --- a/src/oma.cpp +++ b/src/oma.cpp @@ -19,7 +19,11 @@ #include "oma.h" #include <stdlib.h> -TOma::TOma(const std::string& filename, const std::string& title, int numChannel, uint32_t numFrames, int cid, uint32_t framesize) { +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) { oma_info_t info; info.codec = cid; info.samplerate = 44100; @@ -34,27 +38,27 @@ TOma::~TOma() { oma_close(File); } -std::unique_ptr<ICompressedIO::TFrame> TOma::ReadFrame() { +unique_ptr<ICompressedIO::TFrame> TOma::ReadFrame() { abort(); return nullptr; } -void TOma::WriteFrame(std::vector<char> data) { +void TOma::WriteFrame(vector<char> data) { if (oma_write(File, &data[0], 1) == -1) { fprintf(stderr, "write error\n"); abort(); } } -std::string TOma::GetName() const { +string TOma::GetName() const { abort(); return {}; } -int TOma::GetChannelNum() const { +uint8_t TOma::GetChannelNum() const { return 2; //for ATRAC3 } -long long TOma::GetLengthInSamples() const { +uint64_t TOma::GetLengthInSamples() const { abort(); return 0; } @@ -21,15 +21,15 @@ #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, int 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); ~TOma(); std::unique_ptr<TFrame> ReadFrame() override; void WriteFrame(std::vector<char> data) override; std::string GetName() const override; - int GetChannelNum() const override; - long long GetLengthInSamples() const override; + uint8_t GetChannelNum() const override; + uint64_t GetLengthInSamples() const override; }; diff --git a/src/oma/liboma/include/oma.h b/src/oma/liboma/include/oma.h index 89fbbaa..857b0a7 100644 --- a/src/oma/liboma/include/oma.h +++ b/src/oma/liboma/include/oma.h @@ -55,7 +55,7 @@ enum { }; typedef struct oma_info oma_info_t; -typedef long long block_count_t; +typedef int block_count_t; #ifdef __cplusplus extern "C" { diff --git a/src/wav.cpp b/src/wav.cpp index 649189b..8750377 100644 --- a/src/wav.cpp +++ b/src/wav.cpp @@ -36,7 +36,7 @@ TWav::TWav(const std::string& path) : Impl(CreatePCMIOReadImpl(path)) { } -TWav::TWav(const std::string& path, int channels, int sampleRate) +TWav::TWav(const std::string& path, uint8_t channels, uint16_t sampleRate) : Impl(CreatePCMIOWriteImpl(path, channels, sampleRate)) { } @@ -47,12 +47,12 @@ uint64_t TWav::GetTotalSamples() const { return Impl->GetTotalSamples(); } -uint32_t TWav::GetChannelNum() const { - return Impl->GetChannelsNum(); +uint8_t TWav::GetChannelNum() const { + return (uint8_t)Impl->GetChannelsNum(); } -uint32_t TWav::GetSampleRate() const { - return Impl->GetSampleRate(); +uint16_t TWav::GetSampleRate() const { + return (uint16_t)Impl->GetSampleRate(); } //bool TWav::IsFormatSupported() const { @@ -89,10 +89,10 @@ public: E_WRITE }; TWav(const std::string& filename); // reading - TWav(const std::string& filename, int channels, int sampleRate); //writing + TWav(const std::string& filename, uint8_t channels, uint16_t sampleRate); //writing ~TWav(); - uint32_t GetChannelNum() const; - uint32_t GetSampleRate() const; + uint8_t GetChannelNum() const; + uint16_t GetSampleRate() const; uint64_t GetTotalSamples() const; template<class T> |