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.

120 lines
3.2KB

  1. // Copyright 2014 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. #include "warps/cv_scaler.h"
  25. #include "warps/drivers/codec.h"
  26. #include "warps/drivers/debug_pin.h"
  27. #include "warps/drivers/debug_port.h"
  28. #include "warps/drivers/system.h"
  29. #include "warps/drivers/version.h"
  30. #include "warps/dsp/modulator.h"
  31. #include "warps/settings.h"
  32. #include "warps/ui.h"
  33. // #define PROFILE_INTERRUPT 1
  34. using namespace warps;
  35. using namespace stmlib;
  36. Codec codec;
  37. CvScaler cv_scaler;
  38. DebugPort debug_port;
  39. Modulator modulator;
  40. Settings settings;
  41. Ui ui;
  42. int __errno;
  43. // Default interrupt handlers.
  44. extern "C" {
  45. void NMI_Handler() { }
  46. void HardFault_Handler() { while (1); }
  47. void MemManage_Handler() { while (1); }
  48. void BusFault_Handler() { while (1); }
  49. void UsageFault_Handler() { while (1); }
  50. void SVC_Handler() { }
  51. void DebugMon_Handler() { }
  52. void PendSV_Handler() { }
  53. }
  54. void FillBuffer(Codec::Frame* input, Codec::Frame* output, size_t n) {
  55. #ifdef PROFILE_INTERRUPT
  56. TIC
  57. #endif // PROFILE_INTERRUPT
  58. cv_scaler.DetectAudioNormalization(input, n); // 0.8% CPU
  59. cv_scaler.Read(modulator.mutable_parameters());
  60. modulator.Process((ShortFrame*)input, (ShortFrame*)output, n);
  61. ui.Poll();
  62. if (settings.freshly_baked()) {
  63. if (debug_port.readable()) {
  64. uint8_t command = debug_port.ImmediateRead();
  65. uint8_t response = ui.HandleFactoryTestingRequest(command);
  66. debug_port.Overwrite(response);
  67. }
  68. }
  69. #ifdef PROFILE_INTERRUPT
  70. TOC
  71. #endif // PROFILE_INTERRUPT
  72. }
  73. void Init() {
  74. System sys;
  75. Version version;
  76. sys.Init(true);
  77. version.Init();
  78. // Init modulator.
  79. modulator.Init(96000.0f);
  80. settings.Init();
  81. cv_scaler.Init(settings.mutable_calibration_data());
  82. ui.Init(&settings, &cv_scaler, &modulator);
  83. if (!codec.Init(!version.revised(), 96000)) {
  84. ui.Panic();
  85. }
  86. if (!codec.Start(60, &FillBuffer)) {
  87. ui.Panic();
  88. }
  89. codec.set_line_input_gain(24); // Max input level: 16Vpp.
  90. if (settings.freshly_baked()) {
  91. #ifdef PROFILE_INTERRUPT
  92. DebugPin::Init();
  93. #else
  94. debug_port.Init();
  95. #endif // PROFILE_INTERRUPT
  96. }
  97. }
  98. int main(void) {
  99. Init();
  100. while (1) {
  101. ui.DoEvents();
  102. }
  103. }