Oscillator.cpp 731 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "Oscillator.h"
  2. #include <cmath>
  3. namespace Audio
  4. {
  5. void SineOscillator::update()
  6. {
  7. for (size_t i = 0; i < BUFFER_SIZE; i++)
  8. {
  9. m_phase += m_phase_stride;
  10. if (m_phase >= 1.0f)
  11. m_phase -= 1.0f;
  12. buffer[i] = sinf(2.0f * PI_A * m_phase);
  13. }
  14. m_phase_stride = m_frequency * sample_duration;
  15. };
  16. void SquareOscillator::update()
  17. {
  18. for (size_t i = 0; i < BUFFER_SIZE; i++)
  19. {
  20. m_phase += m_phase_stride;
  21. if (m_phase >= 1.0f)
  22. m_phase -= 1.0f;
  23. buffer[i] = m_phase;
  24. m_phase_stride = m_frequency * sample_duration;
  25. }
  26. }
  27. };