[prev in list] [next in list] [prev in thread] [next in thread] 

List:       taglib-devel
Subject:    Speex support
From:       Lukáš_Lalinský <lalinsky () gmail ! com>
Date:       2007-11-07 0:17:39
Message-ID: 1194394660.7754.18.camel () laptop
[Download RAW message or body]

Ok, this one is really trivial, but sending the patch here first anyway.
The code is as old as the WavPack one and is without any known bugs,
too.

Lukas


["taglib-speex.diff" (taglib-speex.diff)]

=== added directory 'taglib/speex'
=== added file 'taglib/speex/CMakeLists.txt'
--- taglib/speex/CMakeLists.txt	1970-01-01 00:00:00 +0000
+++ taglib/speex/CMakeLists.txt	2007-10-17 20:08:31 +0000
@@ -0,0 +1,1 @@
+INSTALL( FILES  speexfile.h speexproperties.h DESTINATION \
${INCLUDE_INSTALL_DIR}/taglib)

=== added file 'taglib/speex/Makefile.am'
--- taglib/speex/Makefile.am	1970-01-01 00:00:00 +0000
+++ taglib/speex/Makefile.am	2007-11-06 23:56:14 +0000
@@ -0,0 +1,11 @@
+INCLUDES = \
+	-I$(top_srcdir)/taglib \
+	-I$(top_srcdir)/taglib/ogg \
+	$(all_includes)
+
+noinst_LTLIBRARIES = libspeex.la
+
+libspeex_la_SOURCES = speexfile.cpp speexproperties.cpp
+
+taglib_include_HEADERS = speexfile.h speexproperties.h
+taglib_includedir = $(includedir)/taglib

