audio_arm.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Copyright 2019 Jack Humbert
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include "ch.h"
  18. /**
  19. * Size of the dac_buffer arrays. All must be the same size.
  20. */
  21. #define DAC_BUFFER_SIZE 256U
  22. /**
  23. * Highest value allowed by our 12bit DAC.
  24. */
  25. #ifndef DAC_SAMPLE_MAX
  26. #define DAC_SAMPLE_MAX 4095U
  27. #endif
  28. // #define DAC_LOW_QUALITY
  29. /**
  30. * These presets allow you to quickly switch between quality/voice settings for
  31. * the DAC. The sample rate and number of voices roughly has an inverse
  32. * relationship - slightly higher sample rates may be possible.
  33. */
  34. #ifdef DAC_VERY_LOW_QUALITY
  35. #define DAC_SAMPLE_RATE 11025U
  36. #define DAC_VOICES_MAX 8
  37. #endif
  38. #ifdef DAC_LOW_QUALITY
  39. #define DAC_SAMPLE_RATE 22050U
  40. #define DAC_VOICES_MAX 4
  41. #endif
  42. #ifdef DAC_HIGH_QUALITY
  43. #define DAC_SAMPLE_RATE 44100U
  44. #define DAC_VOICES_MAX 2
  45. #endif
  46. #ifdef DAC_VERY_HIGH_QUALITY
  47. #define DAC_SAMPLE_RATE 88200U
  48. #define DAC_VOICES_MAX 1
  49. #endif
  50. /**
  51. * Effective bitrate of the DAC. 44.1khz is the standard for most audio - any
  52. * lower will sacrifice perceptible audio quality. Any higher will limit the
  53. * number of simultaneous voices. In most situations, a tenth (1/10) of the
  54. * sample rate is where notes become unbearable.
  55. */
  56. #ifndef DAC_SAMPLE_RATE
  57. #define DAC_SAMPLE_RATE 44100U
  58. #endif
  59. /**
  60. * The number of voices (in polyphony) that are supported. If too high a value
  61. * is used here, the keyboard will freeze and glitch-out when that many voices
  62. * are being played.
  63. */
  64. #ifndef DAC_VOICES_MAX
  65. #define DAC_VOICES_MAX 2
  66. #endif
  67. /**
  68. * The default value of the DAC when not playing anything. Certain hardware
  69. * setups may require a high (DAC_SAMPLE_MAX) or low (0) value here.
  70. */
  71. #ifndef DAC_OFF_VALUE
  72. #define DAC_OFF_VALUE DAC_SAMPLE_MAX / 2
  73. #endif
  74. uint8_t dac_number_of_voices(void);
  75. float dac_get_frequency(uint8_t index);
  76. uint16_t dac_value_generate(void);
  77. void dac_setup_note(void);