static inline void maybe_do_fft( void) { if( ++grab_cnt < FFTWID) return; grab_cnt = 0; process_fft( &left); if( CF_chans == 2) process_fft( &right); if( ++frame_cnt == output_int) { frame_cnt = 0; output_record(); } if( ++uspec_cnt == uspec_max) { uspec_cnt = 0; utility_spectrum(); } }
enum mad_flow output(void *data, struct mad_header const *header, struct mad_pcm *pcm) { register int nsamples = pcm->length; mad_fixed_t const *left_ch = pcm->samples[0], *right_ch = pcm->samples[1]; static unsigned char stream[1152*4]; /* 1152 because that's what mad has as a max; *4 because there are 4 distinct bytes per sample (in 2 channel case) */ static unsigned int rate = 0; static int channels = 0; static struct audio_dither dither; register char * ptr = stream; register signed int sample; register mad_fixed_t tempsample; /* Semaphore operations */ static struct sembuf read_sops = {0, -1, 0}; static struct sembuf write_sops = {1, 1, 0}; if(options.opt & MPG321_ENABLE_BUFFER) { semop(semarray,&read_sops,1); ptr = (Output_Queue+mad_decoder_position)->data; memcpy(&((Output_Queue+mad_decoder_position)->header),header,sizeof(struct mad_header)); }else{ /* We need to know information about the file before we can open the playdevice in some cases. So, we do it here. */ if (!playdevice) { channels = MAD_NCHANNELS(header); rate = header->samplerate; open_ao_playdevice(header); } else if ((channels != MAD_NCHANNELS(header) || rate != header->samplerate) && playdevice_is_live()) { ao_close(playdevice); channels = MAD_NCHANNELS(header); rate = header->samplerate; open_ao_playdevice(header); } } static int peak_rate = 0; static unsigned short int peak = 0; if (pcm->channels == 2) { while (nsamples--) { tempsample = mad_f_mul(*left_ch++, options.volume); sample = (signed int) audio_linear_dither(16, tempsample, &dither); peak = abs(sample) > peak ? abs(sample) : peak; #ifndef WORDS_BIGENDIAN *ptr++ = (unsigned char) (sample >> 0); *ptr++ = (unsigned char) (sample >> 8); #else *ptr++ = (unsigned char) (sample >> 8); *ptr++ = (unsigned char) (sample >> 0); #endif tempsample = mad_f_mul(*right_ch++, options.volume); sample = (signed int) audio_linear_dither(16, tempsample, &dither); peak = abs(sample) > peak ? abs(sample) : peak; #ifndef WORDS_BIGENDIAN *ptr++ = (unsigned char) (sample >> 0); *ptr++ = (unsigned char) (sample >> 8); #else *ptr++ = (unsigned char) (sample >> 8); *ptr++ = (unsigned char) (sample >> 0); #endif } process_fft(stream, pcm->length * 4); if(options.opt & MPG321_ENABLE_BUFFER) { (Output_Queue+mad_decoder_position)->length = pcm->length * 4; }else { ao_play(playdevice, stream, pcm->length * 4); } } else if (options.opt & MPG321_FORCE_STEREO)
enum mad_flow output(void *data, struct mad_header const *header, struct mad_pcm *pcm) { register int nsamples = pcm->length; mad_fixed_t const *left_ch = pcm->samples[0], *right_ch = pcm->samples[1]; static unsigned char stream[1152*4]; /* 1152 because that's what mad has as a max; *4 because there are 4 distinct bytes per sample (in 2 channel case) */ static unsigned int rate = 0; static int channels = 0; static struct audio_dither dither; register char * ptr = stream; register signed int sample; register mad_fixed_t tempsample; /* We need to know information about the file before we can open the playdevice in some cases. So, we do it here. */ if (!playdevice) { channels = MAD_NCHANNELS(header); rate = header->samplerate; open_ao_playdevice(header); } else if ((channels != MAD_NCHANNELS(header) || rate != header->samplerate) && playdevice_is_live()) { ao_close(playdevice); channels = MAD_NCHANNELS(header); rate = header->samplerate; open_ao_playdevice(header); } static int peak_rate = 0; static unsigned short int peak = 0; if (pcm->channels == 2) { while (nsamples--) { tempsample = (mad_fixed_t)((*left_ch++ * (double)options.volume)/MAD_F_ONE); sample = (signed int) audio_linear_dither(16, tempsample, &dither); peak = abs(sample) > peak ? abs(sample) : peak; #ifndef WORDS_BIGENDIAN *ptr++ = (unsigned char) (sample >> 0); *ptr++ = (unsigned char) (sample >> 8); #else *ptr++ = (unsigned char) (sample >> 8); *ptr++ = (unsigned char) (sample >> 0); #endif tempsample = (mad_fixed_t)((*right_ch++ * (double)options.volume)/MAD_F_ONE); sample = (signed int) audio_linear_dither(16, tempsample, &dither); peak = abs(sample) > peak ? abs(sample) : peak; #ifndef WORDS_BIGENDIAN *ptr++ = (unsigned char) (sample >> 0); *ptr++ = (unsigned char) (sample >> 8); #else *ptr++ = (unsigned char) (sample >> 8); *ptr++ = (unsigned char) (sample >> 0); #endif } process_fft(stream, pcm->length * 4); ao_play(playdevice, stream, pcm->length * 4); } else if (options.opt & MPG321_FORCE_STEREO)