=== added file 'taglib/speex/speexfile.cpp'
--- taglib/speex/speexfile.cpp	1970-01-01 00:00:00 +0000
+++ taglib/speex/speexfile.cpp	2007-11-07 00:00:56 +0000
@@ -0,0 +1,111 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2002 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., 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 <bitset>
+
+#include <tstring.h>
+#include <tdebug.h>
+
+#include "speexfile.h"
+
+using namespace TagLib;
+
+class Speex::File::FilePrivate
+{
+public:
+  FilePrivate() :
+    comment(0),
+    properties(0) {}
+
+  ~FilePrivate()
+  {
+    delete comment;
+    delete properties;
+  }
+
+  Ogg::XiphComment *comment;
+  Properties *properties;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+Speex::File::File(const char *file, bool readProperties,
+                   Properties::ReadStyle propertiesStyle) : Ogg::File(file)
+{
+  d = new FilePrivate;
+  read(readProperties, propertiesStyle);
+}
+
+Speex::File::~File()
+{
+  delete d;
+}
+
+Ogg::XiphComment *Speex::File::tag() const
+{
+  return d->comment;
+}
+
+Speex::Properties *Speex::File::audioProperties() const
+{
+  return d->properties;
+}
+
+bool Speex::File::save()
+{
+  if(!d->comment)
+    d->comment = new Ogg::XiphComment;
+
+  setPacket(1, d->comment->render());
+
+  return Ogg::File::save();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+void Speex::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
+{
+  ByteVector speexHeaderData = packet(0);
+  
+  if(!speexHeaderData.startsWith("Speex   ")) {
+    debug("Speex::File::read() -- invalid Speex identification header");
+    return;
+  }
+  
+  ByteVector commentHeaderData = packet(1);
+
+  d->comment = new Ogg::XiphComment(commentHeaderData);
+
+  if(readProperties)
+    d->properties = new Properties(this, propertiesStyle);
+}

=== added file 'taglib/speex/speexfile.h'
--- taglib/speex/speexfile.h	1970-01-01 00:00:00 +0000
+++ taglib/speex/speexfile.h	2007-11-07 00:00:48 +0000
@@ -0,0 +1,97 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2002 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., 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_SPEEXFILE_H
+#define TAGLIB_SPEEXFILE_H
+
+#include <oggfile.h>
+#include <xiphcomment.h>
+
+#include "speexproperties.h"
+
+namespace TagLib {
+
+  //! A namespace containing classes for Speex metadata
+
+  namespace Speex {
+
+    //! An implementation of Ogg::File with Speex specific methods
+
+    /*!
+     * This is the central class in the Ogg Speex 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 Speex specifically.
+     */
+
+    class TAGLIB_EXPORT File : public Ogg::File
+    {
+    public:
+      /*!
+       * Contructs a Speex 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(const char *file, 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 Speex::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

=== added file 'taglib/speex/speexproperties.cpp'
--- taglib/speex/speexproperties.cpp	1970-01-01 00:00:00 +0000
+++ taglib/speex/speexproperties.cpp	2007-11-07 00:01:21 +0000
@@ -0,0 +1,169 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2002 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., 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 <tstring.h>
+#include <tdebug.h>
+
+#include <oggpageheader.h>
+
+#include "speexproperties.h"
+#include "speexfile.h"
+
+using namespace TagLib;
+
+class Speex::Properties::PropertiesPrivate
+{
+public:
+  PropertiesPrivate(File *f, ReadStyle s) :
+    file(f),
+    style(s),
+    length(0),
+    bitrate(0),
+    sampleRate(0),
+    channels(0),
+    speexVersion(0),
+    vbr(false),
+    mode(0) {}
+
+  File *file;
+  ReadStyle style;
+  int length;
+  int bitrate;
+  int sampleRate;
+  int channels;
+  int speexVersion;
+  bool vbr;
+  int mode;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+Speex::Properties::Properties(File *file, ReadStyle style) : AudioProperties(style)
+{
+  d = new PropertiesPrivate(file, style);
+  read();
+}
+
+Speex::Properties::~Properties()
+{
+  delete d;
+}
+
+int Speex::Properties::length() const
+{
+  return d->length;
+}
+
+int Speex::Properties::bitrate() const
+{
+  return int(float(d->bitrate) / float(1000) + 0.5);
+}
+
+int Speex::Properties::sampleRate() const
+{
+  return d->sampleRate;
+}
+
+int Speex::Properties::channels() const
+{
+  return d->channels;
+}
+
+int Speex::Properties::speexVersion() const
+{
+  return d->speexVersion;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+void Speex::Properties::read()
+{
+  // Get the identification header from the Ogg implementation.
+
+  ByteVector data = d->file->packet(0);
+
+  int pos = 28;
+
+  // speex_version_id;       /**< Version for Speex (for checking compatibility) */ 
+  d->speexVersion = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+  
+  // header_size;            /**< Total size of the header ( sizeof(SpeexHeader) ) \
*/  +  pos += 4;
+  
+  // rate;                   /**< Sampling rate used */ 
+  d->sampleRate = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+
+  // mode;                   /**< Mode used (0 for narrowband, 1 for wideband) */ 
+  d->mode = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+
+  // mode_bitstream_version; /**< Version ID of the bit-stream */ 
+  pos += 4;
+
+  // nb_channels;            /**< Number of channels encoded */ 
+  d->channels = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+
+  // bitrate;                /**< Bit-rate used */ 
+  d->bitrate = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+  
+  // frame_size;             /**< Size of frames */
+  //unsigned int frameSize = data.mid(pos, 4).toUInt(false);
+  pos += 4;
+  
+  // vbr;                    /**< 1 for a VBR encoding, 0 otherwise */  
+  d->vbr = data.mid(pos, 4).toUInt(false) == 1;
+  pos += 4;
+
+  // frames_per_packet;      /**< Number of frames stored per Ogg packet */ 
+  //unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
+
+  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->sampleRate > 0)
+      d->length = (int) ((end - start) / (long long) d->sampleRate);
+    else
+      debug("Speex::Properties::read() -- Either the PCM values for the start or "
+            "end of this file was incorrect or the sample rate is zero.");
+  }
+  else
+    debug("Speex::Properties::read() -- Could not find valid first and last Ogg \
pages."); +}

=== added file 'taglib/speex/speexproperties.h'
--- taglib/speex/speexproperties.h	1970-01-01 00:00:00 +0000
+++ taglib/speex/speexproperties.h	2007-11-07 00:01:28 +0000
@@ -0,0 +1,87 @@
+/***************************************************************************
+    copyright            : (C) 2006 by Lukáš Lalinský
+    email                : lalinsky@gmail.com
+    
+    copyright            : (C) 2002 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., 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_SPEEXPROPERTIES_H
+#define TAGLIB_SPEEXPROPERTIES_H
+
+#include <audioproperties.h>
+
+namespace TagLib {
+
+  namespace Speex {
+
+    class File;
+
+    //! An implementation of audio property reading for Ogg Speex
+
+    /*!
+     * This reads the data from an Ogg Speex stream found in the AudioProperties
+     * API.
+     */
+
+    class TAGLIB_EXPORT Properties : public AudioProperties
+    {
+    public:
+      /*!
+       * Create an instance of Vorbis::Properties with the data read from the
+       * Vorbis::File \a file.
+       */
+      Properties(File *file, ReadStyle style = Average);
+
+      /*!
+       * Destroys this VorbisProperties instance.
+       */
+      virtual ~Properties();
+
+      // Reimplementations.
+
+      virtual int length() const;
+      virtual int bitrate() const;
+      virtual int sampleRate() const;
+      virtual int channels() const;
+
+      /*!
+       * Returns the Vorbis version, currently "0" (as specified by the spec).
+       */
+      int speexVersion() const;
+
+    private:
+      Properties(const Properties &);
+      Properties &operator=(const Properties &);
+
+      void read();
+
+      class PropertiesPrivate;
+      PropertiesPrivate *d;
+    };
+  }
+
+}
+
+#endif

