diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-12-26 21:20:53 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-12-26 21:20:53 +0000 |
| commit | 16da57620f5c9efb9d9e81ce8edecf640d20ec29 (patch) | |
| tree | 4ccd08dffb048c4e3d7e442587b9d6b26b7da010 /src | |
| parent | cf563b15e1019161b71cfbaa2cc62f2fa7d60936 (diff) | |
| download | qmmp-16da57620f5c9efb9d9e81ce8edecf640d20ec29.tar.gz qmmp-16da57620f5c9efb9d9e81ce8edecf640d20ec29.tar.bz2 qmmp-16da57620f5c9efb9d9e81ce8edecf640d20ec29.zip | |
fixed equalizer
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5892 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/equ/iir.h | 4 | ||||
| -rw-r--r-- | src/qmmp/equ/iir_fpu.c | 198 | ||||
| -rw-r--r-- | src/qmmp/outputwriter.cpp | 23 |
3 files changed, 23 insertions, 202 deletions
diff --git a/src/qmmp/equ/iir.h b/src/qmmp/equ/iir.h index 816773afe..ad241e8d8 100644 --- a/src/qmmp/equ/iir.h +++ b/src/qmmp/equ/iir.h @@ -66,9 +66,7 @@ void set_gain(int index, int chn, float val); void set_preamp(int chn, float val); -int iir(void * d, int length, int nch); -int iir32(void * d, int length, int nch); -int iir24(void * d, int length, int nch); +int iir(float * d, int samples, int nch); #ifdef ARCH_X86 __inline__ int round_trick(float floatvalue_to_round); diff --git a/src/qmmp/equ/iir_fpu.c b/src/qmmp/equ/iir_fpu.c index b6cf2dd8c..688e586da 100644 --- a/src/qmmp/equ/iir_fpu.c +++ b/src/qmmp/equ/iir_fpu.c @@ -59,17 +59,17 @@ void clean_history() di = 0; } -__inline__ int iir(void * d, int length, int nch) +__inline__ int iir(float *d, int samples, int nch) { // FTZ_ON; - short *data = (short *) d; + float *data = (float *) d; /* Indexes for the history arrays * These have to be kept between calls to this function * hence they are static */ static int i = 2, j = 1, k = 0; int index, band, channel; - int tempgint, halflength; + //int tempgint; sample_t out[EQ_CHANNELS], pcm[EQ_CHANNELS]; // Load the correct filter table according to the sampling rate if needed @@ -95,11 +95,8 @@ __inline__ int iir(void * d, int length, int nch) * This algorithm cascades two filters to get nice filtering * at the expense of extra CPU cycles */ - /* 16bit, 2 bytes per sample, so divide by two the length of - * the buffer (length is in bytes) - */ - halflength = (length >> 1); - for (index = 0; index < halflength; index+=nch) + + for (index = 0; index < samples; index+=nch) { /* For each channel */ for (channel = 0; channel < nch; channel++) @@ -109,7 +106,7 @@ __inline__ int iir(void * d, int length, int nch) pcm[channel] *= preamp[channel]; /* add random noise */ - pcm[channel] += dither[di]; + //pcm[channel] += dither[di]; out[channel] = 0.; /* For each band */ @@ -175,10 +172,10 @@ __inline__ int iir(void * d, int length, int nch) out[channel] += pcm[channel]*0.25; /* remove random noise */ - out[channel] -= dither[di]*0.25; + //out[channel] -= dither[di]*0.25; /* Round and convert to integer */ -#ifdef ARCH_PPC +/*#ifdef ARCH_PPC tempgint = round_ppc(out[channel]); #else #ifdef ARCH_X86 @@ -186,171 +183,23 @@ __inline__ int iir(void * d, int length, int nch) #else tempgint = (int)out[channel]; #endif -#endif +#endif*/ /* Limit the output */ - if (tempgint < -32768) + /*if (tempgint < -32768) data[index+channel] = -32768; else if (tempgint > 32767) data[index+channel] = 32767; else - data[index+channel] = tempgint; - } /* For each channel */ - - /* Wrap around the indexes */ - i = (i+1)%3; - j = (j+1)%3; - k = (k+1)%3; - /* random noise index */ - di = (di + 1) % 256; - - }/* For each pair of samples */ - -#ifdef BENCHMARK - timex += get_counter(); - blength += length; - if (count++ == 1024) - { - printf("FLOATING POINT: %f %d\n",timex/1024.0, blength/1024); - blength = 0; - timex = 0.; - count = 0; - } -#endif // BENCHMARK - -// FTZ_OFF; - return length; -} - -__inline__ int iir32(void * d, int length, int nch) -{ -// FTZ_ON; - int *data = (int *) d; - /* Indexes for the history arrays - * These have to be kept between calls to this function - * hence they are static */ - static int i = 2, j = 1, k = 0; - - int index, band, channel; - int tempgint, quaterlength; - sample_t out[EQ_CHANNELS], pcm[EQ_CHANNELS]; - - // Load the correct filter table according to the sampling rate if needed - /*if (srate != rate) - { - band_count = eqcfg.band_num; - rate = srate; - iir_cf = get_coeffs(&band_count, rate, eqcfg.use_xmms_original_freqs); - clean_history(); - }*/ - -#ifdef BENCHMARK - start_counter(); -#endif //BENCHMARK - - /** - * IIR filter equation is - * y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2]) - * - * NOTE: The 2 factor was introduced in the coefficients to save - * a multiplication - * - * This algorithm cascades two filters to get nice filtering - * at the expense of extra CPU cycles - */ - /* 32bit, 4 bytes per sample, so divide by four the length of - * the buffer (length is in bytes) - */ - quaterlength = (length >> 2); - for (index = 0; index < quaterlength; index+=nch) - { - /* For each channel */ - for (channel = 0; channel < nch; channel++) - { - pcm[channel] = data[index+channel]; - /* Preamp gain */ - pcm[channel] *= preamp[channel]; - - /* add random noise */ - pcm[channel] += dither[di]; - - out[channel] = 0.; - /* For each band */ - for (band = 0; band < band_count; band++) - { - /* Optimization */ - if(gain[band][channel] > -1.0e-10 && gain[band][channel] < 1.0e-10) - continue; - - /* Store Xi(n) */ - data_history[band][channel].x[i] = pcm[channel]; - /* Calculate and store Yi(n) */ - data_history[band][channel].y[i] = - ( - /* = alpha * [x(n)-x(n-2)] */ - iir_cf[band].alpha * ( data_history[band][channel].x[i] - - data_history[band][channel].x[k]) - /* + gamma * y(n-1) */ - + iir_cf[band].gamma * data_history[band][channel].y[j] - /* - beta * y(n-2) */ - - iir_cf[band].beta * data_history[band][channel].y[k] - ); - /* - * The multiplication by 2.0 was 'moved' into the coefficients to save - * CPU cycles here */ - /* Apply the gain */ - out[channel] += data_history[band][channel].y[i]*gain[band][channel]; // * 2.0; - } /* For each band */ - - //if (eqcfg.extra_filtering) - { - /* Optimization */ - if(gain[band][channel] > -1.0e-10 && gain[band][channel] < 1.0e-10) - continue; - - /* Filter the sample again */ - for (band = 0; band < band_count; band++) - { - /* Store Xi(n) */ - data_history2[band][channel].x[i] = out[channel]; - /* Calculate and store Yi(n) */ - data_history2[band][channel].y[i] = - ( - /* y(n) = alpha * [x(n)-x(n-2)] */ - iir_cf[band].alpha * (data_history2[band][channel].x[i] - - data_history2[band][channel].x[k]) - /* + gamma * y(n-1) */ - + iir_cf[band].gamma * data_history2[band][channel].y[j] - /* - beta * y(n-2) */ - - iir_cf[band].beta * data_history2[band][channel].y[k] - ); - /* Apply the gain */ - out[channel] += data_history2[band][channel].y[i]*gain[band][channel]; - } /* For each band */ - } + data[index+channel] = tempgint;*/ - /* Volume stuff - Scale down original PCM sample and add it to the filters - output. This substitutes the multiplication by 0.25 - Go back to use the floating point multiplication before the - conversion to give more dynamic range - */ - out[channel] += pcm[channel]*0.25; + data[index+channel] = out[channel]; + if(data[index+channel] > 1.0) + data[index+channel] = 1.0; + else if(data[index+channel] < -1.0) + data[index+channel] = -1.0; - /* remove random noise */ - out[channel] -= dither[di]*0.25; - /* Round and convert to integer */ -#ifdef ARCH_PPC - tempgint = round_ppc(out[channel]); -#else -#ifdef ARCH_X86 - tempgint = round_trick(out[channel]); -#else - tempgint = (int)out[channel]; -#endif -#endif - data[index+channel] = tempgint; } /* For each channel */ /* Wrap around the indexes */ @@ -375,18 +224,5 @@ __inline__ int iir32(void * d, int length, int nch) #endif // BENCHMARK // FTZ_OFF; - return length; -} - -__inline__ int iir24(void * d, int length, int nch) -{ - int *data = (int *) d; - int samples = (length >> 2); - int index; - for (index = 0; index < samples; index++) - { - if(data[index] & 0x800000) - data[index] |= 0xff000000; - } - return iir32(d, length, nch); + return samples; } diff --git a/src/qmmp/outputwriter.cpp b/src/qmmp/outputwriter.cpp index 2c697a383..b1c04d914 100644 --- a/src/qmmp/outputwriter.cpp +++ b/src/qmmp/outputwriter.cpp @@ -335,23 +335,10 @@ void OutputWriter::run() if (b) { mutex()->lock(); - /*if (m_useEq) + if (m_useEq) { - switch(m_format) - { - case Qmmp::PCM_S16LE: - iir((void*) b->data, b->nbytes, m_channels); - break; - case Qmmp::PCM_S24LE: - iir24((void*) b->data, b->nbytes, m_channels); - break; - case Qmmp::PCM_S32LE: - iir32((void*) b->data, b->nbytes, m_channels); - break; - default: - ; - } - }*/ + iir(b->data, b->samples, m_channels); + } mutex()->unlock(); dispatchVisual(b); if (SoftwareVolume::instance()) @@ -431,7 +418,7 @@ void OutputWriter::status() void OutputWriter::updateEqSettings() { - /*mutex()->lock(); + mutex()->lock(); if(m_settings->eqSettings().isEnabled()) { double preamp = m_settings->eqSettings().preamp(); @@ -449,5 +436,5 @@ void OutputWriter::updateEqSettings() } } m_useEq = m_settings->eqSettings().isEnabled(); - mutex()->unlock();*/ + mutex()->unlock(); } |
