audio.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5. #include "musical_notes.h"
  6. #ifndef AUDIO_H
  7. #define AUDIO_H
  8. typedef union {
  9. uint8_t raw;
  10. struct {
  11. bool enable :1;
  12. uint8_t level :7;
  13. };
  14. } audio_config_t;
  15. void audio_toggle(void);
  16. void audio_on(void);
  17. void audio_off(void);
  18. void play_sample(uint8_t * s, uint16_t l, bool r);
  19. void play_note(double freq, int vol);
  20. void stop_note(double freq);
  21. void stop_all_notes(void);
  22. void init_notes(void);
  23. void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest);
  24. void set_timbre(float timbre);
  25. void set_tempo(float tempo);
  26. void increase_tempo(uint8_t tempo_change);
  27. void decrease_tempo(uint8_t tempo_change);
  28. // These macros are used to allow play_notes to play an array of indeterminate
  29. // length. This works around the limitation of C's sizeof operation on pointers.
  30. // The global float array for the song must be used here.
  31. #define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0]))))
  32. #define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style));
  33. #endif