Changeset 403 for libreplaygain
- Timestamp:
- 04/25/08 17:03:53 (17 years ago)
- Location:
- libreplaygain
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libreplaygain/include/replaygain/gain_analysis.h
r230 r403 26 26 */ 27 27 28 /** 29 * Pseudo-code to process an album: 30 * 31 * Float_t l_samples [4096]; 32 * Float_t r_samples [4096]; 33 * size_t num_samples; 34 * unsigned int num_songs; 35 * unsigned int i; 36 * 37 * gain_init_analysis ( 44100 ); 38 * for ( i = 1; i <= num_songs; i++ ) { 39 * while ( ( num_samples = getSongSamples ( song[i], left_samples, right_samples ) ) > 0 ) 40 * gain_analyze_samples ( left_samples, right_samples, num_samples, 2 ); 41 * fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, gain_get_title() ); 42 * } 43 * fprintf ("Recommended dB change for whole album: %+6.2f dB\n", gain_get_album() ); 44 */ 45 28 46 #ifndef GAIN_ANALYSIS_H 29 47 #define GAIN_ANALYSIS_H … … 44 62 typedef double Float_t; // Type used for filtering 45 63 46 int InitGainAnalysis ( long samplefreq ); 47 int AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels ); 48 int ResetSampleFrequency ( long samplefreq ); 49 Float_t GetTitleGain ( void ); 50 Float_t GetAlbumGain ( void ); 64 /// Here's the deal : Call 65 int gain_init_analysis ( long samplefreq ); 66 /// to initialize everything. Call 67 int gain_analyze_samples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels ); 68 /// as many times as you want, with as many or as few samples as you want. 69 /// If mono, pass the sample buffer in through left_samples, leave 70 /// right_samples NULL, and make sure num_channels = 1. 71 72 Float_t gain_get_title ( void ); 73 /// will return the recommended dB level change for all samples analyzed 74 /// SINCE THE LAST TIME you called gain_get_title() OR gain_init_analysis(). 75 76 Float_t gain_get_album ( void ); 77 /// will return the recommended dB level change for all samples analyzed 78 /// since gain_init_analysis() was called and finalized with gain_get_title(). 51 79 52 80 #ifdef __cplusplus -
libreplaygain/src/Makefile.am
r230 r403 4 4 libreplaygain_la_LDFLAGS = -no-undefined -version-info 1:0:0 5 5 libreplaygain_la_SOURCES = gain_analysis.c 6 6 AM_CFLAGS = -fpic -
libreplaygain/src/gain_analysis.c
r230 r403 32 32 33 33 /* 34 * Here's the deal. Call35 *36 * InitGainAnalysis ( long samplefreq );37 *38 * to initialize everything. Call39 *40 * AnalyzeSamples ( const Float_t* left_samples,41 * const Float_t* right_samples,42 * size_t num_samples,43 * int num_channels );44 *45 * as many times as you want, with as many or as few samples as you want.46 * If mono, pass the sample buffer in through left_samples, leave47 * right_samples NULL, and make sure num_channels = 1.48 *49 * GetTitleGain()50 *51 * will return the recommended dB level change for all samples analyzed52 * SINCE THE LAST TIME you called GetTitleGain() OR InitGainAnalysis().53 *54 * GetAlbumGain()55 *56 * will return the recommended dB level change for all samples analyzed57 * since InitGainAnalysis() was called and finalized with GetTitleGain().58 *59 * Pseudo-code to process an album:60 *61 * Float_t l_samples [4096];62 * Float_t r_samples [4096];63 * size_t num_samples;64 * unsigned int num_songs;65 * unsigned int i;66 *67 * InitGainAnalysis ( 44100 );68 * for ( i = 1; i <= num_songs; i++ ) {69 * while ( ( num_samples = getSongSamples ( song[i], left_samples, right_samples ) ) > 0 )70 * AnalyzeSamples ( left_samples, right_samples, num_samples, 2 );71 * fprintf ("Recommended dB change for song %2d: %+6.2f dB\n", i, GetTitleGain() );72 * }73 * fprintf ("Recommended dB change for whole album: %+6.2f dB\n", GetAlbumGain() );74 */75 76 /*77 34 * So here's the main source of potential code confusion: 78 35 * … … 81 38 * AND up to <filter order> number of previous filtered samples. 82 39 * 83 * I set up the AnalyzeSamples routine to minimize memory usage and interface40 * I set up the gain_analyze_samples routine to minimize memory usage and interface 84 41 * complexity. The speed isn't compromised too much (I don't think), but the 85 42 * internal complexity is higher than it should be for such a relatively … … 115 72 #define PINK_REF 64.82 //298640883795 // calibration value 116 73 117 Float_tlinprebuf [MAX_ORDER * 2];118 Float_t*linpre; // left input samples, with pre-buffer119 Float_tlstepbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER];120 Float_t*lstep; // left "first step" (i.e. post first filter) samples121 Float_tloutbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER];122 Float_t*lout; // left "out" (i.e. post second filter) samples123 Float_trinprebuf [MAX_ORDER * 2];124 Float_t*rinpre; // right input samples ...125 Float_trstepbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER];126 Float_t*rstep;127 Float_troutbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER];128 Float_t*rout;129 longsampleWindow; // number of samples required to reach number of milliseconds required for RMS window130 longtotsamp;131 doublelsum;132 doublersum;133 intfreqindex;134 intfirst;135 static Uint32_t 136 static Uint32_t 74 static Float_t linprebuf [MAX_ORDER * 2]; 75 static Float_t* linpre; // left input samples, with pre-buffer 76 static Float_t lstepbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 77 static Float_t* lstep; // left "first step" (i.e. post first filter) samples 78 static Float_t loutbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 79 static Float_t* lout; // left "out" (i.e. post second filter) samples 80 static Float_t rinprebuf [MAX_ORDER * 2]; 81 static Float_t* rinpre; // right input samples ... 82 static Float_t rstepbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 83 static Float_t* rstep; 84 static Float_t routbuf [MAX_SAMPLES_PER_WINDOW + MAX_ORDER]; 85 static Float_t* rout; 86 static long sampleWindow; // number of samples required to reach number of milliseconds required for RMS window 87 static long totsamp; 88 static double lsum; 89 static double rsum; 90 static int freqindex; 91 static int first; 92 static Uint32_t A [(size_t)(STEPS_per_dB * MAX_dB)]; 93 static Uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)]; 137 94 138 95 // for each filter: … … 232 189 // returns a INIT_GAIN_ANALYSIS_OK if successful, INIT_GAIN_ANALYSIS_ERROR if not 233 190 234 int191 static int 235 192 ResetSampleFrequency ( long samplefreq ) { 236 193 int i; … … 265 222 266 223 int 267 InitGainAnalysis ( long samplefreq )224 gain_init_analysis ( long samplefreq ) 268 225 { 269 226 if (ResetSampleFrequency(samplefreq) != INIT_GAIN_ANALYSIS_OK) { … … 290 247 291 248 int 292 AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels )249 gain_analyze_samples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels ) 293 250 { 294 251 const Float_t* curleft; … … 443 400 444 401 Float_t 445 GetTitleGain( void )402 gain_get_title ( void ) 446 403 { 447 404 Float_t retval; … … 465 422 466 423 Float_t 467 GetAlbumGain( void )424 gain_get_album ( void ) 468 425 { 469 426 return analyzeResult ( B, sizeof(B)/sizeof(*B) );
Note: See TracChangeset
for help on using the changeset viewer.