Mercurial > audlegacy-plugins
comparison src/madplug/decoder.c @ 2342:f40f4ae3d5eb
made some debug messages conditional.
| author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
|---|---|
| date | Thu, 31 Jan 2008 15:26:50 +0900 |
| parents | 59addab003d7 |
| children | fd8271f07747 |
comparison
equal
deleted
inserted
replaced
| 2341:59addab003d7 | 2342:f40f4ae3d5eb |
|---|---|
| 43 */ | 43 */ |
| 44 static inline signed int | 44 static inline signed int |
| 45 scale(mad_fixed_t sample, struct mad_info_t *file_info) | 45 scale(mad_fixed_t sample, struct mad_info_t *file_info) |
| 46 { | 46 { |
| 47 gdouble scale = -1; | 47 gdouble scale = -1; |
| 48 #ifdef AUD_DEBUG | |
| 48 static int i = 0; | 49 static int i = 0; |
| 50 #endif | |
| 49 | 51 |
| 50 if (audmad_config->replaygain.enable) { | 52 if (audmad_config->replaygain.enable) { |
| 51 if (file_info->has_replaygain) { | 53 if (file_info->has_replaygain) { |
| 52 // apply track gain if it is available and track mode is specified | 54 // apply track gain if it is available and track mode is specified |
| 53 if(file_info->replaygain_track_scale != -1) { | 55 if(file_info->replaygain_track_scale != -1) { |
| 61 | 63 |
| 62 // apply preamp1 | 64 // apply preamp1 |
| 63 scale *= audmad_config->replaygain.preamp1_scale; | 65 scale *= audmad_config->replaygain.preamp1_scale; |
| 64 | 66 |
| 65 if (audmad_config->replaygain.anti_clip) { | 67 if (audmad_config->replaygain.anti_clip) { |
| 68 #ifdef AUD_DEBUG | |
| 66 if(i%100000 == 0) | 69 if(i%100000 == 0) |
| 67 AUDDBG("track_peak = %f\n", file_info->replaygain_track_peak); | 70 AUDDBG("track_peak = %f\n", file_info->replaygain_track_peak); |
| 71 #endif | |
| 68 if(scale * file_info->replaygain_track_peak >= 1.0) | 72 if(scale * file_info->replaygain_track_peak >= 1.0) |
| 69 scale = 1.0 / file_info->replaygain_track_peak; | 73 scale = 1.0 / file_info->replaygain_track_peak; |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 else { | 76 else { |
| 80 | 84 |
| 81 // apply global gain | 85 // apply global gain |
| 82 if (audmad_config->replaygain.preamp0_scale != 1) | 86 if (audmad_config->replaygain.preamp0_scale != 1) |
| 83 scale = scale * audmad_config->replaygain.preamp0_scale; | 87 scale = scale * audmad_config->replaygain.preamp0_scale; |
| 84 | 88 |
| 89 #ifdef AUD_DEBUG | |
| 85 if(i%100000 == 0) { | 90 if(i%100000 == 0) { |
| 86 AUDDBG("scale = %f\n", scale); | 91 AUDDBG("scale = %f\n", scale); |
| 87 } | 92 } |
| 93 #endif | |
| 88 | 94 |
| 89 /* hard-limit (clipping-prevention) */ | 95 /* hard-limit (clipping-prevention) */ |
| 90 if (audmad_config->replaygain.hard_limit) { | 96 if (audmad_config->replaygain.hard_limit) { |
| 91 | 97 |
| 98 #ifdef AUD_DEBUG | |
| 92 if(i%100000 == 0) { | 99 if(i%100000 == 0) { |
| 93 AUDDBG("hard_limit\n"); | 100 AUDDBG("hard_limit\n"); |
| 94 } | 101 } |
| 95 | 102 #endif |
| 96 /* convert to double before computation, to avoid mad_fixed_t wrapping */ | 103 /* convert to double before computation, to avoid mad_fixed_t wrapping */ |
| 97 double x = mad_f_todouble(sample) * scale; | 104 double x = mad_f_todouble(sample) * scale; |
| 98 static const double k = 0.5; // -6dBFS | 105 static const double k = 0.5; // -6dBFS |
| 99 if (x > k) { | 106 if (x > k) { |
| 100 x = tanh((x - k) / (1 - k)) * (1 - k) + k; | 107 x = tanh((x - k) / (1 - k)) * (1 - k) + k; |
| 102 else if (x < -k) { | 109 else if (x < -k) { |
| 103 x = tanh((x + k) / (1 - k)) * (1 - k) - k; | 110 x = tanh((x + k) / (1 - k)) * (1 - k) - k; |
| 104 } | 111 } |
| 105 sample = x * (MAD_F_ONE); | 112 sample = x * (MAD_F_ONE); |
| 106 | 113 |
| 114 #ifdef AUD_DEBUG | |
| 107 if(i%100000 == 0) { | 115 if(i%100000 == 0) { |
| 108 AUDDBG("x = %f sample = %d\n", x, sample); | 116 AUDDBG("x = %f sample = %d\n", x, sample); |
| 109 } | 117 } |
| 118 #endif | |
| 110 | 119 |
| 111 } | 120 } |
| 112 else | 121 else |
| 113 sample *= scale; | 122 sample *= scale; |
| 114 | 123 |
| 124 #ifdef AUD_DEBUG | |
| 115 i++; | 125 i++; |
| 126 #endif | |
| 116 | 127 |
| 117 int n_bits_to_loose = MAD_F_FRACBITS + 1 - 16; | 128 int n_bits_to_loose = MAD_F_FRACBITS + 1 - 16; |
| 118 | 129 |
| 119 /* round */ | 130 /* round */ |
| 120 /* add half of the bits_to_loose range to round */ | 131 /* add half of the bits_to_loose range to round */ |
