Simple_drum

Status
Not open for further replies.

Sandro

Well-known member
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!
 
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!

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.
 
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.... ;)

Thank you Paul but at the moment... this "small matter" it's super difficult to me... I belive I need to study a bit of C++ programming in order to go on with my experiments ;)
 
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.

Thank you B. but... it's a pity, my knownledge in C++ programming is close to 0 and I cannot apply your suggestion :(
Let's see... maybe in few weeks of study I'll be ready :)
 
Hi B.Jaquot,
in the meanwhile (while I'm studying c++...) I tried to "implant" your code around line 170 of synth_simple_drum.cpp, deleting "some of the code" (I've never done anything like this before!). I'm surprised that the code is so resistant to my "brutal" approach: I caused some damages to the class (it doesn't work perfectly) but I achieved the waveforms I look for (I didn't check with my oscilloscope, but they might be square).... Ok, this is not a good programming methodology:).. Let's see!!
 
Status
Not open for further replies.
Back
Top