Exemplo n.º 1
0
static void dsp_calculate_fft(dsp16_t *fft, dsp16_t *signal)
{
	int i;
	dsp16_t max_value;
	dsp16_t temp[BUFFER_LENGTH];
	dsp16_complex_t temp_res[BUFFER_LENGTH];

	dsp16_vect_dotmul(temp, signal, fft_window, BUFFER_LENGTH);
	dsp16_trans_realcomplexfft(temp_res, temp, BUFFER_LENGTH_LOG);
	dsp16_vect_complex_abs(fft, temp_res, BUFFER_LENGTH);

	for (i = 0; i < FFT_LENGTH; i++)
		fft[i] += fft[BUFFER_LENGTH - i - 1];

	max_value = dsp16_vect_max(fft, FFT_LENGTH);
	dsp16_vect_realdiv(fft, fft, FFT_LENGTH, max_value + 1);
}
int real_division(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT3_SIZE > 0)

  // Action
  dsp16_debug_printf("vect1 = vect2 / %f\n", vect3[0]);

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_realdiv(vect1, vect2, VECT2_SIZE, vect3[0]);

  return Get_sys_count() - cycle_count;
}
Exemplo n.º 3
0
static bool usb_stream_process(void)
{
    buffer_t *input_buffer;
#if (defined __GNUC__)
    dsp16_t * volatile dsp16_output_buffer;
#else
    dsp16_t * dsp16_output_buffer;
#endif
    int i, channel, size = 0;

    // If no buffer is ready, then set under flow marker
    if (usb_stream_context->current_full_buffer == -1)
        return false;

    // If the audio DAC is not ready to receive more data, then return
    if (!audio_mixer_dacs_output_direct(NULL, 0))
        return false;

    // Select the current input buffer and make sure it is valid
    input_buffer = usb_stream_context->input_buffers[usb_stream_context->current_full_buffer];

    // Make sure this buffer is not already in the process of resampling
    if (input_buffer->buffer_state != BUFFER_STATE_FULL)
        return false;

    // Mark this buffer as a "resampling" buffer
    input_buffer->buffer_state = BUFFER_STATE_RESAMPLING;

    // Select the current output buffer
    dsp16_output_buffer = (dsp16_t *) usb_stream_context->output_buffers[usb_stream_context->current_output_buffer];

    for (channel=0; channel<usb_stream_context->nb_channels; channel++)
    {
        // Interpolates the current channel buffer
        dsp16_resampling_compute(usb_stream_context->ctx->resampling,
                                 usb_stream_context->output_temp_buffer,
                                 input_buffer->buffer[channel],
                                 channel);
        size = dsp16_resampling_get_output_current_buffer_size(usb_stream_context->ctx->resampling);
        // Fill the array with audio samples and mix the channels
        switch (usb_stream_context->nb_channels)
        {
        case 1:
            memcpy(dsp16_output_buffer, usb_stream_context->output_temp_buffer, usb_stream_context->input_buffer_size);
            break;
        case 2:
            for (i=0; i<size; i++)
                dsp16_output_buffer[i*2] = ((dsp16_t *) usb_stream_context->output_temp_buffer)[i];
            break;
        default:
            for (i=0; i<size; i++)
                dsp16_output_buffer[i*usb_stream_context->nb_channels] = ((dsp16_t *) usb_stream_context->output_temp_buffer)[i];
        }
        // change channel
        dsp16_output_buffer++;
    }

    // Re-selects the current output buffer
    dsp16_output_buffer = (dsp16_t *) usb_stream_context->output_buffers[usb_stream_context->current_output_buffer];

    // Scale the output buffer if the scaling is set
    if (usb_stream_context->ctx->gain)
        dsp16_vect_realdiv(dsp16_output_buffer, dsp16_output_buffer, size * usb_stream_context->nb_channels, usb_stream_context->ctx->gain);

    // Send the buffer to the output channel
    audio_mixer_dacs_output_direct(dsp16_output_buffer, size);

    // Set the current input buffer as an empty buffer
    input_buffer->buffer_state = BUFFER_STATE_EMPTY;

    // Update the current output buffer index
    usb_stream_context->current_output_buffer = (usb_stream_context->current_output_buffer+1)%AUDIO_STREAM_NB_OUTPUT_BUFFERS;

    // Update the current full buffer pointer
    i = (usb_stream_context->current_full_buffer+1)%AUDIO_STREAM_NB_INPUT_BUFFERS;
    input_buffer = usb_stream_context->input_buffers[i];
    if (input_buffer->buffer_state != BUFFER_STATE_FULL)
        i = -1;
    usb_stream_context->current_full_buffer = i;

    return true;
}