diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2013-10-09 18:53:18 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2013-10-09 18:53:18 +0000 |
| commit | 8f10f5f1023a0fcdbf8370a59d7a797b0b44c8fd (patch) | |
| tree | ee43be128c135ec9aea0af3cf8af1bd77a4b4450 | |
| parent | 92239f61e83e7269edd138fb389b940b0c16eb26 (diff) | |
| download | qmmp-8f10f5f1023a0fcdbf8370a59d7a797b0b44c8fd.tar.gz qmmp-8f10f5f1023a0fcdbf8370a59d7a797b0b44c8fd.tar.bz2 qmmp-8f10f5f1023a0fcdbf8370a59d7a797b0b44c8fd.zip | |
rgscan: added 1 channel audio support
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3763 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/General/rgscan/rgscaner.cpp | 107 |
1 files changed, 74 insertions, 33 deletions
diff --git a/src/plugins/General/rgscan/rgscaner.cpp b/src/plugins/General/rgscan/rgscaner.cpp index c31785977..99e0e1ac3 100644 --- a/src/plugins/General/rgscan/rgscaner.cpp +++ b/src/plugins/General/rgscan/rgscaner.cpp @@ -145,17 +145,17 @@ void RGScaner::run() Qmmp::AudioFormat format = ap.format(); bool headroom = m_decoder->hasHeadroom(); const int buf_size = 8192; //samples - double out_left[buf_size >> 1], out_right[buf_size >> 1]; //replay gain buffers + double out_left[buf_size], out_right[buf_size]; //replay gain buffers float float_buf[buf_size]; //float buffer char char_buf[buf_size*ap.sampleSize()]; //char buffer qint64 totalSamples = m_decoder->totalTime() * ap.sampleRate() * ap.channels() / 1000; - qint64 sample_count = 0; + qint64 sample_counter = 0; qint64 samples = 0; double max = 0; if(m_handle) DeinitGainAbalysis(m_handle); - InitGainAnalysis(&m_handle, 44100); + InitGainAnalysis(&m_handle, ap.sampleRate()); forever { @@ -166,12 +166,23 @@ void RGScaner::run() if(samples <= 0) break; //TODO add error handler - for(int i = 0; i < (samples >> 1); ++i) + if(ap.channels() == 2) { - 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); + 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 @@ -183,36 +194,66 @@ void RGScaner::run() samples = len / ap.sampleSize(); - for(int i = 0; i < (samples >> 1); ++i) + if(ap.channels() == 2) { - switch (format) + for(int i = 0; i < (samples >> 1); ++i) { - 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)); - 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)); - default: - break; + 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); + } + } + else if(ap.channels() == 1) + { + 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); } - max = qMax(fabs(out_left[i]), max); - max = qMax(fabs(out_right[i]), max); } - } - AnalyzeSamples(m_handle, out_left, out_right, samples >> 1, 2); - sample_count += samples; - emit progress(100 * sample_count / totalSamples); + size_t samples_per_channel = samples >> ((ap.channels() == 2) ? 1 : 0); + + AnalyzeSamples(m_handle, out_left, out_right, samples_per_channel, ap.channels()); + sample_counter += samples; + emit progress(100 * sample_counter / totalSamples); m_mutex.lock(); if(m_user_stop) @@ -226,7 +267,7 @@ void RGScaner::run() m_gain = GetTitleGain(m_handle); m_peak = max/32768.0; qDebug("RGScaner: peak = %f", m_peak); - qDebug("RGScaner: thread %ld finished", QThread::currentThreadId()); + qDebug("RGScaner: thread %lu finished", QThread::currentThreadId()); m_is_running = false; emit progress(100); emit finished(m_url); |
