My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sound_player.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /******************
  2. * sound_player.h *
  3. ******************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <https://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #pragma once
  22. namespace FTDI {
  23. typedef enum {
  24. PLAY_ASYNCHRONOUS,
  25. PLAY_SYNCHRONOUS
  26. } play_mode_t;
  27. class SoundPlayer {
  28. typedef FTDI::ftdi_registers REG;
  29. typedef FTDI::ftdi_memory_map MAP;
  30. public:
  31. struct sound_t {
  32. effect_t effect; // The sound effect number
  33. note_t note; // The MIDI note value
  34. uint16_t sixteenths; // Duration of note, in sixteeths of a second, or zero to play to completion
  35. };
  36. const uint8_t WAIT = 0;
  37. private:
  38. const sound_t *sequence;
  39. tiny_timer_t timer;
  40. tiny_time_t wait;
  41. note_t frequency_to_midi_note(const uint16_t frequency);
  42. public:
  43. static void set_volume(uint8_t volume);
  44. static uint8_t get_volume();
  45. static void play(effect_t effect, note_t note = NOTE_C4);
  46. static bool is_sound_playing();
  47. void play(const sound_t *seq, play_mode_t mode = PLAY_SYNCHRONOUS);
  48. void play_tone(const uint16_t frequency_hz, const uint16_t duration_ms);
  49. bool has_more_notes() {return sequence != 0;};
  50. void onIdle();
  51. };
  52. extern SoundPlayer sound;
  53. const PROGMEM SoundPlayer::sound_t silence[] = {
  54. {SILENCE, END_SONG, 0}
  55. };
  56. }