Sound sample and playback driver header file.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | SOUND_SAMPLE_RATE 22050UL |
Rate at which DA conversions should be done. More... | |
Functions | |
void | sound_init (void) |
Initialize the DAC, timer/counter and event system. More... | |
bool | sound_is_playing (void) |
Convenience function to check if a sound is currently playing. More... | |
void | sound_play_note (uint8_t button) |
Set sinewave frequencies to generate. More... | |
void | sound_play_sample (uint8_t button) |
Starts playing samples when button status is sent. More... | |
static void | sound_start_timer (void) |
Start the timer/counter used for sound output. More... | |
static void | sound_stop_timer (void) |
Stop the timer/counter used for sound output. More... | |
#define SOUND_SAMPLE_RATE 22050UL |
Rate at which DA conversions should be done.
Referenced by sound_init().
void sound_init | ( | void | ) |
Initialize the DAC, timer/counter and event system.
References DAC_ADJ_LEFT, dac_enable(), DAC_REF_AVCC, dac_set_active_channel(), dac_set_conversion_interval(), dac_set_conversion_parameters(), dac_set_conversion_trigger(), dac_write_configuration(), PMIC_LVL_LOW, sample_callback(), SOUND_SAMPLE_RATE, sysclk_enable_module(), SYSCLK_EVSYS, sysclk_get_per_hz(), SYSCLK_PORT_GEN, tc_enable(), tc_set_overflow_interrupt_callback(), tc_set_overflow_interrupt_level(), and tc_write_period().
Referenced by main().
bool sound_is_playing | ( | void | ) |
Convenience function to check if a sound is currently playing.
true | Sound is currently being played back. |
false | Sound is not being played back. |
References snd_cnt, and snd_len.
Referenced by play_game(), and sound_play_sample().
void sound_play_note | ( | uint8_t | buttons | ) |
Set sinewave frequencies to generate.
Sets the frequencies of notes to generate based on currently pressed buttons (each button corresponds to a unique note).
buttons | Mask of buttons which are pressed. |
References sinefreqs, sound_get_frequency_from_note(), sound_start_timer(), and sound_stop_timer().
Referenced by play_game(), and record_buttons().
void sound_play_sample | ( | uint8_t | buttons | ) |
Starts playing samples when button status is sent.
Loads information about the sound to play starts the sound timer which triggers conversions and updates of sample value in DAC, at a rate of SOUND_SAMPLE_RATE times per second.
See get_far.h for usage of GET_FAR_ADDRESS(symbol).
buttons | Mask of buttons which are pressed. |
References GET_FAR_ADDRESS, prog_snd_ptr, snd_cnt, snd_len, snd_samplewidth, sound_is_playing(), and sound_start_timer().
Referenced by play_game(), and record_buttons().
|
inlinestatic |
Start the timer/counter used for sound output.
This will start the timer/counter which is used to:
sound_init should be called before this function.
References tc_write_clock_source().
Referenced by sound_play_note(), and sound_play_sample().
|
inlinestatic |
Stop the timer/counter used for sound output.
This will stop the timer/counter which is used for sound output, effectively causing playback to halt.
References tc_write_clock_source().
Referenced by play_game(), sample_callback(), and sound_play_note().