/* * main: * ----- */ int main(int argc, char **argv) { int raw = 0; int n, p, total; int mono_from_stereo = 0; time_t start, end; static unsigned int buff[samp_per_frame]; fprintf(stderr, "Shine v1.08 19/06/03\n"); time(&start); shine_init(&config); if (!parse_command(argc, argv, &raw, &mono_from_stereo)) print_usage(); shine_update(&config); open_bit_stream(&config, "a.mp3"); fprintf(stderr, "Shine %p\n", config.scalefac_band_long); n = config.samples_per_frame >> (2 - config.channels); for ( ; ; ) { p = read(0, buff, sizeof(unsigned int) * n); if (p <= 0) break; p = p / sizeof(unsigned int); while (p < n) buff[p++] = 0; total = shine_frame(&config, buff, n * sizeof(unsigned int), ignore, sizeof(ignore)); write(1, ignore, total); } close_bit_stream(&config); shine_fini(&config); time(&end); fprintf(stderr, "use %ld\n", end - start); return 0; }
/* * L3_compress: * ------------ */ void L3_compress(void) { int frames_processed; int ch; int i; int gr; static short buffer[2][1152]; short *buffer_window[2]; int remainder; int bytes_per_frame; int lag; int mean_bits; int sideinfo_len; static int l3_enc[2][2][samp_per_frame2]; static int l3_sb_sample[2][3][18][SBLIMIT]; static int mdct_freq[2][2][samp_per_frame2]; static L3_side_info_t side_info; if(config.mpeg.type == MPEG1) { config.mpeg.granules = 2; config.mpeg.samples_per_frame = samp_per_frame; config.mpeg.resv_limit = ((1<<9)-1)<<3; sideinfo_len = (config.mpeg.channels == 1) ? 168 : 288; } else /* mpeg 2/2.5 */ { config.mpeg.granules = 1; config.mpeg.samples_per_frame = samp_per_frame2; config.mpeg.resv_limit = ((1<<8)-1)<<3; sideinfo_len = (config.mpeg.channels == 1) ? 104 : 168; } scalefac_band_long = sfBandIndex[config.mpeg.type][config.mpeg.samplerate_index]; #ifdef NO_RESERVOIR config.mpeg.resv_limit = 0; #endif { /* find number of whole bytes per frame and the remainder */ int x = config.mpeg.samples_per_frame * config.mpeg.bitr * (1000/8); bytes_per_frame = x / config.wave.samplerate; remainder = x % config.wave.samplerate; } config.mpeg.total_frames = /* round up */ (config.wave.total_samples + config.mpeg.samples_per_frame - 1) / config.mpeg.samples_per_frame; printf("%d frames\n",config.mpeg.total_frames); frames_processed = lag = 0; open_bit_stream(config.outfile); while(wave_get(buffer)) { frames_processed++; if(((frames_processed & 7)==0) || (frames_processed >= config.mpeg.total_frames)) printf("\015[%d] %d%%", frames_processed,(frames_processed*100)/config.mpeg.total_frames); buffer_window[0] = buffer[0]; buffer_window[1] = buffer[1]; /* sort out padding */ config.mpeg.padding = (lag += remainder) >= config.wave.samplerate; if (config.mpeg.padding) lag -= config.wave.samplerate; config.mpeg.bits_per_frame = 8*(bytes_per_frame + config.mpeg.padding); /* bits per channel per granule */ mean_bits = (config.mpeg.bits_per_frame - sideinfo_len) >> (config.mpeg.granules + config.mpeg.channels - 2); /* polyphase filtering */ for(gr=0; gr<config.mpeg.granules; gr++) for(ch=0; ch<config.mpeg.channels; ch++) for(i=0;i<18;i++) L3_window_filter_subband(&buffer_window[ch], &l3_sb_sample[ch][gr+1][i][0] ,ch); /* apply mdct to the polyphase output */ L3_mdct_sub(l3_sb_sample, mdct_freq); /* bit and noise allocation */ L3_iteration_loop(mdct_freq, &side_info, l3_enc, mean_bits); /* write the frame to the bitstream */ L3_format_bitstream(l3_enc, &side_info); } close_bit_stream(); }