void psycho_1(twolame_options * glopts, short buffer[2][1152], FLOAT scale[2][SBLIMIT], FLOAT ltmin[2][SBLIMIT]) { psycho_1_mem *mem; frame_header *header = &glopts->header; int nch = glopts->num_channels_out; int sblimit = glopts->sblimit; int k, i, tone = 0, noise = 0; FLOAT sample[FFT_SIZE]; FLOAT spike[2][SBLIMIT]; FLOAT *fft_buf[2]; FLOAT energy[FFT_SIZE]; /* call functions for critical boundaries, freq. */ if (!glopts->p1mem) { /* bands, bark values, and mapping */ mem = (psycho_1_mem *) TWOLAME_MALLOC(sizeof(psycho_1_mem)); mem->power = (mask_ptr) TWOLAME_MALLOC(sizeof(mask) * HAN_SIZE); if (header->version == TWOLAME_MPEG1) { mem->cbound = psycho_1_read_cbound(header->lay, header->samplerate_idx, &mem->crit_band); psycho_1_read_freq_band(&mem->ltg, header->lay, header->samplerate_idx, &mem->sub_size); } else { mem->cbound = psycho_1_read_cbound(header->lay, header->samplerate_idx + 4, &mem->crit_band); psycho_1_read_freq_band(&mem->ltg, header->lay, header->samplerate_idx + 4, &mem->sub_size); } psycho_1_make_map(mem->sub_size, mem->power, mem->ltg); for (i = 0; i < 1408; i++) mem->fft_buf[0][i] = mem->fft_buf[1][i] = 0; psycho_1_init_add_db(mem); /* create the add_db table */ mem->off[0] = 256; mem->off[1] = 256; glopts->p1mem = mem; } { mem = glopts->p1mem; fft_buf[0] = mem->fft_buf[0]; fft_buf[1] = mem->fft_buf[1]; } for (k = 0; k < nch; k++) { /* check pcm input for 3 blocks of 384 samples */ /* sami's speedup, added in 02j saves about 4% overall during an encode */ int ok = mem->off[k] % 1408; for (i = 0; i < 1152; i++) { fft_buf[k][ok++] = (FLOAT) buffer[k][i] / SCALE; if (ok >= 1408) ok = 0; } ok = (mem->off[k] + 1216) % 1408; for (i = 0; i < FFT_SIZE; i++) { sample[i] = fft_buf[k][ok++]; if (ok >= 1408) ok = 0; } mem->off[k] += 1152; mem->off[k] %= 1408; psycho_1_hann_fft_pickmax(sample, mem->power, &spike[k][0], energy); psycho_1_tonal_label(mem, &tone); psycho_1_noise_label(mem, &noise, energy); // psycho_1_dump(power, &tone, &noise) ; psycho_1_subsampling(mem->power, mem->ltg, &tone, &noise); psycho_1_threshold(mem, &tone, &noise, glopts->bitrate / nch); psycho_1_minimum_mask(mem->sub_size, mem->ltg, <min[k][0], sblimit); psycho_1_smr(<min[k][0], &spike[k][0], &scale[k][0], sblimit); } }
void psycho_1 (short buffer[2][1152], double scale[2][SBLIMIT], double ltmin[2][SBLIMIT], frame_info * frame) { frame_header *header = frame->header; int nch = frame->nch; int sblimit = frame->sblimit; int k, i, tone = 0, noise = 0; static char init = 0; static int off[2] = { 256, 256 }; double sample[FFT_SIZE]; double spike[2][SBLIMIT]; static D1408 *fft_buf; static mask_ptr power; static g_ptr ltg; FLOAT energy[FFT_SIZE]; /* call functions for critical boundaries, freq. */ if (!init) { /* bands, bark values, and mapping */ fft_buf = (D1408 *) mem_alloc ((long) sizeof (D1408) * 2, "fft_buf"); power = (mask_ptr) mem_alloc (sizeof (mask) * HAN_SIZE, "power"); if (header->version == MPEG_AUDIO_ID) { psycho_1_read_cbound (header->lay, header->sampling_frequency); psycho_1_read_freq_band (<g, header->lay, header->sampling_frequency); } else { psycho_1_read_cbound (header->lay, header->sampling_frequency + 4); psycho_1_read_freq_band (<g, header->lay, header->sampling_frequency + 4); } psycho_1_make_map (power, ltg); for (i = 0; i < 1408; i++) fft_buf[0][i] = fft_buf[1][i] = 0; psycho_1_init_add_db (); /* create the add_db table */ init = 1; } for (k = 0; k < nch; k++) { /* check pcm input for 3 blocks of 384 samples */ /* sami's speedup, added in 02j saves about 4% overall during an encode */ int ok = off[k] % 1408; for (i = 0; i < 1152; i++) { fft_buf[k][ok++] = (double) buffer[k][i] / SCALE; if (ok >= 1408) ok = 0; } ok = (off[k] + 1216) % 1408; for (i = 0; i < FFT_SIZE; i++) { sample[i] = fft_buf[k][ok++]; if (ok >= 1408) ok = 0; } off[k] += 1152; off[k] %= 1408; psycho_1_hann_fft_pickmax (sample, power, &spike[k][0], energy); psycho_1_tonal_label (power, &tone); psycho_1_noise_label (power, &noise, ltg, energy); //psycho_1_dump(power, &tone, &noise) ; psycho_1_subsampling (power, ltg, &tone, &noise); psycho_1_threshold (power, ltg, &tone, &noise, bitrate[header->version][header->bitrate_index] / nch); psycho_1_minimum_mask (ltg, <min[k][0], sblimit); psycho_1_smr (<min[k][0], &spike[k][0], &scale[k][0], sblimit); } }