traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src/core AbstractAudioReader.cpp core....


From: Ben Levitt
Subject: [Traverso-commit] traverso/src/core AbstractAudioReader.cpp core....
Date: Thu, 19 Jul 2007 05:25:59 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Ben Levitt <benjie>     07/07/19 05:25:59

Modified files:
        src/core       : AbstractAudioReader.cpp core.pro 
Added files:
        src/core       : WPAudioReader.cpp WPAudioReader.h 

Log message:
        Another present for Remon:
        Add wavpack reading support (currently floats work well, int16s need 
gain adjustment)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/AbstractAudioReader.cpp?cvsroot=traverso&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/core.pro?cvsroot=traverso&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/WPAudioReader.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/WPAudioReader.h?cvsroot=traverso&rev=1.1

Patches:
Index: AbstractAudioReader.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/AbstractAudioReader.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- AbstractAudioReader.cpp     19 Jul 2007 04:05:57 -0000      1.10
+++ AbstractAudioReader.cpp     19 Jul 2007 05:25:58 -0000      1.11
@@ -23,6 +23,7 @@
 #include "SFAudioReader.h"
 #include "FlacAudioReader.h"
 #include "MadAudioReader.h"
+#include "WPAudioReader.h"
 #include "VorbisAudioReader.h"
 #include "ResampleAudioReader.h"
 
@@ -93,6 +94,9 @@
        else if (VorbisAudioReader::can_decode(filename)) {
                newReader = new VorbisAudioReader(filename);
        }
+       else if (WPAudioReader::can_decode(filename)) {
+               newReader = new WPAudioReader(filename);
+       }
        else if (SFAudioReader::can_decode(filename)) {
                newReader = new SFAudioReader(filename);
        }

Index: core.pro
===================================================================
RCS file: /sources/traverso/traverso/src/core/core.pro,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- core.pro    19 Jul 2007 04:05:58 -0000      1.35
+++ core.pro    19 Jul 2007 05:25:59 -0000      1.36
@@ -55,6 +55,7 @@
        FlacAudioReader.cpp \
        ResampleAudioReader.cpp \
        VorbisAudioReader.cpp \
+       WPAudioReader.cpp \
        MadAudioReader.cpp
 HEADERS = precompile.h \
        AudioClip.h \
@@ -104,6 +105,7 @@
        FlacAudioReader.h \
        ResampleAudioReader.h \
        VorbisAudioReader.h \
