Provisional .wav support. Tag writing will probably be disabled by default...

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@822160 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Scott Wheeler 2008-06-19 11:15:39 +00:00
parent 1d86a684b2
commit 75579dc0dd
11 changed files with 419 additions and 2 deletions

View File

@ -16,6 +16,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/trueaudio
${CMAKE_CURRENT_SOURCE_DIR}/riff
${CMAKE_CURRENT_SOURCE_DIR}/riff/aiff
${CMAKE_CURRENT_SOURCE_DIR}/riff/wav
${CMAKE_CURRENT_BINARY_DIR}/taglib
${CMAKE_CURRENT_BINARY_DIR}/..
)

View File

@ -14,6 +14,7 @@ INCLUDES = \
-I$(top_srcdir)/taglib/trueaudio \
-I$(top_srcdir)/taglib/riff \
-I$(top_srcdir)/taglib/riff/aiff \
-I$(top_srcdir)/taglib/riff/wav \
-I$(top_srcdir)/taglib/mpeg/id3v2 \
$(all_includes)

View File

@ -36,6 +36,7 @@
#include "speexfile.h"
#include "trueaudiofile.h"
#include "aifffile.h"
#include "wavfile.h"
using namespace TagLib;
@ -124,6 +125,7 @@ StringList FileRef::defaultFileExtensions()
l.append("tta");
l.append("aif");
l.append("aiff");
l.append("wav");
return l;
}
@ -202,6 +204,8 @@ File *FileRef::create(FileName fileName, bool readAudioProperties,
return new TrueAudio::File(fileName, readAudioProperties, audioPropertiesStyle);
if(s.substr(s.size() - 4, 4).upper() == ".AIF")
return new RIFF::AIFF::File(fileName, readAudioProperties, audioPropertiesStyle);
if(s.substr(s.size() - 4, 4).upper() == ".WAV")
return new RIFF::WAV::File(fileName, readAudioProperties, audioPropertiesStyle);
}
if(s.size() > 5) {
if(s.substr(s.size() - 5, 5).upper() == ".AIFF")

View File

@ -1,3 +1,4 @@
ADD_SUBDIRECTORY( aiff )
ADD_SUBDIRECTORY( wav )
INSTALL( FILES rifffile.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)

View File

@ -1,4 +1,4 @@
SUBDIRS = aiff
SUBDIRS = aiff wav
INCLUDES = \
-I$(top_srcdir)/taglib \
@ -12,4 +12,4 @@ libriff_la_SOURCES = rifffile.cpp
taglib_include_HEADERS = rifffile.h
taglib_includedir = $(includedir)/taglib
libriff_la_LIBADD = ./aiff/libaiff.la
libriff_la_LIBADD = ./aiff/libaiff.la ./wav/libwav.la

View File

@ -0,0 +1 @@
INSTALL( FILES wavfile.h wavproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)

View File

@ -0,0 +1,13 @@
INCLUDES = \
-I$(top_srcdir)/taglib \
-I$(top_srcdir)/taglib/toolkit \
-I$(top_srcdir)/taglib/riff \
-I$(top_srcdir)/taglib/mpeg/id3v2 \
$(all_includes)
noinst_LTLIBRARIES = libwav.la
libwav_la_SOURCES = wavfile.cpp wavproperties.cpp
taglib_include_HEADERS = wavfile.h wavproperties.h
taglib_includedir = $(includedir)/taglib

108
taglib/riff/wav/wavfile.cpp Normal file
View File

@ -0,0 +1,108 @@
/***************************************************************************
copyright : (C) 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* 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 <tbytevector.h>
#include <tdebug.h>
#include <id3v2tag.h>
#include "wavfile.h"
using namespace TagLib;
class RIFF::WAV::File::FilePrivate
{
public:
FilePrivate() :
properties(0),
tag(0)
{
}
~FilePrivate()
{
delete properties;
delete tag;
}
Properties *properties;
ID3v2::Tag *tag;
};
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
RIFF::WAV::File::File(FileName file, bool readProperties,
Properties::ReadStyle propertiesStyle) : RIFF::File(file, LittleEndian)
{
d = new FilePrivate;
if(isOpen())
read(readProperties, propertiesStyle);
}
RIFF::WAV::File::~File()
{
delete d;
}
ID3v2::Tag *RIFF::WAV::File::tag() const
{
return d->tag;
}
RIFF::WAV::Properties *RIFF::WAV::File::audioProperties() const
{
return d->properties;
}
bool RIFF::WAV::File::save()
{
if(readOnly()) {
debug("RIFF::WAV::File::save() -- File is read only.");
return false;
}
setChunkData("ID3 ", d->tag->render());
return true;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
{
for(uint i = 0; i < chunkCount(); i++) {
if(chunkName(i) == "ID3 ")
d->tag = new ID3v2::Tag(this, chunkOffset(i));
else if(chunkName(i) == "fmt " && readProperties)
d->properties = new Properties(chunkData(i), propertiesStyle);
}
if(!d->tag)
d->tag = new ID3v2::Tag;
}

102
taglib/riff/wav/wavfile.h Normal file
View File

@ -0,0 +1,102 @@
/***************************************************************************
copyright : (C) 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* 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_WAVFILE_H
#define TAGLIB_WAVFILE_H
#include "rifffile.h"
#include "id3v2tag.h"
#include "wavproperties.h"
namespace TagLib {
namespace RIFF {
//! An implementation of WAV metadata
/*!
* This is implementation of WAV metadata.
*
* This supports an ID3v2 tag as well as reading stream from the ID3 RIFF
* chunk as well as properties from the file.
*/
namespace WAV {
//! An implementation of TagLib::File with WAV specific methods
/*!
* This implements and provides an interface for WAV files to the
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to WAV files.
*/
class TAGLIB_EXPORT File : public TagLib::RIFF::File
{
public:
/*!
* Contructs an WAV 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);
/*!
* Destroys this instance of the File.
*/
virtual ~File();
/*!
* Returns the Tag for this file.
*/
virtual ID3v2::Tag *tag() const;
/*!
* Returns the WAV::Properties for this file. If no audio properties
* were read then this will return a null pointer.
*/
virtual Properties *audioProperties() const;
/*!
* Saves the file.
*/
virtual bool save();
private:
File(const File &);
File &operator=(const File &);
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
class FilePrivate;
FilePrivate *d;
};
}
}
}
#endif

