/***************************************************************************** * DoWork: process samples buffer ***************************************************************************** * This function queues the audio buffer to be processed by the galaktos thread *****************************************************************************/ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter, aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf ) { int i_samples; int i_channels; float *p_float; galaktos_thread_t *p_thread = p_filter->p_sys->p_thread; p_float = (float *)p_in_buf->p_buffer; i_channels = p_thread->i_channels; p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes; for( i_samples = p_in_buf->i_nb_samples; i_samples > 0; i_samples-- ) { int i_cur_sample = p_thread->i_cur_sample; p_thread->p_data[0][i_cur_sample] = FloatToInt16( p_float[0] ); if( i_channels > 1 ) { p_thread->p_data[1][i_cur_sample] = FloatToInt16( p_float[1] ); } p_float += i_channels; if( ++(p_thread->i_cur_sample) == 512 ) { addPCM( p_thread->p_data ); p_thread->i_cur_sample = 0; } } }
/***************************************************************************** * Fill buffer *****************************************************************************/ static int FillBuffer( int16_t *p_data, int *pi_data, date_t *pi_date, date_t *pi_date_end, goom_thread_t *p_this ) { int i_samples = 0; block_t *p_block; while( *pi_data < 512 ) { if( !p_this->i_blocks ) return VLC_EGENERIC; p_block = p_this->pp_blocks[0]; i_samples = __MIN( (unsigned)(512 - *pi_data), p_block->i_buffer / sizeof(float) / p_this->i_channels ); /* Date management */ if( p_block->i_pts > VLC_TS_INVALID && p_block->i_pts != date_Get( pi_date_end ) ) { date_Set( pi_date_end, p_block->i_pts ); } p_block->i_pts = VLC_TS_INVALID; date_Increment( pi_date_end, i_samples ); while( i_samples > 0 ) { float *p_float = (float *)p_block->p_buffer; p_data[*pi_data] = FloatToInt16( p_float[0] ); if( p_this->i_channels > 1 ) p_data[512 + *pi_data] = FloatToInt16( p_float[1] ); (*pi_data)++; p_block->p_buffer += (sizeof(float) * p_this->i_channels); p_block->i_buffer -= (sizeof(float) * p_this->i_channels); i_samples--; } if( !p_block->i_buffer ) { block_Release( p_block ); p_this->i_blocks--; if( p_this->i_blocks ) memmove( p_this->pp_blocks, p_this->pp_blocks + 1, p_this->i_blocks * sizeof(block_t *) ); } } *pi_date = *pi_date_end; *pi_data = 0; return VLC_SUCCESS; }
PackedInt16Cplx* CreatePackedTwiddleFactors(int size) { int i; PackedInt16Cplx* twiddleFactors = (PackedInt16Cplx*)malloc(sizeof(PackedInt16Cplx)*size); float scaleFac = (float)(1<<15); if(twiddleFactors) { for(i = 0; i < size/2; ++i) { int cosSin; float tmp; tmp = scaleFac*cosf(2.0*M_PI*i/size); cosSin = FloatToInt16(tmp) << 16; tmp = -scaleFac*sinf(2.0*M_PI*i/size); cosSin |= FloatToInt16(tmp) & 0x0000ffff; twiddleFactors[i] = cosSin; } } return twiddleFactors; }