Ignore:
Timestamp:
02/13/07 11:40:24 (18 years ago)
Author:
r2d
Message:
  • changed replay gain implementation (using sv8 representation)
Location:
libmpc/branches/r2d/libmpcdec
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/libmpcdec/mpc_demux.c

    r206 r212  
    3333*/
    3434
     35#include <math.h>
    3536#include <string.h>
    3637#include <mpc/streaminfo.h>
     
    353354        memcpy(i, &d->si, sizeof d->si);
    354355}
    355 
    356 #include <stdio.h>
    357356
    358357void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
     
    471470}
    472471
     472void setReplayLevel(mpc_demux * d, float level, mpc_bool_t use_gain,
     473                                        mpc_bool_t use_title, mpc_bool_t clip_prevention)
     474{
     475        float peak = use_title ? d->si.peak_title : d->si.peak_album;
     476        float gain = use_title ? d->si.gain_title : d->si.gain_album;
     477
     478        if(!use_gain && !clip_prevention)
     479                return;
     480
     481        if(!peak)
     482                peak = 1.;
     483        else
     484                peak = (1 << 15) / __builtin_powf(10, peak / (20 * 256));
     485
     486        if(!gain)
     487                gain = 1.;
     488        else
     489                gain = __builtin_powf(10, (level - gain / 256) / 20);
     490
     491        if(clip_prevention && (peak < gain || !use_gain))
     492                gain = peak;
     493
     494        mpc_decoder_scale_output(d->d, gain);
     495}
  • libmpc/branches/r2d/libmpcdec/streaminfo.c

    r201 r212  
    3535/// Implementation of streaminfo reading functions.
    3636
     37#include <math.h>
    3738#include <mpc/mpcdec.h>
    3839#include <mpc/streaminfo.h>
     
    125126        si->block_pwr          = 0;
    126127
     128        // convert gain info
     129        if (si->gain_title != 0) {
     130                int tmp = (int)((65. - si->gain_title / 100.) * 256);
     131                if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
     132                si->gain_title = (mpc_int16_t) tmp;
     133        }
     134
     135        if (si->gain_album != 0) {
     136                int tmp = (int)((65. - si->gain_album / 100.) * 256);
     137                if (tmp >= (1 << 16) || tmp < 0) tmp = 0;
     138                si->gain_album = (mpc_int16_t) tmp;
     139        }
     140
     141        if (si->peak_title != 0)
     142                si->peak_title = (mpc_uint16_t) (__builtin_log10(si->peak_title) * 20 * 256);
     143
     144        if (si->peak_album != 0)
     145                si->peak_album = (mpc_uint16_t) (__builtin_log10(si->peak_album) * 20 * 256);
     146
    127147        mpc_get_encoder_string(si);
    128148
     
    146166
    147167        mpc_bits_read(&r, 8); // gain version
    148         // FIXME : add gain conversion
    149168        si->gain_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
    150169        si->peak_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
Note: See TracChangeset for help on using the changeset viewer.