View File

@ -0,0 +1,104 @@
/***************************************************************************
copyright : (C) 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* 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 "wavproperties.h"
#include <tstring.h>
#include <tdebug.h>
#include <cmath>
#include <math.h>
using namespace TagLib;
class RIFF::WAV::Properties::PropertiesPrivate
{
public:
PropertiesPrivate() :
format(0),
length(0),
bitrate(0),
sampleRate(0),
channels(0)
{
}
short format;
int length;
int bitrate;
int sampleRate;
int channels;
};
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
RIFF::WAV::Properties::Properties(const ByteVector &data, ReadStyle style) : AudioProperties(style)
{
d = new PropertiesPrivate;
read(data);
}
RIFF::WAV::Properties::~Properties()
{
delete d;
}
int RIFF::WAV::Properties::length() const
{
return d->length;
}
int RIFF::WAV::Properties::bitrate() const
{
return d->bitrate;
}
int RIFF::WAV::Properties::sampleRate() const
{
return d->sampleRate;
}
int RIFF::WAV::Properties::channels() const
{
return d->channels;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void RIFF::WAV::Properties::read(const ByteVector &data)
{
d->format = data.mid(0, 2).toShort(false);
d->channels = data.mid(2, 2).toShort(false);
d->sampleRate = data.mid(4, 4).toUInt(false);
d->bitrate = data.mid(8, 4).toUInt(false) * 8 / 1024;
// short bitsPerSample = data.mid(10, 2).toShort();
// d->bitrate = (sampleRate * sampleSize * d->channels) / 1024.0;
// d->length = sampleFrames / d->sampleRate;
}

View File

@ -0,0 +1,82 @@
/***************************************************************************
copyright : (C) 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* 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_WAVPROPERTIES_H
#define TAGLIB_WAVPROPERTIES_H
#include "audioproperties.h"
namespace TagLib {
class ByteVector;
namespace RIFF {
namespace WAV {
class File;
//! An implementation of audio property reading for WAV
/*!
* This reads the data from an WAV stream found in the AudioProperties
* API.
*/
class TAGLIB_EXPORT Properties : public AudioProperties
{
public:
/*!
* Create an instance of WAV::Properties with the data read from the
* ByteVector \a data.
*/
Properties(const ByteVector &data, ReadStyle style);
/*!
* Destroys this WAV::Properties instance.
*/
virtual ~Properties();
// Reimplementations.
virtual int length() const;
virtual int bitrate() const;
virtual int sampleRate() const;
virtual int channels() const;
private:
Properties(const Properties &);
Properties &operator=(const Properties &);
void read(const ByteVector &data);
class PropertiesPrivate;
PropertiesPrivate *d;
};
}
}
}
#endif