Hi all, I'm new here... I'd like to modify the synth_simple_drum object in order to produce square waves instead of sinus waves... Is it a difficult task? Anybody could give me some suggestions?
thanks a lot!
if(wav_phasor & 0x40000000)
interp = 0x4000;
else
interp = -0x4000;
The audio library works by processing blocks of 128 samples. Details here:
http://www.pjrc.com/teensy/td_libs_AudioNewObjects.html
In theory, all you'd need to do is modify the code to create the waveform you want. Just put the data to the array of 128 numbers and use the transmit function to send it to the rest of the audio system.
Just a "small matter" of programming....![]()
To get squares instead of sines, replace the sine lookup & interpolation with a check of the MSB of the `wav_phasor` member.
Around line 170 of synth_simple_drum.cpp, it might look something like:
Code:if(wav_phasor & 0x40000000) interp = 0x4000; else interp = -0x4000;
Repeat for wav_phasor2, if you desire.
0x4000 is somewhat arbitrary...it might be considerably louder than the sine.
You can also look at how synth_waveform.cpp does squares -- they're similar.
And, of course, the ultimate result will be somewhat trapezoidal - the amplitude envelope will impose a slope on the tops of the waves.