+       WPAudioReader.h \
        MadAudioReader.h
 macx{
     QMAKE_LIBDIR += /usr/local/qt/lib

Index: WPAudioReader.cpp
===================================================================
RCS file: WPAudioReader.cpp
diff -N WPAudioReader.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ WPAudioReader.cpp   19 Jul 2007 05:25:58 -0000      1.1
@@ -0,0 +1,182 @@
+/*
+Copyright (C) 2007 Ben Levitt 
+
+This file is part of Traverso
+
+Traverso is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
+
+*/
+
+#include "WPAudioReader.h"
+#include <QFile>
+#include <QString>
+#include "Utils.h"
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+
+WPAudioReader::WPAudioReader(QString filename)
+ : AbstractAudioReader(filename)
+{
+       char error[80];
+       
+       m_wp = WavpackOpenFileInput(m_fileName.toUtf8().data(), error, 
OPEN_2CH_MAX, 1);
+       
+       if (m_wp == 0) {
+               PERROR("Couldn't open soundfile (%s) %s", QS_C(m_fileName), 
error);
+       }
+       
+       m_isFloat = ((WavpackGetMode(m_wp) & MODE_FLOAT) != 0);
+       
+       m_tmpBuffer = 0;
+       m_tmpBufferSize = 0;
+}
+
+
+WPAudioReader::~WPAudioReader()
+{
+       if (m_tmpBuffer) {
+               delete m_tmpBuffer;
+       }
+       
+       if (m_wp) {
+               WavpackCloseFile(m_wp);
+       }
+}
+
+
+bool WPAudioReader::can_decode(QString filename)
+{
+       char error[80];
+       
+       WavpackContext *wp = WavpackOpenFileInput(filename.toUtf8().data(), 
error, OPEN_2CH_MAX, 1);
+       
+       if (wp == 0) {
+               return false;
+       }
+       
+       WavpackCloseFile(wp);
+       
+       return true;
+}
+
+
+int WPAudioReader::get_num_channels()
+{
+       if (m_wp) {
+               return WavpackGetReducedChannels(m_wp);
+       }
+       return 0;
+}
+
+
+nframes_t WPAudioReader::get_length()
+{
+       if (m_wp) {
+               return WavpackGetNumSamples(m_wp);
+       }
+       return 0;
+}
+
+
+int WPAudioReader::get_rate()
+{
+       if (m_wp) {
+               return WavpackGetSampleRate(m_wp);
+       }
+       return 0;
+}
+
+
+bool WPAudioReader::seek(nframes_t start)
+{
+       Q_ASSERT(m_wp);
+       
+       
+       if (start >= get_length()) {
+               return false;
+       }
+       
+       if (!WavpackSeekSample(m_wp, start)) {
+               PERROR("could not seek to frame %d within %s", start, 
QS_C(m_fileName));
+               return false;
+       }
+       
+       AbstractAudioReader::seek(start);
+       
+       return true;
+}
+
+
+nframes_t WPAudioReader::read(audio_sample_t** buffer, nframes_t frameCount)
+{
+       Q_ASSERT(m_wp);
+       
+       // Make sure the temp buffer is big enough for this read
+       if (m_tmpBufferSize < frameCount) {
+               if (m_tmpBuffer) {
+                       delete m_tmpBuffer;
+               }
+               m_tmpBuffer = new int32_t[frameCount * get_num_channels()];
+       }
+       nframes_t framesRead = WavpackUnpackSamples(m_wp, m_tmpBuffer, 
frameCount);
+       
+       // De-interlace
+       if (m_isFloat) {
+               switch (get_num_channels()) {
+                       case 1:
+                               memcpy(buffer[0], m_tmpBuffer, framesRead * 
sizeof(audio_sample_t));
+                               break;  
+                       case 2:
+                               for (int f = 0; f < framesRead; f++) {
+                                       buffer[0][f] = ((float*)m_tmpBuffer)[f 
* 2];
+                                       buffer[1][f] = ((float*)m_tmpBuffer)[f 
* 2 + 1];
+                               }
+                               break;  
+                       default:
+                               for (int f = 0; f < framesRead; f++) {
+                                       for (int c = 0; c < get_num_channels(); 
c++) {
+                                               buffer[c][f] = 
((float*)m_tmpBuffer)[f * get_num_channels() + c];
+                                       }
+                               }
+               }
+       }
+       else {
+               switch (get_num_channels()) {
+                       case 1:
+                               for (int f = 0; f < framesRead; f++) {
+                                       buffer[0][f] = m_tmpBuffer[f];
+                               }
+                               break;  
+                       case 2:
+                               for (int f = 0; f < framesRead; f++) {
+                                       buffer[0][f] = m_tmpBuffer[f * 2];
+                                       buffer[1][f] = m_tmpBuffer[f * 2 + 1];
+                               }
+                               break;  
+                       default:
+                               for (int f = 0; f < framesRead; f++) {
+                                       for (int c = 0; c < get_num_channels(); 
c++) {
+                                               buffer[c][f] = m_tmpBuffer[f * 
get_num_channels() + c];
+                                       }
+                               }
+               }
+       }
+       
+       return framesRead;
+}
+

Index: WPAudioReader.h
===================================================================
RCS file: WPAudioReader.h
diff -N WPAudioReader.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ WPAudioReader.h     19 Jul 2007 05:25:59 -0000      1.1
@@ -0,0 +1,50 @@
+/*
+Copyright (C) 2007 Ben Levitt 
+
+This file is part of Traverso
+
+Traverso is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
+
+*/
+
+#ifndef WPAUDIOREADER_H
+#define WPAUDIOREADER_H
+
+#include <AbstractAudioReader.h>
+#include "wavpack/wavpack.h"
+
+
+class WPAudioReader : public AbstractAudioReader
+{
+public:
+       WPAudioReader(QString filename);
+       ~WPAudioReader();
+
+       int get_num_channels();
+       nframes_t get_length();
+       int get_rate();
+       bool seek(nframes_t start);
+       nframes_t read(audio_sample_t** buffer, nframes_t frameCount);
+
+       static bool can_decode(QString filename);
+
+protected:
+       WavpackContext* m_wp;
+       bool            m_isFloat;
+       int32_t         *m_tmpBuffer;
+       int             m_tmpBufferSize;
+};
+
+#endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]