summaryrefslogtreecommitdiffstats
path: root/src/metadata/wav
diff options
context:
space:
mode:
Diffstat (limited to 'src/metadata/wav')
-rw-r--r--src/metadata/wav/Makefile.am15
-rw-r--r--src/metadata/wav/wavfile.cpp115
-rw-r--r--src/metadata/wav/wavfile.h92
-rw-r--r--src/metadata/wav/wavfiletyperesolver.cpp44
-rw-r--r--src/metadata/wav/wavfiletyperesolver.h36
-rw-r--r--src/metadata/wav/wavproperties.cpp108
-rw-r--r--src/metadata/wav/wavproperties.h85
7 files changed, 495 insertions, 0 deletions
diff --git a/src/metadata/wav/Makefile.am b/src/metadata/wav/Makefile.am
new file mode 100644
index 0000000..add569f
--- /dev/null
+++ b/src/metadata/wav/Makefile.am
@@ -0,0 +1,15 @@
+SUBDIRS =
+
+INCLUDES = $(all_includes) $(taglib_includes)
+METASOURCES = AUTO
+libtagwav_la_LDFLAGS = $(all_libraries)
+noinst_LTLIBRARIES = libtagwav.la
+
+libtagwav_la_SOURCES = wavproperties.cpp \
+ wavfile.cpp \
+ wavfiletyperesolver.cpp
+
+noinst_HEADERS = wavproperties.h \
+ wavfile.h \
+ wavfiletyperesolver.h
+
diff --git a/src/metadata/wav/wavfile.cpp b/src/metadata/wav/wavfile.cpp
new file mode 100644
index 0000000..303c5b2
--- /dev/null
+++ b/src/metadata/wav/wavfile.cpp
@@ -0,0 +1,115 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+
+ copyright : (C) 2005 by Andy Leadbetter
+ email : andrew.leadbetter@gmail.com
+ (original mp4 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 *
+ ***************************************************************************/
+
+#include <stdio.h>
+
+#include "wavfile.h"
+
+#include <taglib/tfile.h>
+#include <taglib/audioproperties.h>
+#include <taglib/tag.h>
+
+namespace TagLib {
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+Wav::File::File(const char *file,
+ bool readProperties,
+ Properties::ReadStyle propertiesStyle,
+ FILE *fp)
+ : TagLib::File(file)
+ , wavtag( NULL )
+ , properties( NULL )
+{
+
+ // debug ("Wav::File: create new file object.");
+ //debug ( file );
+
+ /**
+ * Create the Wav file.
+ */
+
+ if(fp)
+ wavfile = fp;
+ else
+ wavfile = fopen(file, "rb");
+
+ if( isOpen() )
+ {
+ read(readProperties, propertiesStyle );
+ }
+}
+
+Wav::File::~File()
+{
+ if(wavfile)
+ fclose(wavfile);
+ delete properties;
+}
+
+TagLib::Tag *Wav::File::tag() const
+{
+ return NULL;
+}
+
+TagLib::Tag *Wav::File::getWavTag() const
+{
+ return NULL;
+}
+
+Wav::Properties *Wav::File::audioProperties() const
+{
+ return properties;
+}
+
+bool Wav::File::save()
+{
+ return false;
+}
+
+bool Wav::File::isOpen()
+{
+ return wavfile != NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+void Wav::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
+{
+ properties = new Wav::Properties(propertiesStyle);
+
+ if (wavfile != NULL) {
+ if(readProperties)
+ {
+ // Parse bitrate etc.
+ properties->readWavProperties( wavfile );
+ }
+ }
+}
+
+}
diff --git a/src/metadata/wav/wavfile.h b/src/metadata/wav/wavfile.h
new file mode 100644
index 0000000..e47fdfb
--- /dev/null
+++ b/src/metadata/wav/wavfile.h
@@ -0,0 +1,92 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+
+ copyright : (C) 2005 by Andy Leadbetter
+ email : andrew.leadbetter@gmail.com
+ (original mp4 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 *
+ ***************************************************************************/
+
+#ifndef TAGLIB_WAVFILE_H
+#define TAGLIB_WAVFILE_H
+
+#include <taglib/tfile.h>
+#include "wavproperties.h"
+
+namespace TagLib {
+
+ namespace Wav {
+
+ class Tag;
+
+ class File : public TagLib::File
+ {
+ public:
+ /*!
+ * Contructs a 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(const char *file, bool readProperties = true,
+ Properties::ReadStyle propertiesStyle = Properties::Average,
+ FILE *fp=NULL);
+
+ /*!
+ * Destroys this instance of the File.
+ */
+ virtual ~File();
+
+
+ virtual TagLib::Tag *tag() const;
+
+ /*!
+ * Returns the Wav::Properties for this file. If no audio properties
+ * were read then this will return a null pointer.
+ */
+ virtual Wav::Properties *audioProperties() const;
+
+ /*!
+ * Save the file.
+ * This is the same as calling save(AllTags);
+ *
+ * \note As of now, saving Wav tags is not supported.
+ */
+ virtual bool save();
+
+ void read(bool readProperties, Properties::ReadStyle propertiesStyle);
+
+ TagLib::Tag *getWavTag() const;
+
+ bool isWavFile() const;
+
+ protected:
+ File(const File &);
+ File &operator=(const File &);
+ bool isOpen();
+
+
+ TagLib::Tag *wavtag;
+ Wav::Properties *properties;
+
+ FILE *wavfile;
+ };
+ }
+}
+
+#endif
diff --git a/src/metadata/wav/wavfiletyperesolver.cpp b/src/metadata/wav/wavfiletyperesolver.cpp
new file mode 100644
index 0000000..830742f
--- /dev/null
+++ b/src/metadata/wav/wavfiletyperesolver.cpp
@@ -0,0 +1,44 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+ ***************************************************************************/
+
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#include <stdio.h>
+
+#include "wavfiletyperesolver.h"
+#include "wavfile.h"
+
+#include <string.h>
+
+TagLib::File *WavFileTypeResolver::createFile(const char *fileName,
+ bool readProperties,
+ TagLib::AudioProperties::ReadStyle propertiesStyle) const
+{
+ const char *ext = strrchr(fileName, '.');
+ if(ext && !strcasecmp(ext, ".wav"))
+ {
+ FILE *fp = fopen(fileName, "rb");
+ if(!fp)
+ return 0;
+
+ return new TagLib::Wav::File(fileName, readProperties, propertiesStyle, fp);
+ }
+
+ return 0;
+}
diff --git a/src/metadata/wav/wavfiletyperesolver.h b/src/metadata/wav/wavfiletyperesolver.h
new file mode 100644
index 0000000..de818c9
--- /dev/null
+++ b/src/metadata/wav/wavfiletyperesolver.h
@@ -0,0 +1,36 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+ ***************************************************************************/
+
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#ifndef TAGLIB_WAVFILETYPERESOLVER_H
+#define TAGLIB_WAVFILETYPERESOLVER_H
+
+#include <taglib/tfile.h>
+#include <taglib/fileref.h>
+
+
+class WavFileTypeResolver : public TagLib::FileRef::FileTypeResolver
+{
+ TagLib::File *createFile(const char *fileName,
+ bool readAudioProperties,
+ TagLib::AudioProperties::ReadStyle audioPropertiesStyle) const;
+};
+
+#endif
diff --git a/src/metadata/wav/wavproperties.cpp b/src/metadata/wav/wavproperties.cpp
new file mode 100644
index 0000000..20ba1ab
--- /dev/null
+++ b/src/metadata/wav/wavproperties.cpp
@@ -0,0 +1,108 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+
+ copyright : (C) 2005 by Andy Leadbetter
+ email : andrew.leadbetter@gmail.com
+ (original mp4 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 *
+ ***************************************************************************/
+
+#include <stdio.h>
+
+#include "wavproperties.h"
+
+#include <taglib/tstring.h>
+
+#include "wavfile.h"
+
+#include <netinet/in.h> // ntohl
+
+using namespace TagLib;
+
+struct WavHeader
+{
+ uint32_t riff_id;
+ uint32_t riff_size;
+ uint32_t wave_id;
+ uint32_t format_id;
+ uint32_t format_size;
+ uint16_t format_tag;
+ uint16_t num_channels;
+ uint32_t num_samples_per_sec;
+ uint32_t num_avg_bytes_per_sec;
+ uint16_t num_block_align;
+ uint16_t bits_per_sample;
+ uint32_t data_id;
+ uint32_t num_data_bytes;
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+Wav::Properties::Properties(Properties::ReadStyle style) : AudioProperties(style)
+{
+ m_length = 0;
+ m_bitrate = 0;
+ m_sampleRate = 0;
+ m_channels = 0;
+}
+
+Wav::Properties::~Properties()
+{
+}
+
+int Wav::Properties::length() const
+{
+ return m_length;
+}
+
+int Wav::Properties::bitrate() const
+{
+ return m_bitrate;
+}
+
+int Wav::Properties::sampleRate() const
+{
+ return m_sampleRate;
+}
+
+int Wav::Properties::channels() const
+{
+ return m_channels;
+}
+
+#define swap16(x) ((((x)&0xff00)>>8) | (((x)&0x00ff)<<8))
+#define swap32(x) ((swap16((x)&0x0000ffff)<<16) | swap16(((x)&0xffff0000)>>16))
+
+void Wav::Properties::readWavProperties( FILE *fp )
+{
+ fseek(fp, 0, SEEK_SET );
+ WavHeader header;
+ if( fread(&header, sizeof(header), 1, fp) != 1 )
+ {
+ return;
+ }
+
+ m_channels = ntohs(swap16(header.num_channels));
+ m_sampleRate = ntohl(swap32(header.num_samples_per_sec));
+ m_bitrate = ntohl(swap32(header.num_avg_bytes_per_sec)) * 8 / 1000;
+ m_length = ntohl(swap32(header.num_data_bytes))/ntohl(swap32(header.num_avg_bytes_per_sec));
+}
diff --git a/src/metadata/wav/wavproperties.h b/src/metadata/wav/wavproperties.h
new file mode 100644
index 0000000..a02e734
--- /dev/null
+++ b/src/metadata/wav/wavproperties.h
@@ -0,0 +1,85 @@
+/***************************************************************************
+ copyright : (C) 2006 by Martin Aumueller
+ email : aumuell@reserv.at
+
+ copyright : (C) 2005 by Andy Leadbetter
+ email : andrew.leadbetter@gmail.com
+ (original mp4 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 *
+ ***************************************************************************/
+
+#ifndef TAGLIB_WAVPROPERTIES_H
+#define TAGLIB_WAVPROPERTIES_H
+
+#include <config.h>
+
+#include <taglib/audioproperties.h>
+#include <taglib/tstring.h>
+
+namespace TagLib {
+
+ namespace Wav {
+
+ class File;
+
+ /*!
+ * This reads the data from a Wav stream to support the
+ * AudioProperties API.
+ */
+
+ class Properties : public AudioProperties
+ {
+ public:
+ /*!
+ * Initialize this structure
+ */
+ Properties(Properties::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;
+
+ void readWavProperties(FILE *file);
+
+
+ private:
+ void readAudioTrackProperties(FILE *file);
+ friend class Wav::File;
+
+ int m_length;
+ int m_bitrate;
+ int m_sampleRate;
+ int m_channels;
+
+ Properties(const Properties &);
+ Properties &operator=(const Properties &);
+
+ void read();
+ };
+ }
+}
+
+#endif