# HG changeset patch # User Rachel Bittner # Date 1389521528 18000 # Node ID 5c69d40a0e30e29580c48dae8cab45ff59b816e6 # Parent ccd3c927638be6c68aaa396fce24b6974d073447 Added alternate waveforms for sonification. Created parameter m_wavetype in ContinuousSynth. diff -r ccd3c927638b -r 5c69d40a0e30 audioio/AudioGenerator.cpp --- a/audioio/AudioGenerator.cpp Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/AudioGenerator.cpp Sun Jan 12 05:12:08 2014 -0500 @@ -48,6 +48,7 @@ AudioGenerator::AudioGenerator() : m_sourceSampleRate(0), m_targetChannelCount(1), + m_waveType(0), m_soloing(false) { initialiseSampleDir(); @@ -226,7 +227,8 @@ ContinuousSynth *synth = new ContinuousSynth(m_targetChannelCount, m_sourceSampleRate, - m_processingBlockSize); + m_processingBlockSize, + m_waveType); std::cerr << "AudioGenerator::makeSynthFor(" << model << "): created synth" << std::endl; diff -r ccd3c927638b -r 5c69d40a0e30 audioio/AudioGenerator.h --- a/audioio/AudioGenerator.h Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/AudioGenerator.h Sun Jan 12 05:12:08 2014 -0500 @@ -99,6 +99,7 @@ protected: size_t m_sourceSampleRate; size_t m_targetChannelCount; + size_t m_waveType; bool m_soloing; std::set m_soloModelSet; diff -r ccd3c927638b -r 5c69d40a0e30 audioio/ContinuousSynth.cpp --- a/audioio/ContinuousSynth.cpp Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/ContinuousSynth.cpp Sun Jan 12 05:12:08 2014 -0500 @@ -19,12 +19,13 @@ #include -ContinuousSynth::ContinuousSynth(int channels, int sampleRate, int blockSize) : +ContinuousSynth::ContinuousSynth(int channels, int sampleRate, int blockSize, int waveType) : m_channels(channels), m_sampleRate(sampleRate), m_blockSize(blockSize), m_prevF0(-1.f), - m_phase(0.0) + m_phase(0.0), + m_wavetype(waveType) // 0: 3 sinusoids, 1: 1 sinusoid, 2: sawtooth, 3: square { } @@ -76,16 +77,55 @@ double phasor = (fHere * 2 * M_PI) / m_sampleRate; - m_phase = m_phase + phasor; + m_phase = m_phase + phasor; int harmonics = (m_sampleRate / 4) / fHere - 1; if (harmonics < 1) harmonics = 1; + switch (m_wavetype) { + case 1: + harmonics = 1; + break; + case 2: + break; + case 3: + break; + default: + harmonics = 3; + break; + } + + for (int h = 0; h < harmonics; ++h) { - - double hn = h*2 + 1; - double hp = m_phase * hn; - double v = sin(hp) / hn; + + double v = 0; + double hn = 0; + double hp = 0; + + switch (m_wavetype) { + case 1: // single sinusoid + v = sin(m_phase); + break; + case 2: // sawtooth + if (h != 0) { + hn = h + 1; + hp = m_phase * hn; + v = -(1.0 / M_PI) * sin(hp) / hn; + } else { + v = 0.5; + } + break; + case 3: // square + hn = h*2 + 1; + hp = m_phase * hn; + v = sin(hp) / hn; + break; + default: // 3 sinusoids + hn = h*2 + 1; + hp = m_phase * hn; + v = sin(hp) / hn; + break; + } if (!wasOn && i < fadeLength) { // fade in diff -r ccd3c927638b -r 5c69d40a0e30 audioio/ContinuousSynth.h --- a/audioio/ContinuousSynth.h Thu Jan 09 21:31:54 2014 +0000 +++ b/audioio/ContinuousSynth.h Sun Jan 12 05:12:08 2014 -0500 @@ -24,7 +24,7 @@ class ContinuousSynth { public: - ContinuousSynth(int channels, int sampleRate, int blockSize); + ContinuousSynth(int channels, int sampleRate, int blockSize, int waveType); ~ContinuousSynth(); void setChannelCount(int channels); @@ -56,6 +56,8 @@ double m_prevF0; double m_phase; + + int m_wavetype; }; #endif