diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-12-27 15:38:48 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-12-27 15:38:48 +0000 |
| commit | 35683d6728e70fa9eb218dd87eaa2092a02d9c3d (patch) | |
| tree | cc62c2ed0bbfc7726adf21c48862bee156e89be2 /src/plugins/General | |
| parent | 94d94e53ee022fa98bc6fcafa3b645e29916c6b4 (diff) | |
| download | qmmp-35683d6728e70fa9eb218dd87eaa2092a02d9c3d.tar.gz qmmp-35683d6728e70fa9eb218dd87eaa2092a02d9c3d.tar.bz2 qmmp-35683d6728e70fa9eb218dd87eaa2092a02d9c3d.zip | |
enabled replay gain scanner
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5913 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General')
| -rw-r--r-- | src/plugins/General/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/plugins/General/General.pro | 4 | ||||
| -rw-r--r-- | src/plugins/General/rgscan/rgscanner.cpp | 137 |
3 files changed, 41 insertions, 102 deletions
diff --git a/src/plugins/General/CMakeLists.txt b/src/plugins/General/CMakeLists.txt index 1b02b2d19..3eb64595b 100644 --- a/src/plugins/General/CMakeLists.txt +++ b/src/plugins/General/CMakeLists.txt @@ -71,7 +71,7 @@ add_subdirectory(converter) ENDIF(USE_CONVERTER AND TAGLIB_FOUND) IF(USE_RGSCAN AND TAGLIB_FOUND) -#add_subdirectory(rgscan) +add_subdirectory(rgscan) ENDIF(USE_RGSCAN AND TAGLIB_FOUND) IF(USE_SB) diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro index c503b9db4..9484a4b3d 100644 --- a/src/plugins/General/General.pro +++ b/src/plugins/General/General.pro @@ -9,8 +9,8 @@ SUBDIRS += statusicon \ streambrowser \ trackchange \ hotkey \ - copypaste -# rgscan + copypaste \ + rgscan unix:SUBDIRS += mpris \ kdenotify \ converter \ diff --git a/src/plugins/General/rgscan/rgscanner.cpp b/src/plugins/General/rgscan/rgscanner.cpp index 2afacd921..7e5692398 100644 --- a/src/plugins/General/rgscan/rgscanner.cpp +++ b/src/plugins/General/rgscan/rgscanner.cpp @@ -22,8 +22,11 @@ #include <math.h> #include <qmmp/inputsourcefactory.h> #include <qmmp/decoderfactory.h> +#include <qmmp/audioconverter.h> #include "rgscanner.h" +#define BUFFER_FRAMES 4096 + RGScanner::RGScanner() { m_gain = 0.; @@ -174,15 +177,19 @@ void RGScanner::run() bool error = false; AudioParameters ap = m_decoder->audioParameters(); - Qmmp::AudioFormat format = ap.format(); - bool headroom = m_decoder->hasHeadroom(); - const int buf_size = 8192; //samples - double out_left[buf_size], out_right[buf_size]; //replay gain buffers - float float_buf[buf_size]; //float buffer - unsigned char char_buf[buf_size*ap.sampleSize()]; //char buffer - qint64 totalSamples = m_decoder->totalTime() * ap.sampleRate() * ap.channels() / 1000; - qint64 sample_counter = 0; - qint64 samples = 0; + AudioConverter converter; + converter.configure(ap.format()); + //buffers + double out_left[BUFFER_FRAMES], out_right[BUFFER_FRAMES]; //replay gain buffers + float float_buf[BUFFER_FRAMES*ap.channels()]; //float buffer + qint64 char_buf_size = BUFFER_FRAMES*ap.channels()*ap.sampleSize(); + unsigned char char_buf[char_buf_size]; //char buffer + + + //counters + qint64 totalSamples = m_decoder->totalTime() * ap.sampleRate() * ap.channels() / 1000, len = 0; + quint64 sample_counter = 0; + quint64 samples = 0; double max = 0; if(m_handle) @@ -191,104 +198,36 @@ void RGScanner::run() forever { - if(headroom) - { - samples = m_decoder->read(float_buf, buf_size); - - if(samples < 0) - { - error = true; - break; - } - else if(samples == 0) - break; + len = m_decoder->read(char_buf, char_buf_size); - if(ap.channels() == 2) - { - for(int i = 0; i < (samples >> 1); ++i) - { - out_left[i] = float_buf[i*2]*32768.0; - out_right[i] = float_buf[i*2+1]*32768.0; - max = qMax(fabs(out_left[i]), max); - max = qMax(fabs(out_right[i]), max); - } - } - else if(ap.channels() == 1) - { - for(int i = 0; i < samples; ++i) - { - out_left[i] = float_buf[i]*32768.0; - max = qMax(fabs(out_left[i]), max); - } - } - } - else + if(len < 0) { + error = true; + break; + } + else if(len == 0) + break; - qint64 len = m_decoder->read(char_buf, buf_size*ap.sampleSize()); + samples = len / ap.sampleSize(); - if(len < 0) - { - error = true; - break; - } - else if(len == 0) - break; + converter.toFloat(char_buf, float_buf, samples); - samples = len / ap.sampleSize(); - - if(ap.channels() == 2) + if(ap.channels() == 2) + { + for(uint i = 0; i < (samples >> 1); ++i) { - for(int i = 0; i < (samples >> 1); ++i) - { - switch (format) - { - case Qmmp::PCM_S8: - out_left[i] = char_buf[i*2]*32768.0/128.0; - out_right[i] = char_buf[i*2+1]*32768.0/128.0; - break; - case Qmmp::PCM_S16LE: - out_left[i] = ((short *)char_buf)[i*2]; - out_right[i] = ((short *)char_buf)[i*2+1]; - break; - case Qmmp::PCM_S24LE: - out_left[i] = ((qint32 *)char_buf)[i*2]*32768.0/((1U << 23)); - out_right[i] = ((qint32 *)char_buf)[i*2+1]*32768.0/((1U << 23)); - break; - case Qmmp::PCM_S32LE: - out_left[i] = ((qint32 *)char_buf)[i*2]*32768.0/((1U << 31)); - out_right[i] = ((qint32 *)char_buf)[i*2+1]*32768.0/((1U << 31)); - break; - default: - break; - } - max = qMax(fabs(out_left[i]), max); - max = qMax(fabs(out_right[i]), max); - } + out_left[i] = float_buf[i*2]*32768.0; + out_right[i] = float_buf[i*2+1]*32768.0; + max = qMax(fabs(out_left[i]), max); + max = qMax(fabs(out_right[i]), max); } - else if(ap.channels() == 1) + } + else if(ap.channels() == 1) + { + for(uint i = 0; i < samples; ++i) { - for(int i = 0; i < samples; ++i) - { - switch (format) - { - case Qmmp::PCM_S8: - out_left[i] = char_buf[i*2]*32768.0/128.0; - break; - case Qmmp::PCM_S16LE: - out_left[i] = ((short *)char_buf)[i*2]; - break; - case Qmmp::PCM_S24LE: - out_left[i] = ((qint32 *)char_buf)[i*2]*32768.0/((1U << 23)); - break; - case Qmmp::PCM_S32LE: - out_left[i] = ((qint32 *)char_buf)[i*2]*32768.0/((1U << 31)); - break; - default: - break; - } - max = qMax(fabs(out_left[i]), max); - } + out_left[i] = float_buf[i]*32768.0; + max = qMax(fabs(out_left[i]), max); } } |
