summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMax Linke <kain88@mixxx.org>2014-04-29 23:40:58 +0200
committerMax Linke <kain88@mixxx.org>2014-04-29 23:40:58 +0200
commit4e2afca878f3c1a0c7d4cb26e325b042be7461f3 (patch)
treec9d53b0a95d3b2c0f44125fda66ad3284edd4961 /plugins
parentad097a849bc670b226a965e067b4aba53750cf54 (diff)
update m4a plugin to math refactor
Diffstat (limited to 'plugins')
-rw-r--r--plugins/soundsourcewv/soundsourcewv.cpp222
-rw-r--r--plugins/soundsourcewv/soundsourcewv.h5
2 files changed, 114 insertions, 113 deletions
diff --git a/plugins/soundsourcewv/soundsourcewv.cpp b/plugins/soundsourcewv/soundsourcewv.cpp
index 5f473c8064..c247ac3dbb 100644
--- a/plugins/soundsourcewv/soundsourcewv.cpp
+++ b/plugins/soundsourcewv/soundsourcewv.cpp
@@ -13,15 +13,15 @@ namespace Mixxx {
SoundSourceWV::SoundSourceWV(QString qFilename) : SoundSource(qFilename)
{
- // Initialize variables to invalid values in case loading fails.
- filewvc=NULL;
+ // Initialize variables to invalid values in case loading fails.
+ filewvc=NULL;
}
SoundSourceWV::~SoundSourceWV(){
if (filewvc) {
- WavpackCloseFile(filewvc);
- filewvc=NULL;
+ WavpackCloseFile(filewvc);
+ filewvc=NULL;
}
}
@@ -33,94 +33,94 @@ QList<QString> SoundSourceWV::supportedFileExtensions()
}
-int SoundSourceWV::open()
+Result SoundSourceWV::open()
{
- QByteArray qBAFilename = m_qFilename.toLocal8Bit();
- char msg[80]; //hold posible error message
-
- filewvc = WavpackOpenFileInput(qBAFilename.constData(), msg,OPEN_2CH_MAX | OPEN_WVC,0);
- if (!filewvc) {
- qDebug() << "SSWV::open: failed to open file : "<<msg;
- return ERR;
- }
- if (WavpackGetMode(filewvc) & MODE_FLOAT) {
- qDebug() << "SSWV::open: cannot load 32bit float files";
- WavpackCloseFile(filewvc);
- filewvc=NULL;
- return ERR;
- }
- // wavpack_open succeeded -> populate variables
- filelength = WavpackGetNumSamples(filewvc);
- m_iSampleRate=WavpackGetSampleRate(filewvc);
- m_iChannels=WavpackGetReducedChannels(filewvc);
- Bps=WavpackGetBytesPerSample(filewvc);
- qDebug () << "SSWV::open: opened filewvc with filelength: "<<filelength<<" SampleRate: " << m_iSampleRate
- << " channels: " << m_iChannels << " bytes per samp: "<<Bps;
- if (Bps>2) {
- qDebug() << "SSWV::open: warning: input file has > 2 bytes per sample, will be truncated to 16bits";
- }
- return OK;
+ QByteArray qBAFilename = m_qFilename.toLocal8Bit();
+ char msg[80]; //hold posible error message
+
+ filewvc = WavpackOpenFileInput(qBAFilename.constData(), msg,OPEN_2CH_MAX | OPEN_WVC,0);
+ if (!filewvc) {
+ qDebug() << "SSWV::open: failed to open file : "<<msg;
+ return ERR;
+ }
+ if (WavpackGetMode(filewvc) & MODE_FLOAT) {
+ qDebug() << "SSWV::open: cannot load 32bit float files";
+ WavpackCloseFile(filewvc);
+ filewvc=NULL;
+ return ERR;
+ }
+ // wavpack_open succeeded -> populate variables
+ filelength = WavpackGetNumSamples(filewvc);
+ m_iSampleRate=WavpackGetSampleRate(filewvc);
+ m_iChannels=WavpackGetReducedChannels(filewvc);
+ Bps=WavpackGetBytesPerSample(filewvc);
+ qDebug () << "SSWV::open: opened filewvc with filelength: "<<filelength<<" SampleRate: " << m_iSampleRate
+ << " channels: " << m_iChannels << " bytes per samp: "<<Bps;
+ if (Bps>2) {
+ qDebug() << "SSWV::open: warning: input file has > 2 bytes per sample, will be truncated to 16bits";
+ }
+ return OK;
}
long SoundSourceWV::seek(long filepos){
- if (WavpackSeekSample(filewvc,filepos>>1) != true) {
- qDebug() << "SSWV::seek : could not seek to sample #" << (filepos>>1);
- return 0;
- }
- return filepos;
+ if (WavpackSeekSample(filewvc,filepos>>1) != true) {
+ qDebug() << "SSWV::seek : could not seek to sample #" << (filepos>>1);
+ return 0;
+ }
+ return filepos;
}
unsigned SoundSourceWV::read(volatile unsigned long size, const SAMPLE* destination){
- //SAMPLE is "short int" => 16bits. [size] is timesamps*2 (because L+R)
- SAMPLE * dest = (SAMPLE*) destination;
- unsigned long sampsread=0;
- unsigned long timesamps, tsdone;
-
- //tempbuffer is fixed size : WV_BUF_LENGTH of uint32
- while (sampsread != size) {
- timesamps=(size-sampsread)>>1; //timesamps still remaining
- if (timesamps > (WV_BUF_LENGTH/m_iChannels)) { //if requested size requires more than one buffer filling
- timesamps=(WV_BUF_LENGTH/m_iChannels); //tempbuffer must hold (timesamps * channels) samples
- qDebug() << "SSWV::read : performance warning, size requested > buffer size !";
- }
-
- tsdone=WavpackUnpackSamples(filewvc, tempbuffer, timesamps); //fill temp buffer with timesamps*4bytes*channels
- //data is right justified, format_samples() fixes that.
-
- SoundSourceWV::format_samples(Bps, (char *) (dest + (sampsread>>1)*m_iChannels), tempbuffer, tsdone*m_iChannels);
- //this will unpack the 4byte/sample
- //output of wUnpackSamples(), sign-extending or truncating to output 16bit / sample.
- //specifying dest+sampsread should resume the conversion where it was left if size requested
- //required multiple reads (size req. > fixed buffer size)
-
- sampsread = sampsread + (tsdone<<1);
- if (tsdone!=timesamps) {
- qDebug () << "SSWV::read : WavpackUnpackSamples read "<<sampsread<<" asamps out of "<<size<<" requested";
- break; //exit the while loop : subsequent reads are sure to read less than required.
- }
-
- }
-
- if (m_iChannels==1) { //if MONO : expand array to double it's size; see ssov.cpp
- for(int i=(sampsread/2-1); i>=0; i--) { //algo courtesy of rryan !
- dest[i*2] = dest[i]; //go through array backwards, expanding and copying L -> R
- dest[(i*2)+1] = dest[i];
- }
- }
-
- return sampsread;
+ //SAMPLE is "short int" => 16bits. [size] is timesamps*2 (because L+R)
+ SAMPLE * dest = (SAMPLE*) destination;
+ unsigned long sampsread=0;
+ unsigned long timesamps, tsdone;
+
+ //tempbuffer is fixed size : WV_BUF_LENGTH of uint32
+ while (sampsread != size) {
+ timesamps=(size-sampsread)>>1; //timesamps still remaining
+ if (timesamps > (WV_BUF_LENGTH/m_iChannels)) { //if requested size requires more than one buffer filling
+ timesamps=(WV_BUF_LENGTH/m_iChannels); //tempbuffer must hold (timesamps * channels) samples
+ qDebug() << "SSWV::read : performance warning, size requested > buffer size !";
+ }
+
+ tsdone=WavpackUnpackSamples(filewvc, tempbuffer, timesamps); //fill temp buffer with timesamps*4bytes*channels
+ //data is right justified, format_samples() fixes that.
+
+ SoundSourceWV::format_samples(Bps, (char *) (dest + (sampsread>>1)*m_iChannels), tempbuffer, tsdone*m_iChannels);
+ //this will unpack the 4byte/sample
+ //output of wUnpackSamples(), sign-extending or truncating to output 16bit / sample.
+ //specifying dest+sampsread should resume the conversion where it was left if size requested
+ //required multiple reads (size req. > fixed buffer size)
+
+ sampsread = sampsread + (tsdone<<1);
+ if (tsdone!=timesamps) {
+ qDebug () << "SSWV::read : WavpackUnpackSamples read "<<sampsread<<" asamps out of "<<size<<" requested";
+ break; //exit the while loop : subsequent reads are sure to read less than required.
+ }
+
+ }
+
+ if (m_iChannels==1) { //if MONO : expand array to double it's size; see ssov.cpp
+ for(int i=(sampsread/2-1); i>=0; i--) { //algo courtesy of rryan !
+ dest[i*2] = dest[i]; //go through array backwards, expanding and copying L -> R
+ dest[(i*2)+1] = dest[i];
+ }
+ }
+
+ return sampsread;
}
inline long unsigned SoundSourceWV::length(){
- //filelength is # of timesamps.
- return filelength<<1;
+ //filelength is # of timesamps.
+ return filelength<<1;
}
-int SoundSourceWV::parseHeader() {
+Result SoundSourceWV::parseHeader() {
setType("wv");
QByteArray qBAFilename = m_qFilename.toLocal8Bit();
@@ -141,41 +141,41 @@ int SoundSourceWV::parseHeader() {
void SoundSourceWV::format_samples(int Bps, char *dst, int32_t *src, uint32_t count)
{
- //this handles converting the fixed 32bit per sample produced by UnpackSamples
- //to 16 bps, by truncating (24/32) or sign-extending (8)
- //could eventually be asm-optimized..
- int32_t temp;
-
- switch (Bps) {
- case 1:
- while (count--) {
- *dst++ = (char) 0; //left shift the 8 bit sample
- *dst++ = (char) *src++ ;//+ 128; //only works with u8int ?
- }
- break;
- case 2:
- while (count--) {
- *dst++ = (char) (temp = *src++); //low byte
- *dst++ = (char) (temp >> 8); //high byte
- }
- break;
- case 3: //modified to truncate to 16bits
- while (count--) {
- *dst++ = (char) (temp = (*src++) >> 8);
- *dst++ = (char) (temp >> 8);
- }
- break;
- case 4: //also truncates
- while (count--) {
- *dst++ = (char) (temp = (*src++) >> 16);
- *dst++ = (char) (temp >> 8);
- //*dst++ = (char) (temp >> 16);
- //*dst++ = (char) (temp >> 24);
- }
- break;
- }
-
- return;
+ //this handles converting the fixed 32bit per sample produced by UnpackSamples
+ //to 16 bps, by truncating (24/32) or sign-extending (8)
+ //could eventually be asm-optimized..
+ int32_t temp;
+
+ switch (Bps) {
+ case 1:
+ while (count--) {
+ *dst++ = (char) 0; //left shift the 8 bit sample
+ *dst++ = (char) *src++ ;//+ 128; //only works with u8int ?
+ }
+ break;
+ case 2:
+ while (count--) {
+ *dst++ = (char) (temp = *src++); //low byte
+ *dst++ = (char) (temp >> 8); //high byte
+ }
+ break;
+ case 3: //modified to truncate to 16bits
+ while (count--) {
+ *dst++ = (char) (temp = (*src++) >> 8);
+ *dst++ = (char) (temp >> 8);
+ }
+ break;
+ case 4: //also truncates
+ while (count--) {
+ *dst++ = (char) (temp = (*src++) >> 16);
+ *dst++ = (char) (temp >> 8);
+ //*dst++ = (char) (temp >> 16);
+ //*dst++ = (char) (temp >> 24);
+ }
+ break;
+ }
+
+ return;
}
} // namespace Mixxx
diff --git a/plugins/soundsourcewv/soundsourcewv.h b/plugins/soundsourcewv/soundsourcewv.h
index 5589bb7a5c..e7235da39a 100644
--- a/plugins/soundsourcewv/soundsourcewv.h
+++ b/plugins/soundsourcewv/soundsourcewv.h
@@ -9,6 +9,7 @@
#include <QString>
#include "soundsource.h"
#include "defs_version.h"
+#include "util/defs.h"
#include "wavpack/wavpack.h"
@@ -26,11 +27,11 @@ class SoundSourceWV : public SoundSource {
public:
SoundSourceWV(QString qFilename);
~SoundSourceWV();
- int open();
+ Result open();
long seek(long);
unsigned read(unsigned long size, const SAMPLE*);
inline long unsigned length();
- int parseHeader();
+ Result parseHeader();
static QList<QString> supportedFileExtensions();
private:
int Bps;