mirror of
https://github.com/taglib/taglib.git
synced 2025-07-25 16:34:26 -04:00
Merge branch 'master' into taglib2
Conflicts: taglib/mpeg/id3v1/id3v1tag.cpp
This commit is contained in:
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@ -0,0 +1,6 @@
|
||||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
install: sudo apt-get install libcppunit-dev zlib1g-dev
|
||||
script: cmake -DBUILD_TESTS=ON . && make && make check
|
||||
|
15
NEWS
15
NEWS
@ -1,5 +1,18 @@
|
||||
TagLib 1.9 (In Development)
|
||||
==========================
|
||||
|
||||
* Added support for the Ogg Opus file format.
|
||||
* Added support for INFO tags in WAV files.
|
||||
* Changed FileStream to use Windows file API.
|
||||
* Included taglib-config.cmd script for Windows.
|
||||
* New ID3v1::Tag methods for working directly with genre numbers.
|
||||
* New MPEG::File methods for checking which tags are saved in the file.
|
||||
* Better parsing of corrupted FLAC files.
|
||||
* Fixed saving of PropertyMap comments without description into ID3v2 tags.
|
||||
* Fixed crash when parsing certain XM files.
|
||||
|
||||
TagLib 1.8 (Sep 6, 2012)
|
||||
==============================
|
||||
========================
|
||||
|
||||
1.8:
|
||||
|
||||
|
@ -10,6 +10,7 @@ include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mp4
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ogg/vorbis
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ogg/speex
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ogg/opus
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v2/frames
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
|
||||
@ -84,6 +85,8 @@ set(tag_HDRS
|
||||
ogg/flac/oggflacfile.h
|
||||
ogg/speex/speexfile.h
|
||||
ogg/speex/speexproperties.h
|
||||
ogg/opus/opusfile.h
|
||||
ogg/opus/opusproperties.h
|
||||
flac/flacfile.h
|
||||
flac/flacpicture.h
|
||||
flac/flacproperties.h
|
||||
@ -221,6 +224,11 @@ set(speex_SRCS
|
||||
ogg/speex/speexproperties.cpp
|
||||
)
|
||||
|
||||
set(opus_SRCS
|
||||
ogg/opus/opusfile.cpp
|
||||
ogg/opus/opusproperties.cpp
|
||||
)
|
||||
|
||||
set(trueaudio_SRCS
|
||||
trueaudio/trueaudiofile.cpp
|
||||
trueaudio/trueaudioproperties.cpp
|
||||
@ -290,7 +298,7 @@ set(tag_LIB_SRCS
|
||||
${mpeg_SRCS} ${id3v1_SRCS} ${id3v2_SRCS} ${frames_SRCS} ${ogg_SRCS}
|
||||
${vorbis_SRCS} ${oggflacs_SRCS} ${mpc_SRCS} ${ape_SRCS} ${toolkit_SRCS} ${flacs_SRCS}
|
||||
${wavpack_SRCS} ${speex_SRCS} ${trueaudio_SRCS} ${riff_SRCS} ${aiff_SRCS} ${wav_SRCS}
|
||||
${asf_SRCS} ${mp4_SRCS} ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS}
|
||||
${asf_SRCS} ${mp4_SRCS} ${mod_SRCS} ${s3m_SRCS} ${it_SRCS} ${xm_SRCS} ${opus_SRCS}
|
||||
tag.cpp
|
||||
tagunion.cpp
|
||||
fileref.cpp
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "mp4file.h"
|
||||
#include "wavpackfile.h"
|
||||
#include "speexfile.h"
|
||||
#include "opusfile.h"
|
||||
#include "trueaudiofile.h"
|
||||
#include "aifffile.h"
|
||||
#include "wavfile.h"
|
||||
@ -252,6 +253,8 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
|
||||
return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "SPX")
|
||||
return new Ogg::Speex::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "OPUS")
|
||||
return new Ogg::Opus::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "TTA")
|
||||
return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
|
||||
if(ext == "M4A" || ext == "M4R" || ext == "M4B" || ext == "M4P" || ext == "MP4" || ext == "3G2")
|
||||
|
@ -70,7 +70,8 @@ public:
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
for(uint i = 0; i < blocks.size(); i++) {
|
||||
uint size = blocks.size();
|
||||
for(uint i = 0; i < size; i++) {
|
||||
delete blocks[i];
|
||||
}
|
||||
delete properties;
|
||||
@ -425,7 +426,7 @@ void FLAC::File::scan()
|
||||
length = header.mid(1, 3).toUInt();
|
||||
|
||||
ByteVector data = readBlock(length);
|
||||
if(data.size() != length) {
|
||||
if(data.size() != length || length == 0) {
|
||||
debug("FLAC::File::scan() -- FLAC stream corrupted");
|
||||
setValid(false);
|
||||
return;
|
||||
|
@ -570,7 +570,7 @@ MP4::Tag::updateOffsets(long delta, long offset)
|
||||
atom->offset += delta;
|
||||
}
|
||||
d->file->seek(atom->offset + 9);
|
||||
ByteVector data = d->file->readBlock(atom->offset - 9);
|
||||
ByteVector data = d->file->readBlock(atom->length - 9);
|
||||
unsigned int flags = (ByteVector(1, '\0') + data.mid(0, 3)).toUInt();
|
||||
if(flags & 1) {
|
||||
long long o = data.mid(7, 8).toLongLong();
|
||||
|
@ -176,16 +176,26 @@ void ID3v1::Tag::setGenre(const String &s)
|
||||
d->genre = ID3v1::genreIndex(s);
|
||||
}
|
||||
|
||||
void ID3v1::Tag::setYear(uint i)
|
||||
void ID3v1::Tag::setYear(TagLib::uint i)
|
||||
{
|
||||
d->year = i > 0 ? String::number(i) : String::null;
|
||||
}
|
||||
|
||||
void ID3v1::Tag::setTrack(uint i)
|
||||
void ID3v1::Tag::setTrack(TagLib::uint i)
|
||||
{
|
||||
d->track = i < 256 ? i : 0;
|
||||
}
|
||||
|
||||
TagLib::uint ID3v1::Tag::genreNumber() const
|
||||
{
|
||||
return d->genre;
|
||||
}
|
||||
|
||||
void ID3v1::Tag::setGenreNumber(TagLib::uint i)
|
||||
{
|
||||
d->genre = i < 256 ? i : 255;
|
||||
}
|
||||
|
||||
void ID3v1::Tag::setStringHandler(const TagLib::StringHandler *handler)
|
||||
{
|
||||
if(handler)
|
||||
|
@ -137,16 +137,31 @@ namespace TagLib {
|
||||
virtual String album() const;
|
||||
virtual String comment() const;
|
||||
virtual String genre() const;
|
||||
virtual uint year() const;
|
||||
virtual uint track() const;
|
||||
virtual TagLib::uint year() const;
|
||||
virtual TagLib::uint track() const;
|
||||
|
||||
virtual void setTitle(const String &s);
|
||||
virtual void setArtist(const String &s);
|
||||
virtual void setAlbum(const String &s);
|
||||
virtual void setComment(const String &s);
|
||||
virtual void setGenre(const String &s);
|
||||
virtual void setYear(uint i);
|
||||
virtual void setTrack(uint i);
|
||||
virtual void setYear(TagLib::uint i);
|
||||
virtual void setTrack(TagLib::uint i);
|
||||
|
||||
/*!
|
||||
* Returns the genre in number.
|
||||
*
|
||||
* /note Normally 255 indicates that this tag contains no genre.
|
||||
*/
|
||||
TagLib::uint genreNumber() const;
|
||||
|
||||
/*!
|
||||
* Sets the genre in number to \a i.
|
||||
*
|
||||
* /note Valid value is from 0 up to 255. Normally 255 indicates that
|
||||
* this tag contains no genre.
|
||||
*/
|
||||
void setGenreNumber(TagLib::uint i);
|
||||
|
||||
/*!
|
||||
* Sets the string handler that decides how the ID3v1 data will be
|
||||
|
@ -120,7 +120,7 @@ Frame *Frame::createTextualFrame(const String &key, const StringList &values) //
|
||||
TextIdentificationFrame *frame = new TextIdentificationFrame(frameID, String::UTF8);
|
||||
frame->setText(values);
|
||||
return frame;
|
||||
} else if(values.size() == 1){ // URL frame (not WXXX); support only one value
|
||||
} else if((frameID[0] == 'W') && (values.size() == 1)){ // URL frame (not WXXX); support only one value
|
||||
UrlLinkFrame* frame = new UrlLinkFrame(frameID);
|
||||
frame->setUrl(values.front());
|
||||
return frame;
|
||||
@ -144,7 +144,9 @@ Frame *Frame::createTextualFrame(const String &key, const StringList &values) //
|
||||
// -COMMENT: depending on the number of values, use COMM or TXXX (with description=COMMENT)
|
||||
if((key == "COMMENT" || key.startsWith(commentPrefix)) && values.size() == 1){
|
||||
CommentsFrame *frame = new CommentsFrame(String::UTF8);
|
||||
frame->setDescription(key == "COMMENT" ? key : key.substr(commentPrefix.size()));
|
||||
if (key != "COMMENT"){
|
||||
frame->setDescription(key.substr(commentPrefix.size()));
|
||||
}
|
||||
frame->setText(values.front());
|
||||
return frame;
|
||||
}
|
||||
|
126
taglib/ogg/opus/opusfile.cpp
Normal file
126
taglib/ogg/opus/opusfile.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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 <bitset>
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include "opusfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Opus::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
comment(0),
|
||||
properties(0) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete comment;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *comment;
|
||||
Properties *properties;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Opus::File::File(FileName file, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) : Ogg::File(file)
|
||||
{
|
||||
d = new FilePrivate;
|
||||
read(readProperties, propertiesStyle);
|
||||
}
|
||||
|
||||
Opus::File::File(IOStream *stream, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) : Ogg::File(stream)
|
||||
{
|
||||
d = new FilePrivate;
|
||||
read(readProperties, propertiesStyle);
|
||||
}
|
||||
|
||||
Opus::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *Opus::File::tag() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
Opus::Properties *Opus::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
bool Opus::File::save()
|
||||
{
|
||||
if(!d->comment)
|
||||
d->comment = new Ogg::XiphComment;
|
||||
|
||||
setPacket(1, ByteVector("OpusTags", 8) + d->comment->render(false));
|
||||
|
||||
return Ogg::File::save();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Opus::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
|
||||
{
|
||||
ByteVector opusHeaderData = packet(0);
|
||||
|
||||
if(!opusHeaderData.startsWith("OpusHead")) {
|
||||
setValid(false);
|
||||
debug("Opus::File::read() -- invalid Opus identification header");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteVector commentHeaderData = packet(1);
|
||||
|
||||
if(!commentHeaderData.startsWith("OpusTags")) {
|
||||
setValid(false);
|
||||
debug("Opus::File::read() -- invalid Opus tags header");
|
||||
return;
|
||||
}
|
||||
|
||||
d->comment = new Ogg::XiphComment(commentHeaderData.mid(8));
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(this, propertiesStyle);
|
||||
}
|
110
taglib/ogg/opus/opusfile.h
Normal file
110
taglib/ogg/opus/opusfile.h
Normal file
@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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_OPUSFILE_H
|
||||
#define TAGLIB_OPUSFILE_H
|
||||
|
||||
#include "oggfile.h"
|
||||
#include "xiphcomment.h"
|
||||
|
||||
#include "opusproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
//! A namespace containing classes for Opus metadata
|
||||
|
||||
namespace Opus {
|
||||
|
||||
//! An implementation of Ogg::File with Opus specific methods
|
||||
|
||||
/*!
|
||||
* This is the central class in the Ogg Opus metadata processing collection
|
||||
* of classes. It's built upon Ogg::File which handles processing of the Ogg
|
||||
* logical bitstream and breaking it down into pages which are handled by
|
||||
* the codec implementations, in this case Opus specifically.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public Ogg::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Contructs a Opus file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read using \a propertiesStyle. If
|
||||
* false, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(FileName file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Contructs a Opus file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read using \a propertiesStyle. If
|
||||
* false, \a propertiesStyle is ignored.
|
||||
*
|
||||
* \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,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the XiphComment for this file. XiphComment implements the tag
|
||||
* interface, so this serves as the reimplementation of
|
||||
* TagLib::File::tag().
|
||||
*/
|
||||
virtual Ogg::XiphComment *tag() const;
|
||||
|
||||
/*!
|
||||
* Returns the Opus::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
virtual bool save();
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
161
taglib/ogg/opus/opusproperties.cpp
Normal file
161
taglib/ogg/opus/opusproperties.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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 <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "opusproperties.h"
|
||||
#include "opusfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Opus::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate(File *f, ReadStyle s) :
|
||||
file(f),
|
||||
style(s),
|
||||
length(0),
|
||||
inputSampleRate(0),
|
||||
channels(0),
|
||||
opusVersion(0) {}
|
||||
|
||||
File *file;
|
||||
ReadStyle style;
|
||||
int length;
|
||||
int inputSampleRate;
|
||||
int channels;
|
||||
int opusVersion;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Opus::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
|
||||
{
|
||||
d = new PropertiesPrivate(file, style);
|
||||
read();
|
||||
}
|
||||
|
||||
Opus::Properties::~Properties()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int Opus::Properties::length() const
|
||||
{
|
||||
return d->length;
|
||||
}
|
||||
|
||||
int Opus::Properties::bitrate() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Opus::Properties::sampleRate() const
|
||||
{
|
||||
// Opus can decode any stream at a sample rate of 8, 12, 16, 24, or 48 kHz,
|
||||
// so there is no single sample rate. Let's assume it's the highest
|
||||
// possible.
|
||||
return 48000;
|
||||
}
|
||||
|
||||
int Opus::Properties::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
int Opus::Properties::inputSampleRate() const
|
||||
{
|
||||
return d->inputSampleRate;
|
||||
}
|
||||
|
||||
int Opus::Properties::opusVersion() const
|
||||
{
|
||||
return d->opusVersion;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Opus::Properties::read()
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
// http://tools.ietf.org/html/draft-terriberry-oggopus-01#section-5.1
|
||||
|
||||
ByteVector data = d->file->packet(0);
|
||||
|
||||
// *Magic Signature*
|
||||
int pos = 8;
|
||||
|
||||
// *Version* (8 bits, unsigned)
|
||||
d->opusVersion = uchar(data.at(pos));
|
||||
pos += 1;
|
||||
|
||||
// *Output Channel Count* 'C' (8 bits, unsigned)
|
||||
d->channels = uchar(data.at(pos));
|
||||
pos += 1;
|
||||
|
||||
// *Pre-skip* (16 bits, unsigned, little endian)
|
||||
ushort preSkip = data.mid(pos, 2).toUShort(false);
|
||||
pos += 2;
|
||||
|
||||
// *Input Sample Rate* (32 bits, unsigned, little endian)
|
||||
d->inputSampleRate = data.mid(pos, 4).toUInt(false);
|
||||
pos += 4;
|
||||
|
||||
// *Output Gain* (16 bits, signed, little endian)
|
||||
pos += 2;
|
||||
|
||||
// *Channel Mapping Family* (8 bits, unsigned)
|
||||
pos += 1;
|
||||
|
||||
const Ogg::PageHeader *first = d->file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = d->file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
long long start = first->absoluteGranularPosition();
|
||||
long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0)
|
||||
d->length = (int) ((end - start - preSkip) / 48000);
|
||||
else {
|
||||
debug("Opus::Properties::read() -- The PCM values for the start or "
|
||||
"end of this file was incorrect.");
|
||||
}
|
||||
}
|
||||
else
|
||||
debug("Opus::Properties::read() -- Could not find valid first and last Ogg pages.");
|
||||
}
|
96
taglib/ogg/opus/opusproperties.h
Normal file
96
taglib/ogg/opus/opusproperties.h
Normal file
@ -0,0 +1,96 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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_OPUSPROPERTIES_H
|
||||
#define TAGLIB_OPUSPROPERTIES_H
|
||||
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
namespace Opus {
|
||||
|
||||
class File;
|
||||
|
||||
//! An implementation of audio property reading for Ogg Opus
|
||||
|
||||
/*!
|
||||
* This reads the data from an Ogg Opus stream found in the AudioProperties
|
||||
* API.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Opus::Properties with the data read from the
|
||||
* Opus::File \a file.
|
||||
*/
|
||||
Properties(File *file, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this Opus::Properties instance.
|
||||
*/
|
||||
virtual ~Properties();
|
||||
|
||||
// Reimplementations.
|
||||
|
||||
virtual int length() const;
|
||||
virtual int bitrate() const;
|
||||
virtual int sampleRate() const;
|
||||
virtual int channels() const;
|
||||
|
||||
/*!
|
||||
* The Opus codec supports decoding at multiple sample rates, there is no
|
||||
* single sample rate of the encoded stream. This returns the sample rate
|
||||
* of the original audio stream.
|
||||
*/
|
||||
int inputSampleRate() const;
|
||||
|
||||
/*!
|
||||
* Returns the Opus version, currently "0" (as specified by the spec).
|
||||
*/
|
||||
int opusVersion() const;
|
||||
|
||||
private:
|
||||
Properties(const Properties &);
|
||||
Properties &operator=(const Properties &);
|
||||
|
||||
void read();
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -145,7 +145,7 @@ namespace TagLib {
|
||||
* - A clean, high level, C++ API to handling audio meta data.
|
||||
* - Format specific APIs for advanced API users.
|
||||
* - ID3v1, ID3v2, APE, FLAC, Xiph, iTunes-style MP4 and WMA tag formats.
|
||||
* - MP3, MPC, FLAC, MP4, ASF, AIFF, WAV, TrueAudio, WavPack, Ogg FLAC, Ogg Vorbis and Speex file formats.
|
||||
* - MP3, MPC, FLAC, MP4, ASF, AIFF, WAV, TrueAudio, WavPack, Ogg FLAC, Ogg Vorbis, Speex and Opus file formats.
|
||||
* - Basic audio file properties such as length, sample rate, etc.
|
||||
* - Long term binary and source compatibility.
|
||||
* - Extensible design, notably the ability to add other formats or extend current formats as a library user.
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "mp4file.h"
|
||||
#include "wavpackfile.h"
|
||||
#include "speexfile.h"
|
||||
#include "opusfile.h"
|
||||
#include "trueaudiofile.h"
|
||||
#include "aifffile.h"
|
||||
#include "wavfile.h"
|
||||
@ -135,6 +136,8 @@ PropertyMap File::properties() const
|
||||
return dynamic_cast<const Ogg::FLAC::File* >(this)->properties();
|
||||
if(dynamic_cast<const Ogg::Speex::File* >(this))
|
||||
return dynamic_cast<const Ogg::Speex::File* >(this)->properties();
|
||||
if(dynamic_cast<const Ogg::Opus::File* >(this))
|
||||
return dynamic_cast<const Ogg::Opus::File* >(this)->properties();
|
||||
if(dynamic_cast<const Ogg::Vorbis::File* >(this))
|
||||
return dynamic_cast<const Ogg::Vorbis::File* >(this)->properties();
|
||||
if(dynamic_cast<const RIFF::AIFF::File* >(this))
|
||||
@ -174,6 +177,8 @@ void File::removeUnsupportedProperties(const StringList &properties)
|
||||
dynamic_cast<Ogg::FLAC::File* >(this)->removeUnsupportedProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Speex::File* >(this))
|
||||
dynamic_cast<Ogg::Speex::File* >(this)->removeUnsupportedProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Opus::File* >(this))
|
||||
dynamic_cast<Ogg::Opus::File* >(this)->removeUnsupportedProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Vorbis::File* >(this))
|
||||
dynamic_cast<Ogg::Vorbis::File* >(this)->removeUnsupportedProperties(properties);
|
||||
else if(dynamic_cast<RIFF::AIFF::File* >(this))
|
||||
@ -210,6 +215,8 @@ PropertyMap File::setProperties(const PropertyMap &properties)
|
||||
return dynamic_cast<Ogg::FLAC::File* >(this)->setProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Speex::File* >(this))
|
||||
return dynamic_cast<Ogg::Speex::File* >(this)->setProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Opus::File* >(this))
|
||||
return dynamic_cast<Ogg::Opus::File* >(this)->setProperties(properties);
|
||||
else if(dynamic_cast<Ogg::Vorbis::File* >(this))
|
||||
return dynamic_cast<Ogg::Vorbis::File* >(this)->setProperties(properties);
|
||||
else if(dynamic_cast<RIFF::AIFF::File* >(this))
|
||||
|
@ -443,7 +443,7 @@ bool XM::File::save()
|
||||
return false;
|
||||
|
||||
uint len = std::min(22UL, instrumentHeaderSize - 4U);
|
||||
if(i > lines.size())
|
||||
if(i >= lines.size())
|
||||
writeString(String::null, len);
|
||||
else
|
||||
writeString(lines[i], len);
|
||||
|
@ -16,6 +16,8 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg/vorbis
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg/speex
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/ogg/opus
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/flac
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/wavpack
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/mod
|
||||
@ -60,8 +62,11 @@ SET(test_runner_SRCS
|
||||
test_it.cpp
|
||||
test_xm.cpp
|
||||
test_mpc.cpp
|
||||
test_opus.cpp
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR})
|
||||
|
||||
ADD_EXECUTABLE(test_runner ${test_runner_SRCS})
|
||||
TARGET_LINK_LIBRARIES(test_runner tag ${CPPUNIT_LIBRARIES})
|
||||
|
||||
|
BIN
tests/data/correctness_gain_silent_output.opus
Normal file
BIN
tests/data/correctness_gain_silent_output.opus
Normal file
Binary file not shown.
61
tests/test_opus.cpp
Normal file
61
tests/test_opus.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <opusfile.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestOpus : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestOpus);
|
||||
CPPUNIT_TEST(testProperties);
|
||||
CPPUNIT_TEST(testReadComments);
|
||||
CPPUNIT_TEST(testWriteComments);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testProperties()
|
||||
{
|
||||
Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
|
||||
CPPUNIT_ASSERT_EQUAL(7, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(48000, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(48000, ((Ogg::Opus::Properties *)f.audioProperties())->inputSampleRate());
|
||||
}
|
||||
|
||||
void testReadComments()
|
||||
{
|
||||
Ogg::Opus::File f(TEST_FILE_PATH_C("correctness_gain_silent_output.opus"));
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f.tag()->fieldListMap()["ENCODER"]);
|
||||
CPPUNIT_ASSERT(f.tag()->fieldListMap().contains("TESTDESCRIPTION"));
|
||||
CPPUNIT_ASSERT(!f.tag()->fieldListMap().contains("ARTIST"));
|
||||
CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f.tag()->vendorID());
|
||||
}
|
||||
|
||||
void testWriteComments()
|
||||
{
|
||||
ScopedFileCopy copy("correctness_gain_silent_output", ".opus");
|
||||
string filename = copy.fileName();
|
||||
|
||||
Ogg::Opus::File *f = new Ogg::Opus::File(filename.c_str());
|
||||
f->tag()->setArtist("Your Tester");
|
||||
f->save();
|
||||
delete f;
|
||||
|
||||
f = new Ogg::Opus::File(filename.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Xiph.Org Opus testvectormaker"), f->tag()->fieldListMap()["ENCODER"]);
|
||||
CPPUNIT_ASSERT(f->tag()->fieldListMap().contains("TESTDESCRIPTION"));
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Your Tester"), f->tag()->fieldListMap()["ARTIST"]);
|
||||
CPPUNIT_ASSERT_EQUAL(String("libopus 0.9.11-66-g64c2dd7"), f->tag()->vendorID());
|
||||
delete f;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestOpus);
|
Reference in New Issue
Block a user