=== modified file 'bindings/c/CMakeLists.txt'
--- bindings/c/CMakeLists.txt	2007-11-06 18:50:09 +0000
+++ bindings/c/CMakeLists.txt	2007-11-06 23:58:23 +0000
@@ -8,6 +8,7 @@
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpc
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/mpeg/id3v2
 		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/wavpack
+		     ${CMAKE_CURRENT_SOURCE_DIR}/../../taglib/speex
 )
 
 

=== modified file 'bindings/c/Makefile.am'
--- bindings/c/Makefile.am	2007-11-06 18:50:09 +0000
+++ bindings/c/Makefile.am	2007-11-06 23:59:25 +0000
@@ -9,6 +9,7 @@
 	-I$(top_srcdir)/taglib/mpc \
 	-I$(top_srcdir)/taglib/mpeg/id3v2 \
 	-I$(top_srcdir)/taglib/wavpack \
+	-I$(top_srcdir)/taglib/speex \
 	$(all_includes)
 
 lib_LTLIBRARIES = libtag_c.la

=== modified file 'bindings/c/tag_c.cpp'
--- bindings/c/tag_c.cpp	2007-11-06 18:50:09 +0000
+++ bindings/c/tag_c.cpp	2007-11-06 23:58:14 +0000
@@ -30,6 +30,7 @@
 #include <oggflacfile.h>
 #include <mpcfile.h>
 #include <wavpackfile.h>
+#include <speexfile.h>
 #include <tag.h>
 #include <string.h>
 #include <id3v2framefactory.h>
@@ -74,6 +75,8 @@
     return reinterpret_cast<TagLib_File *>(new Ogg::FLAC::File(filename));
   case TagLib_File_WavPack:
     return reinterpret_cast<TagLib_File *>(new WavPack::File(filename));
+  case TagLib_File_Speex:
+    return reinterpret_cast<TagLib_File *>(new Speex::File(filename));
   }
 
   return 0;

=== modified file 'bindings/c/tag_c.h'
--- bindings/c/tag_c.h	2007-11-06 18:50:09 +0000
+++ bindings/c/tag_c.h	2007-11-06 23:57:39 +0000
@@ -87,7 +87,8 @@
   TagLib_File_FLAC,
   TagLib_File_MPC,
   TagLib_File_OggFlac,
