#include <stdio.h>
#include "conf_usb.h"
#include "conf_audio_player.h"
#include "audio_mixer.h"
#include "usb_drv.h"
#include "usb_stream_player.h"
#include "dsp.h"
#include "cycle_counter.h"
Macros | |
#define | BROKEN_STREAM_TIMER 4000 |
Functions | |
void | dac_sample_sent_cb (void) |
This callback function is called when the DAC interrupt has sent the buffer 'n-1' and switches to buffer 'n'. More... | |
void | dac_underflow_cb (void) |
This callback function is called when the PWM DAC interrupt does not have any more audio samples (i.e. More... | |
void | player_init (void) |
void | player_shutdown (void) |
void | usb_stream_close (void) |
static int | usb_stream_count_nb_buffer (buffer_state_t state) |
Returns the number of buffer filtered by state. More... | |
static int | usb_stream_current_buffer_size_left (void) |
Returns the length of the free part of the current buffer size. More... | |
static void | usb_stream_fill_input_buffers (void *buffer, int size, int nb_channels, int bits_per_sample) |
uint32_t | usb_stream_get_buffer_level () |
This function returns the number of full buffers. More... | |
uint16_t | usb_stream_get_counter () |
This function returns the internal audio counter. More... | |
static void * | usb_stream_get_current_buffer_for_writing (int channel) |
Returns a pointer on free space where to store new samples. More... | |
uint8_t | usb_stream_get_status (void) |
uint16_t | usb_stream_get_stream_status () |
This function returns the audio status. More... | |
void | usb_stream_init (uint32_t sample_rate_hz, uint8_t num_channels, uint8_t bits_per_sample, bool swap_channels) |
This function initializes the USB Stream driver. More... | |
int | usb_stream_input (usb_stream_side_t side, uint8_t pipe_in, uint32_t *pFifoCount) |
This function takes the stream coming from the selected USB pipe and sends it to the DAC driver. More... | |
bool | usb_stream_new_sample_rate (uint32_t sample_rate) |
Sync the sample rate of the audio output stream with the USB stream. More... | |
void | usb_stream_out_of_samples (void) |
int32_t | usb_stream_ppm_get (void) |
This function returns the PPM differences between the input audio stream frequency and the DAC output frequency. More... | |
static bool | usb_stream_process (void) |
void | usb_stream_resync (void) |
This function ensures that no underflow/underflow will never occur by adjusting the SSC/ABDAC frequencies. More... | |
bool | usb_stream_task (void) |
static void | usb_stream_update_buffers (int written_buffer_size) |
Update usb_stream_context->current_buffer_index usb_stream_context->current_buffer. More... | |
Variables | |
static t_cpu_time | broken_stream_timer |
volatile uint16_t | usb_stream_cnt =0 |
usb_stream_context_t * | usb_stream_context = NULL |
#define BROKEN_STREAM_TIMER 4000 |
Referenced by usb_stream_init(), and usb_stream_input().
void dac_sample_sent_cb | ( | void | ) |
This callback function is called when the DAC interrupt has sent the buffer 'n-1' and switches to buffer 'n'.
The aim of this function is thus to prepare the buffer 'n+1'; so that there is always a pending buffer for the interrupt.
void dac_underflow_cb | ( | void | ) |
This callback function is called when the PWM DAC interrupt does not have any more audio samples (i.e.
"famine").
void player_init | ( | void | ) |
Referenced by device_audio_task_init(), and host_audio_task_init().
void player_shutdown | ( | void | ) |
Referenced by host_audio_task_shutdown().
void usb_stream_close | ( | void | ) |
References dsp16_resampling_free(), i, NULL, and usb_stream_context_t::status.
Referenced by player_shutdown(), and usb_stream_init().
|
static |
Returns the number of buffer filtered by state.
References count, and current_buffer.
Referenced by usb_stream_get_buffer_level(), usb_stream_input(), and usb_stream_task().
|
inlinestatic |
Returns the length of the free part of the current buffer size.
Referenced by usb_stream_fill_input_buffers().
|
static |
References i, j, Min, swap16, swap32, usb_stream_current_buffer_size_left(), USB_STREAM_ERROR_OVERFLOW, USB_STREAM_ERROR_UNSUPPORTED, usb_stream_get_current_buffer_for_writing(), and usb_stream_update_buffers().
Referenced by usb_stream_input().
uint32_t usb_stream_get_buffer_level | ( | void | ) |
This function returns the number of full buffers.
uint16_t usb_stream_get_counter | ( | void | ) |
This function returns the internal audio counter.
|
inlinestatic |
Returns a pointer on free space where to store new samples.
References current_buffer, and NULL.
Referenced by usb_stream_fill_input_buffers().
uint8_t usb_stream_get_status | ( | void | ) |
References usb_stream_context_t::status.
uint16_t usb_stream_get_stream_status | ( | void | ) |
This function returns the audio status.
void usb_stream_init | ( | uint32_t | sample_rate_hz, |
uint8_t | num_channels, | ||
uint8_t | bits_per_sample, | ||
bool | swap_channels | ||
) |
This function initializes the USB Stream driver.
Referenced by audio_speaker_set_sample_freq(), device_audio_task_init(), host_audio_task(), and usb_stream_new_sample_rate().
int usb_stream_input | ( | usb_stream_side_t | side, |
uint8_t | pipe_in, | ||
uint32_t * | pFifoCount | ||
) |
This function takes the stream coming from the selected USB pipe and sends it to the DAC driver.
Moreover, it ensures that both input and output stream keep synchronized by adding or deleting samples.
side | USB_STREAM_HOST for USB host, USB_STREAM_DEVICE for device. |
pipe_in | Number of the addressed pipe |
pFifoCount | (return parameter) NULL or pointer to the number of used buffers at this time |
Referenced by device_audio_task(), and host_audio_task().
bool usb_stream_new_sample_rate | ( | uint32_t | sample_rate | ) |
Sync the sample rate of the audio output stream with the USB stream.
false | The new sample rate already matches the current settings. |
true | The output sample rate was changed. |
void usb_stream_out_of_samples | ( | void | ) |
References usb_stream_context_t::synchronized, and USB_STREAM_ERROR_UNDERFLOW.
int32_t usb_stream_ppm_get | ( | void | ) |
This function returns the PPM differences between the input audio stream frequency and the DAC output frequency.
Note that this information should only be considered as an indication, for debug or visual effect for example.
Referenced by mmi_activity_display().
|
static |
References audio_mixer_dacs_output_direct(), dsp16_resampling_compute(), dsp16_resampling_get_output_current_buffer_size(), dsp16_vect_realdiv(), for(), i, if(), and NULL.
Referenced by usb_stream_task().
void usb_stream_resync | ( | void | ) |
This function ensures that no underflow/underflow will never occur by adjusting the SSC/ABDAC frequencies.
Referenced by device_audio_task(), host_audio_task(), and usb_stream_input().
bool usb_stream_task | ( | void | ) |
|
static |
Update usb_stream_context->current_buffer_index usb_stream_context->current_buffer.
written_buffer_size | The size of sample written on 1 channel. |
References current_buffer, USB_STREAM_ERROR_NONE, and USB_STREAM_ERROR_OVERFLOW.
Referenced by usb_stream_fill_input_buffers().
|
static |
volatile uint16_t usb_stream_cnt =0 |
Referenced by usb_stream_get_counter(), and usb_stream_input().
usb_stream_context_t* usb_stream_context = NULL |