]> granicus.if.org Git - taglib/commitdiff
Provisional .wav support. Tag writing will probably be disabled by default...
authorScott Wheeler <wheeler@kde.org>
Thu, 19 Jun 2008 11:15:39 +0000 (11:15 +0000)
committerScott Wheeler <wheeler@kde.org>
Thu, 19 Jun 2008 11:15:39 +0000 (11:15 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@822160 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/CMakeLists.txt
taglib/Makefile.am
taglib/fileref.cpp
taglib/riff/CMakeLists.txt
taglib/riff/Makefile.am
taglib/riff/wav/CMakeLists.txt [new file with mode: 0644]
taglib/riff/wav/Makefile.am [new file with mode: 0644]
taglib/riff/wav/wavfile.cpp [new file with mode: 0644]
taglib/riff/wav/wavfile.h [new file with mode: 0644]
taglib/riff/wav/wavproperties.cpp [new file with mode: 0644]
taglib/riff/wav/wavproperties.h [new file with mode: 0644]

index e7cb745271ae88ea1cffb98ac540cab3290ed8d7..98f11bfd42910eb169a8c2b512375eeaa930fe87 100644 (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}/..
 )
index 5a997a801c1d01728ebfd2682647dbdc80ce28c9..a75a549547e06295fc3357d67bb7dd4a5be8d86c 100644 (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)
 
index 0fc977a31c61b8ac12e0d4c62e2199c4287c95bf..ce6f649b299feb4bd64b573eae07d75da3fa863d 100644 (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")
index 56c35d9662fd124be436a2fb14cda4a7615b583d..f691ee41ec505e0d0e34edfb967ef45c26110863 100644 (file)
@@ -1,3 +1,4 @@
 ADD_SUBDIRECTORY( aiff )
+ADD_SUBDIRECTORY( wav )
 
 INSTALL( FILES  rifffile.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)
index f7bbacb9eec2676f3b697b7b04e1b171d281befc..5ef736b4d94dc0ec90a2f78f83575d880ed35590 100644 (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
diff --git a/taglib/riff/wav/CMakeLists.txt b/taglib/riff/wav/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c011579
--- /dev/null
@@ -0,0 +1 @@
+INSTALL( FILES  wavfile.h wavproperties.h DESTINATION ${INCLUDE_INSTALL_DIR}/taglib)
diff --git a/taglib/riff/wav/Makefile.am b/taglib/riff/wav/Makefile.am
new file mode 100644 (file)
index 0000000..767c29f
--- /dev/null
@@ -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
diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp
new file mode 100644 (file)
index 0000000..b2123ad
--- /dev/null
@@ -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;
+}
diff --git a/taglib/riff/wav/wavfile.h b/taglib/riff/wav/wavfile.h
new file mode 100644 (file)
index 0000000..6c36a3c
--- /dev/null
@@ -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
diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp
new file mode 100644 (file)
index 0000000..18920dd
--- /dev/null
@@ -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;
+}
diff --git a/taglib/riff/wav/wavproperties.h b/taglib/riff/wav/wavproperties.h
new file mode 100644 (file)
index 0000000..531f877
--- /dev/null
@@ -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