Audio file detection by content

This commit is contained in:
Jonas Kvinge
2018-05-10 15:29:28 +02:00
parent 7b2d1d95d3
commit 5392cc4109
232 changed files with 55355 additions and 133 deletions

248
3rdparty/taglib/s3m/s3mfile.cpp vendored Normal file
View File

@@ -0,0 +1,248 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "s3mfile.h"
#include "tstringlist.h"
#include "tdebug.h"
#include "modfileprivate.h"
#include "tpropertymap.h"
#include <iostream>
using namespace TagLib;
using namespace S3M;
class S3M::File::FilePrivate
{
public:
FilePrivate(AudioProperties::ReadStyle propertiesStyle)
: properties(propertiesStyle)
{
}
Mod::Tag tag;
S3M::Properties properties;
};
S3M::File::File(FileName file, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(file),
d(new FilePrivate(propertiesStyle))
{
if(isOpen())
read(readProperties);
}
S3M::File::File(IOStream *stream, bool readProperties,
AudioProperties::ReadStyle propertiesStyle) :
Mod::FileBase(stream),
d(new FilePrivate(propertiesStyle))
{
if(isOpen())
read(readProperties);
}
S3M::File::~File()
{
delete d;
}
Mod::Tag *S3M::File::tag() const
{
return &d->tag;
}
PropertyMap S3M::File::properties() const
{
return d->tag.properties();
}
PropertyMap S3M::File::setProperties(const PropertyMap &properties)
{
return d->tag.setProperties(properties);
}
S3M::Properties *S3M::File::audioProperties() const
{
return &d->properties;
}
bool S3M::File::save()
{
if(readOnly()) {
debug("S3M::File::save() - Cannot save to a read only file.");
return false;
}
// note: if title starts with "Extended Module: "
// the file would look like an .xm file
seek(0);
writeString(d->tag.title(), 27);
// string terminating NUL is not optional:
writeByte(0);
seek(32);
unsigned short length = 0;
unsigned short sampleCount = 0;
if(!readU16L(length) || !readU16L(sampleCount))
return false;
seek(28, Current);
int channels = 0;
for(int i = 0; i < 32; ++ i) {
unsigned char setting = 0;
if(!readByte(setting))
return false;
// or if(setting >= 128)?
// or channels = i + 1;?
// need a better spec!
if(setting != 0xff) ++ channels;
}
seek(channels, Current);
StringList lines = d->tag.comment().split("\n");
// write comment as sample names:
for(unsigned short i = 0; i < sampleCount; ++ i) {
seek(96L + length + ((long)i << 1));
unsigned short instrumentOffset = 0;
if(!readU16L(instrumentOffset))
return false;
seek(((long)instrumentOffset << 4) + 48);
if(i < lines.size())
writeString(lines[i], 27);
else
writeString(String(), 27);
// string terminating NUL is not optional:
writeByte(0);
}
return true;
}
void S3M::File::read(bool)
{
if(!isOpen())
return;
READ_STRING(d->tag.setTitle, 28);
READ_BYTE_AS(mark);
READ_BYTE_AS(type);
READ_ASSERT(mark == 0x1A && type == 0x10);
seek(32);
READ_U16L_AS(length);
READ_U16L_AS(sampleCount);
d->properties.setSampleCount(sampleCount);
READ_U16L(d->properties.setPatternCount);
READ_U16L(d->properties.setFlags);
READ_U16L(d->properties.setTrackerVersion);
READ_U16L(d->properties.setFileFormatVersion);
READ_ASSERT(readBlock(4) == "SCRM");
READ_BYTE(d->properties.setGlobalVolume);
READ_BYTE(d->properties.setBpmSpeed);
READ_BYTE(d->properties.setTempo);
READ_BYTE_AS(masterVolume);
d->properties.setMasterVolume(masterVolume & 0x7f);
d->properties.setStereo((masterVolume & 0x80) != 0);
// I've seen players who call the next two bytes
// "ultra click" and "use panning values" (if == 0xFC).
// I don't see them in any spec, though.
// Hm, but there is "UltraClick-removal" and some other
// variables in ScreamTracker IIIs GUI.
seek(12, Current);
int channels = 0;
for(int i = 0; i < 32; ++ i) {
READ_BYTE_AS(setting);
// or if(setting >= 128)?
// or channels = i + 1;?
// need a better spec!
if(setting != 0xff) ++ channels;
}
d->properties.setChannels(channels);
seek(96);
unsigned short realLength = 0;
for(unsigned short i = 0; i < length; ++ i) {
READ_BYTE_AS(order);
if(order == 255) break;
if(order != 254) ++ realLength;
}
d->properties.setLengthInPatterns(realLength);
seek(channels, Current);
// Note: The S3M spec mentions samples and instruments, but in
// the header there are only pointers to instruments.
// However, there I never found instruments (SCRI) but
// instead samples (SCRS).
StringList comment;
for(unsigned short i = 0; i < sampleCount; ++ i) {
seek(96L + length + ((long)i << 1));
READ_U16L_AS(sampleHeaderOffset);
seek((long)sampleHeaderOffset << 4);
READ_BYTE_AS(sampleType);
READ_STRING_AS(dosFileName, 13);
READ_U16L_AS(sampleDataOffset);
READ_U32L_AS(sampleLength);
READ_U32L_AS(repeatStart);
READ_U32L_AS(repeatStop);
READ_BYTE_AS(sampleVolume);
seek(1, Current);
READ_BYTE_AS(packing);
READ_BYTE_AS(sampleFlags);
READ_U32L_AS(baseFrequency);
seek(12, Current);
READ_STRING_AS(sampleName, 28);
// The next 4 bytes should be "SCRS", but I've found
// files that are otherwise ok with 4 nils instead.
// READ_ASSERT(readBlock(4) == "SCRS");
comment.append(sampleName);
}
d->tag.setComment(comment.toString("\n"));
d->tag.setTrackerName("ScreamTracker III");
}

112
3rdparty/taglib/s3m/s3mfile.h vendored Normal file
View File

@@ -0,0 +1,112 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifndef TAGLIB_S3MFILE_H
#define TAGLIB_S3MFILE_H
#include "tfile.h"
#include "audioproperties.h"
#include "taglib_export.h"
#include "modfilebase.h"
#include "modtag.h"
#include "s3mproperties.h"
namespace TagLib {
namespace S3M {
class TAGLIB_EXPORT File : public Mod::FileBase {
public:
/*!
* Constructs a ScreamTracker III from \a file.
*
* \note In the current implementation, both \a readProperties and
* \a propertiesStyle are ignored. The audio properties are always
* read.
*/
File(FileName file, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
* Constructs a ScreamTracker III file from \a stream.
*
* \note In the current implementation, both \a readProperties and
* \a propertiesStyle are ignored. The audio properties are always
* read.
*
* \note TagLib will *not* take ownership of the stream, the caller is
* responsible for deleting it after the File object.
*/
File(IOStream *stream, bool readProperties = true,
AudioProperties::ReadStyle propertiesStyle =
AudioProperties::Average);
/*!
* Destroys this instance of the File.
*/
virtual ~File();
Mod::Tag *tag() const;
/*!
* Implements the unified property interface -- export function.
* Forwards to Mod::Tag::properties().
*/
PropertyMap properties() const;
/*!
* Implements the unified property interface -- import function.
* Forwards to Mod::Tag::setProperties().
*/
PropertyMap setProperties(const PropertyMap &);
/*!
* Returns the S3M::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
S3M::Properties *audioProperties() const;
/*!
* Save the file.
* This is the same as calling save(AllTags);
*
* \note Saving ScreamTracker III tags is not supported.
*/
bool save();
private:
File(const File &);
File &operator=(const File &);
void read(bool readProperties);
class FilePrivate;
FilePrivate *d;
};
}
}
#endif

219
3rdparty/taglib/s3m/s3mproperties.cpp vendored Normal file
View File

@@ -0,0 +1,219 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "s3mproperties.h"
using namespace TagLib;
using namespace S3M;
class S3M::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
lengthInPatterns(0),
channels(0),
stereo(false),
sampleCount(0),
patternCount(0),
flags(0),
trackerVersion(0),
fileFormatVersion(0),
globalVolume(0),
masterVolume(0),
tempo(0),
bpmSpeed(0)
{
}
unsigned short lengthInPatterns;
int channels;
bool stereo;
unsigned short sampleCount;
unsigned short patternCount;
unsigned short flags;
unsigned short trackerVersion;
unsigned short fileFormatVersion;
unsigned char globalVolume;
unsigned char masterVolume;
unsigned char tempo;
unsigned char bpmSpeed;
};
S3M::Properties::Properties(AudioProperties::ReadStyle propertiesStyle) :
AudioProperties(propertiesStyle),
d(new PropertiesPrivate())
{
}
S3M::Properties::~Properties()
{
delete d;
}
int S3M::Properties::length() const
{
return 0;
}
int S3M::Properties::lengthInSeconds() const
{
return 0;
}
int S3M::Properties::lengthInMilliseconds() const
{
return 0;
}
int S3M::Properties::bitrate() const
{
return 0;
}
int S3M::Properties::sampleRate() const
{
return 0;
}
int S3M::Properties::channels() const
{
return d->channels;
}
unsigned short S3M::Properties::lengthInPatterns() const
{
return d->lengthInPatterns;
}
bool S3M::Properties::stereo() const
{
return d->stereo;
}
unsigned short S3M::Properties::sampleCount() const
{
return d->sampleCount;
}
unsigned short S3M::Properties::patternCount() const
{
return d->patternCount;
}
unsigned short S3M::Properties::flags() const
{
return d->flags;
}
unsigned short S3M::Properties::trackerVersion() const
{
return d->trackerVersion;
}
unsigned short S3M::Properties::fileFormatVersion() const
{
return d->fileFormatVersion;
}
unsigned char S3M::Properties::globalVolume() const
{
return d->globalVolume;
}
unsigned char S3M::Properties::masterVolume() const
{
return d->masterVolume;
}
unsigned char S3M::Properties::tempo() const
{
return d->tempo;
}
unsigned char S3M::Properties::bpmSpeed() const
{
return d->bpmSpeed;
}
void S3M::Properties::setLengthInPatterns(unsigned short lengthInPatterns)
{
d->lengthInPatterns = lengthInPatterns;
}
void S3M::Properties::setChannels(int channels)
{
d->channels = channels;
}
void S3M::Properties::setStereo(bool stereo)
{
d->stereo = stereo;
}
void S3M::Properties::setSampleCount(unsigned short sampleCount)
{
d->sampleCount = sampleCount;
}
void S3M::Properties::setPatternCount(unsigned short patternCount)
{
d->patternCount = patternCount;
}
void S3M::Properties::setFlags(unsigned short flags)
{
d->flags = flags;
}
void S3M::Properties::setTrackerVersion(unsigned short trackerVersion)
{
d->trackerVersion = trackerVersion;
}
void S3M::Properties::setFileFormatVersion(unsigned short fileFormatVersion)
{
d->fileFormatVersion = fileFormatVersion;
}
void S3M::Properties::setGlobalVolume(unsigned char globalVolume)
{
d->globalVolume = globalVolume;
}
void S3M::Properties::setMasterVolume(unsigned char masterVolume)
{
d->masterVolume = masterVolume;
}
void S3M::Properties::setTempo(unsigned char tempo)
{
d->tempo = tempo;
}
void S3M::Properties::setBpmSpeed(unsigned char bpmSpeed)
{
d->bpmSpeed = bpmSpeed;
}

94
3rdparty/taglib/s3m/s3mproperties.h vendored Normal file
View File

@@ -0,0 +1,94 @@
/***************************************************************************
copyright : (C) 2011 by Mathias Panzenböck
email : grosser.meister.morti@gmx.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifndef TAGLIB_S3MPROPERTIES_H
#define TAGLIB_S3MPROPERTIES_H
#include "taglib.h"
#include "audioproperties.h"
namespace TagLib {
namespace S3M {
class TAGLIB_EXPORT Properties : public AudioProperties {
friend class File;
public:
/*! Flag bits. */
enum {
ST2Vibrato = 1,
ST2Tempo = 2,
AmigaSlides = 4,
Vol0MixOptimizations = 8,
AmigaLimits = 16,
EnableFilter = 32,
CustomData = 128
};
Properties(AudioProperties::ReadStyle propertiesStyle);
virtual ~Properties();
int length() const;
int lengthInSeconds() const;
int lengthInMilliseconds() const;
int bitrate() const;
int sampleRate() const;
int channels() const;
unsigned short lengthInPatterns() const;
bool stereo() const;
unsigned short sampleCount() const;
unsigned short patternCount() const;
unsigned short flags() const;
unsigned short trackerVersion() const;
unsigned short fileFormatVersion() const;
unsigned char globalVolume() const;
unsigned char masterVolume() const;
unsigned char tempo() const;
unsigned char bpmSpeed() const;
void setChannels(int channels);
void setLengthInPatterns (unsigned short lengthInPatterns);
void setStereo (bool stereo);
void setSampleCount (unsigned short sampleCount);
void setPatternCount (unsigned short patternCount);
void setFlags (unsigned short flags);
void setTrackerVersion (unsigned short trackerVersion);
void setFileFormatVersion(unsigned short fileFormatVersion);
void setGlobalVolume (unsigned char globalVolume);
void setMasterVolume (unsigned char masterVolume);
void setTempo (unsigned char tempo);
void setBpmSpeed (unsigned char bpmSpeed);
private:
Properties(const Properties&);
Properties &operator=(const Properties&);
class PropertiesPrivate;
PropertiesPrivate *d;
};
}
}
#endif