-  TagLib_File_WavPack
+  TagLib_File_WavPack,
+  TagLib_File_Speex
 } TagLib_File_Type;
 
 /*!

=== modified file 'taglib/CMakeLists.txt'
--- taglib/CMakeLists.txt	2007-11-06 18:50:09 +0000
+++ taglib/CMakeLists.txt	2007-11-06 23:55:19 +0000
@@ -12,6 +12,7 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/mpeg/id3v1
     ${CMAKE_CURRENT_SOURCE_DIR}/ape
     ${CMAKE_CURRENT_SOURCE_DIR}/wavpack
+    ${CMAKE_CURRENT_SOURCE_DIR}/speex
     ${CMAKE_CURRENT_BINARY_DIR}/taglib
     ${CMAKE_CURRENT_BINARY_DIR}/..
 )
@@ -26,6 +27,7 @@
 ADD_SUBDIRECTORY( ape )
 ADD_SUBDIRECTORY( mpc )
 ADD_SUBDIRECTORY( wavpack )
+ADD_SUBDIRECTORY( speex )
 
 
 
@@ -103,6 +105,11 @@
 wavpack/wavpackproperties.cpp
 )
 
+SET(speex_SRCS
+speex/speexfile.cpp
+speex/speexproperties.cpp
+)
+
 SET(toolkit_SRCS
 toolkit/tstring.cpp
 toolkit/tstringlist.cpp
@@ -115,7 +122,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}
+		 ${wavpack_SRCS} ${speex_SRCS}
 		 tag.cpp
 		 fileref.cpp
 		 audioproperties.cpp

=== modified file 'taglib/Makefile.am'
--- taglib/Makefile.am	2007-11-06 18:50:09 +0000
+++ taglib/Makefile.am	2007-11-06 23:54:19 +0000
@@ -10,6 +10,7 @@
 	-I$(top_srcdir)/taglib/mpc \
 	-I$(top_srcdir)/taglib/ogg/vorbis \
 	-I$(top_srcdir)/taglib/wavpack \
+	-I$(top_srcdir)/taglib/speex \
 	$(all_includes)
 
 lib_LTLIBRARIES = libtag.la
@@ -19,4 +20,5 @@
 taglib_includedir = $(includedir)/taglib
 
 libtag_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 5:0:4
-libtag_la_LIBADD = ./mpeg/libmpeg.la ./ogg/libogg.la ./flac/libflac.la \
./mpc/libmpc.la ./ape/libape.la ./toolkit/libtoolkit.la ./wavpack/libwavpack.la \
+libtag_la_LIBADD = ./mpeg/libmpeg.la ./ogg/libogg.la ./flac/libflac.la \
./mpc/libmpc.la \ +	./ape/libape.la ./toolkit/libtoolkit.la ./wavpack/libwavpack.la \
./speex/libspeex.la

=== modified file 'taglib/fileref.cpp'
--- taglib/fileref.cpp	2007-11-06 18:50:09 +0000
+++ taglib/fileref.cpp	2007-11-06 23:57:21 +0000
@@ -33,6 +33,7 @@
 #include "oggflacfile.h"
 #include "mpcfile.h"
 #include "wavpackfile.h"
+#include "speexfile.h"
 
 using namespace TagLib;
 
@@ -117,6 +118,7 @@
   l.append("mp3");
   l.append("mpc");
   l.append("wv");
+  l.append("spx");
 
   return l;
 }
@@ -181,7 +183,9 @@
       return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
     if(s.substr(s.size() - 4, 4).upper() == ".MPC")
       return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
-    if(s.substr(s.size() - 4, 4).upper() == ".WV")
+    if(s.substr(s.size() - 3, 3).upper() == ".WV")
+      return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
+    if(s.substr(s.size() - 4, 4).upper() == ".SPX")
       return new WavPack::File(fileName, readAudioProperties, audioPropertiesStyle);
   }
 



_______________________________________________
taglib-devel mailing list
taglib-devel@kde.org
https://mail.kde.org/mailman/listinfo/taglib-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic