void usb_stream_close(void) { int i; // Reset status to not initialized usb_stream_context->status = USB_STREAM_STATUS_NOT_INITIALIZED; if (usb_stream_context->ctx_overrun.resampling) dsp16_resampling_free(usb_stream_context->ctx_overrun.resampling, (free_fct_t) free); if (usb_stream_context->ctx_underrun.resampling) dsp16_resampling_free(usb_stream_context->ctx_underrun.resampling, (free_fct_t) free); if (usb_stream_context->ctx_original.resampling) dsp16_resampling_free(usb_stream_context->ctx_original.resampling, (free_fct_t) free); usb_stream_context->ctx_original.resampling = NULL; usb_stream_context->ctx_underrun.resampling = NULL; usb_stream_context->ctx_overrun.resampling = NULL; usb_stream_context->ctx = NULL; // Free also the output buffers for(i=0; i<AUDIO_STREAM_NB_OUTPUT_BUFFERS; i++) { if (usb_stream_context->output_buffers[i]) { free(usb_stream_context->output_buffers[i]); usb_stream_context->output_buffers[i] = NULL; } } // Free the temporary output buffer if (usb_stream_context->output_temp_buffer) free(usb_stream_context->output_temp_buffer); usb_stream_context->output_temp_buffer = NULL; }
//! The main function int main(int argc, char *argv[]) { A_ALIGNED static dsp16_t s_input[N/NB_CUTS]; int f; dsp_resampling_t *resampling; dsp16_t *output; U32 temp; dsp16_resampling_options_t options; // Initialize options memset(&options, 0, sizeof(options)); options.coefficients_generation = DSP16_RESAMPLING_OPTIONS_USE_DYNAMIC; options.dynamic.coefficients_normalization = true; // Switch to external Oscillator 0. pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); // Initialize the DSP debug module dsp_debug_initialization(FOSC0); dsp16_debug_printf("16-bit fixed point signal resampling\n"); dsp16_debug_printf("Input Fs: %iHz\n", F_INPUT); dsp16_debug_printf("Output Fs: %iHz\n", F_OUTPUT); dsp16_debug_printf("%i samples to process cut into %i buffers\n", N, NB_CUTS); dsp16_debug_printf("Filter order used: %i\n", FILTER_ORDER); if (!(resampling = dsp16_resampling_setup(F_INPUT, F_OUTPUT, N/NB_CUTS, FILTER_ORDER, 1, (malloc_fct_t) malloc, &options))) { dsp16_debug_printf("Unable to allocate enough memory\n"); return -1; } if (!(output = (dsp16_t *) malloc(dsp16_resampling_get_output_max_buffer_size(resampling)*sizeof(dsp16_t) + 4))) { dsp16_debug_printf("Unable to allocate enough memory for the output buffer\n"); return -1; } for(f=0; f<NB_CUTS; f++) { memcpy(s_input, &s[N/NB_CUTS*f], (N/NB_CUTS)*sizeof(dsp16_t)); temp = Get_sys_count(); dsp16_resampling_compute(resampling, output, s_input, 0); temp = Get_sys_count() - temp; dsp16_debug_print_vect(output, dsp16_resampling_get_output_current_buffer_size(resampling)); } dsp16_debug_printf( "Cycle count per iteration: %i\n in total (to compute %i samples): %i\n", temp, dsp16_resampling_get_output_current_buffer_size(resampling)*NB_CUTS, temp*NB_CUTS); dsp16_resampling_free(resampling, (free_fct_t) free); while(1); }