Add Shorten (SHN) support (#1257)

* Add Shorten (SHN) support

* Add `<cmath>` include and use `std::log2`

* Use `uintptr_t` for buffer size calculations

* Work around `byteSwap` not using fixed width types

* Remove four-character codes

* Attempt to fix `static_assert`

* Revert previous commit

* Update `read_uint`* functions

* Use ByteVector for byte swaps

* Use different ByteVector ctor

* Rework variable-length input to use ByteVector

* Rename some variables

* Naming and formatting cleanup

* Add basic Shorten tests

* Rename a constant

* Rename `internalFileType` to `fileType`

* Add documentation on `fileType` meaning

* Add DO_NOT_DOCUMENT guard

* Fix shadowVariable issues reported by cppcheck

cppcheck --enable=all --inline-suppr \
  --suppress=noExplicitConstructor --suppress=unusedFunction \
  --suppress=missingIncludeSystem --project=compile_commands.json

* Formatting cleanup

* More explicit types

Reason for these changes: getRiceGolombCode(k, uInt32CodeSize) was
called with int k for uint32_t& argument.
There was also a warning from MSVC for line 299:
warning C4267: 'argument': conversion from 'size_t' to 'int'

* Additional explicit types

* Rename `SHN` namespace to `Shorten`

Also rename files to match

---------

Co-authored-by: Urs Fleisch <ufleisch@users.sourceforge.net>
This commit is contained in:
Stephen Booth
2024-12-30 07:23:11 -06:00
committed by GitHub
parent c1c60ebeea
commit 648f5e5882
17 changed files with 1261 additions and 2 deletions

View File

@ -27,6 +27,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/xm
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/dsf
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/dsdiff
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/shorten
)
SET(test_runner_SRCS
@ -74,6 +75,7 @@ SET(test_runner_SRCS
test_speex.cpp
test_dsf.cpp
test_dsdiff.cpp
test_shorten.cpp
test_sizes.cpp
test_versionnumber.cpp
)

File diff suppressed because one or more lines are too long

View File

@ -385,6 +385,7 @@ public:
CPPUNIT_ASSERT(extensions.contains("dsf"));
CPPUNIT_ASSERT(extensions.contains("dff"));
CPPUNIT_ASSERT(extensions.contains("dsdiff"));
CPPUNIT_ASSERT(extensions.contains("shn"));
}
void testFileResolver()

44
tests/test_shorten.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <string>
#include <cstdio>
#include "tbytevectorlist.h"
#include "tpropertymap.h"
#include "tag.h"
#include "shortenfile.h"
#include "plainfile.h"
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
using namespace std;
using namespace TagLib;
class TestShorten : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestShorten);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testTags);
CPPUNIT_TEST_SUITE_END();
public:
void testBasic()
{
Shorten::File f(TEST_FILE_PATH_C("2sec-silence.shn"));
CPPUNIT_ASSERT(f.audioProperties());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->lengthInSeconds());
CPPUNIT_ASSERT_EQUAL(2000, f.audioProperties()->lengthInMilliseconds());
CPPUNIT_ASSERT_EQUAL(1411, f.audioProperties()->bitrate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->shortenVersion());
CPPUNIT_ASSERT_EQUAL(5, f.audioProperties()->fileType());
CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long>(88200), f.audioProperties()->sampleFrames());
}
void testTags()
{
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestShorten);

View File

@ -92,6 +92,9 @@
#include "rifffile.h"
#include "s3mfile.h"
#include "s3mproperties.h"
#include "shortenfile.h"
#include "shortenproperties.h"
#include "shortentag.h"
#include "speexfile.h"
#include "speexproperties.h"
#include "synchronizedlyricsframe.h"
@ -245,6 +248,9 @@ public:
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::RIFF::WAV::Properties));
CPPUNIT_ASSERT_EQUAL(classSize(2, true), sizeof(TagLib::S3M::File));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::S3M::Properties));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::Shorten::File));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::Shorten::Properties));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::Shorten::Tag));
CPPUNIT_ASSERT_EQUAL(classSize(1, false), sizeof(TagLib::String));
CPPUNIT_ASSERT_EQUAL(classSize(2, false), sizeof(TagLib::StringList));
CPPUNIT_ASSERT_EQUAL(classSize(0, true), sizeof(TagLib::Tag));