Skip to content

Commit 648f5e5

Browse files
sboothufleisch
andauthored
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>
1 parent c1c60eb commit 648f5e5

17 files changed

Lines changed: 1261 additions & 2 deletions

bindings/c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include_directories(
2525
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/ogg/opus
2626
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/dsf
2727
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/dsdiff
28+
${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/shorten
2829
)
2930

3031
set(tag_c_HDRS tag_c.h)

bindings/c/tag_c.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "opusfile.h"
5656
#include "dsffile.h"
5757
#include "dsdifffile.h"
58+
#include "shortenfile.h"
5859
#include "tag.h"
5960
#include "id3v2framefactory.h"
6061

@@ -190,6 +191,9 @@ TagLib_File *taglib_file_new_type(const char *filename, TagLib_File_Type type)
190191
case TagLib_File_DSDIFF:
191192
file = new DSDIFF::File(filename);
192193
break;
194+
case TagLib_File_SHORTEN:
195+
file = new Shorten::File(filename);
196+
break;
193197
default:
194198
break;
195199
}

bindings/c/tag_c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ typedef enum {
130130
TagLib_File_XM,
131131
TagLib_File_Opus,
132132
TagLib_File_DSF,
133-
TagLib_File_DSDIFF
133+
TagLib_File_DSDIFF,
134+
TagLib_File_SHORTEN
134135
} TagLib_File_Type;
135136

136137
/*!

taglib/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ include_directories(
2626
${CMAKE_CURRENT_SOURCE_DIR}/xm
2727
${CMAKE_CURRENT_SOURCE_DIR}/dsf
2828
${CMAKE_CURRENT_SOURCE_DIR}/dsdiff
29+
${CMAKE_CURRENT_SOURCE_DIR}/shorten
2930
)
3031

3132
set(tag_HDRS
@@ -141,6 +142,9 @@ set(tag_HDRS
141142
dsdiff/dsdifffile.h
142143
dsdiff/dsdiffproperties.h
143144
dsdiff/dsdiffdiintag.h
145+
shorten/shortenfile.h
146+
shorten/shortenproperties.h
147+
shorten/shortentag.h
144148
)
145149

146150
set(mpeg_SRCS
@@ -308,6 +312,12 @@ set(dsdiff_SRCS
308312
dsdiff/dsdiffdiintag.cpp
309313
)
310314

315+
set(shorten_SRCS
316+
shorten/shortenfile.cpp
317+
shorten/shortenproperties.cpp
318+
shorten/shortentag.cpp
319+
)
320+
311321
set(toolkit_SRCS
312322
toolkit/tstring.cpp
313323
toolkit/tstringlist.cpp
@@ -331,7 +341,7 @@ set(tag_LIB_SRCS
331341
${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
332342
${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS} ${riff_SRCS} ${aiff_SRCS} ${wav_SRCS}
333343
${asf_SRCS} ${mp4_SRCS} ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS} ${opus_SRCS}
334-
${dsf_SRCS} ${dsdiff_SRCS}
344+
${dsf_SRCS} ${dsdiff_SRCS} ${shorten_SRCS}
335345
tag.cpp
336346
tagunion.cpp
337347
fileref.cpp

taglib/fileref.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "xmfile.h"
5858
#include "dsffile.h"
5959
#include "dsdifffile.h"
60+
#include "shortenfile.h"
6061

6162
using namespace TagLib;
6263

@@ -180,6 +181,8 @@ namespace
180181
file = new DSF::File(stream, readAudioProperties, audioPropertiesStyle);
181182
else if(ext == "DFF" || ext == "DSDIFF")
182183
file = new DSDIFF::File(stream, readAudioProperties, audioPropertiesStyle);
184+
else if(ext == "SHN")
185+
file = new Shorten::File(stream, readAudioProperties, audioPropertiesStyle);
183186

184187
// if file is not valid, leave it to content-based detection.
185188

@@ -231,6 +234,8 @@ namespace
231234
file = new DSF::File(stream, readAudioProperties, audioPropertiesStyle);
232235
else if(DSDIFF::File::isSupported(stream))
233236
file = new DSDIFF::File(stream, readAudioProperties, audioPropertiesStyle);
237+
else if(Shorten::File::isSupported(stream))
238+
file = new Shorten::File(stream, readAudioProperties, audioPropertiesStyle);
234239

235240
// isSupported() only does a quick check, so double check the file here.
236241

@@ -436,6 +441,7 @@ StringList FileRef::defaultFileExtensions()
436441
l.append("dsf");
437442
l.append("dff");
438443
l.append("dsdiff"); // alias for "dff"
444+
l.append("shn");
439445

440446
return l;
441447
}

0 commit comments

Comments
 (0)