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.

73 lines
2.1KB

  1. // Copyright 2012 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  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. #include <cmath>
  16. #include <cstdio>
  17. #include <cstring>
  18. #include <cstdlib>
  19. #include "braids/macro_oscillator.h"
  20. #include "braids/quantizer.h"
  21. #include "stmlib/test/wav_writer.h"
  22. #include "stmlib/utils/dsp.h"
  23. using namespace braids;
  24. using namespace stmlib;
  25. const uint32_t kSampleRate = 96000;
  26. const uint16_t kAudioBlockSize = 24;
  27. void TestAudioRendering() {
  28. MacroOscillator osc;
  29. WavWriter wav_writer(1, kSampleRate, 5);
  30. wav_writer.Open("oscillator.wav");
  31. osc.Init();
  32. osc.set_shape(MACRO_OSC_SHAPE_VOWEL_FOF);
  33. for (uint32_t i = 0; i < kSampleRate * 5 / kAudioBlockSize; ++i) {
  34. /*if ((i % 2000) == 0) {
  35. osc.Strike();
  36. }*/
  37. int16_t buffer[kAudioBlockSize];
  38. uint8_t sync_buffer[kAudioBlockSize];
  39. uint16_t tri = (i * 3);
  40. uint16_t tri2 = (i * 11);
  41. uint16_t ramp = i * 150;
  42. tri = tri > 32767 ? 65535 - tri : tri;
  43. tri2 = tri2 > 32767 ? 65535 - tri2 : tri2;
  44. osc.set_parameters(tri, 0);
  45. memset(sync_buffer, 0, sizeof(sync_buffer));
  46. //sync_buffer[0] = (i % 32) == 0 ? 1 : 0;
  47. osc.set_pitch((48 << 7));
  48. osc.Render(sync_buffer, buffer, kAudioBlockSize);
  49. wav_writer.WriteFrames(buffer, kAudioBlockSize);
  50. }
  51. }
  52. void TestQuantizer() {
  53. Quantizer q;
  54. q.Init();
  55. for (int16_t i = 0; i < 16384; ++i) {
  56. int32_t pitch = i;
  57. printf("%d quantized to %d\n", i, q.Process(i, 60 << 7));
  58. }
  59. }
  60. int main(void) {
  61. // TestQuantizer();
  62. TestAudioRendering();
  63. }