int resample_audio( AVAudioResampleContext *avr, audio_samples_t *out, audio_samples_t *in ) { /* Don't call this function over different block aligns. */ uint8_t *out_orig = *out->data; int out_channels = get_channel_layout_nb_channels( out->channel_layout ); int block_align = av_get_bytes_per_sample( out->sample_format ) * out_channels; int request_sample_count = out->sample_count; if( avresample_available( avr ) > 0 ) { int resampled_count = avresample_read( avr, out->data, request_sample_count ); if( resampled_count < 0 ) return 0; request_sample_count -= resampled_count; *out->data += resampled_count * block_align; } uint8_t **in_data = in->sample_count > 0 ? in->data : NULL; int in_channels = get_channel_layout_nb_channels( in->channel_layout ); int in_linesize = get_linesize( in_channels, in->sample_count, in->sample_format ); int out_linesize = get_linesize( out_channels, request_sample_count, out->sample_format ); int resampled_count = avresample_convert( avr, out->data, out_linesize, request_sample_count, in_data, in_linesize, in->sample_count ); if( resampled_count < 0 ) return 0; *out->data += resampled_count * block_align; return *out->data - out_orig; }
int main(int argc, char **argv) { int events[1],i; long long counts[1]; int retval,quiet; int l1_size,l2_size,l1_linesize,l2_entries; int arraysize; char test_string[]="Testing PAPI_L2_DCM predefined event..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("Error! PAPI_library_init %d\n",retval); test_fail(test_string); } retval = PAPI_query_event(PAPI_L2_DCM); if (retval != PAPI_OK) { if (!quiet) printf("PAPI_L2_DCM not available\n"); test_skip(test_string); } events[0]=PAPI_L2_DCM; l1_size=get_cachesize(L1D_CACHE,quiet,test_string); l1_linesize=get_linesize(L1D_CACHE,quiet,test_string); l2_size=get_cachesize(L2_CACHE,quiet,test_string); l2_entries=get_entries(L2_CACHE,quiet,test_string); /*******************************************************************/ /* Test if the C compiler uses a sane number of data cache acceess */ /*******************************************************************/ arraysize=l2_size/sizeof(double); double *array; double aSumm = 0.0; if (!quiet) { printf("Allocating %ld bytes of memory (%d doubles)\n", arraysize*sizeof(double),arraysize); } array=calloc(arraysize,sizeof(double)); if (array==NULL) { if (!quiet) printf("Error! Can't allocate memory\n"); test_fail(test_string); } if (!quiet) printf("Write test:\n"); PAPI_start_counters(events,1); for(i=0; i<arraysize; i++) { array[i]=(double)i; } PAPI_stop_counters(counts,1); if (!quiet) { printf("\tL2 D misses: %lld\n",counts[0]); printf("\tShould be roughly (%d/(%d/%ld)): %ld\n", arraysize,l1_linesize,sizeof(double), arraysize/(l1_linesize/sizeof(double))); } PAPI_start_counters(events,1); for(i=0; i<arraysize; i++) { aSumm += array[i]; } PAPI_stop_counters(counts,1); if (!quiet) { printf("Read test (%lf):\n",aSumm); printf("\tL2 D misses: %lld\n",counts[0]); printf("\tShould be roughly (%d/(%d/%ld)): %ld\n", arraysize,l1_linesize,sizeof(double), arraysize/(l1_linesize/sizeof(double))); } PAPI_shutdown(); test_pass(test_string); return 0; }