12 tones at once? (an entire octave) is it possible?

Status
Not open for further replies.

Oddball

Active member
I'm working on building a synth, and I need all 12 notes. its not a typical synth where you press a key and that tells the controller to sound that note. its a division setup where all notes are played continuously, and the keys just let the sound through to the speaker. that being said, the dividers don't seem to like anything but pulsed / square waves, and only one frequency per channel, however they respond well to varying the frequency. so what I want to do, at first attempt is be able to pitch bend all 12 notes, and vary the pulse width, more than likely in unison, but possibly not, I also want to leave room for upgrades, more flexibility down the road? Can this be achieved with one chip? or am I going to need multiple controllers? this is my 2nd synth project, and I'm a total noob to coding, so going to learn as I go. Thanks folks!
 
Yes, Teensy 4.0 has PWM pins which can generate 18 independent frequencies!

Code:
// Top Octave Generator

void setup() {
  analogWriteFrequency(2, 4186.01);
  analogWriteFrequency(4, 4434.92);
  analogWriteFrequency(5, 4698.64);
  analogWriteFrequency(6, 4978.03);
  analogWriteFrequency(7, 5274.04);
  analogWriteFrequency(10, 5587.65);
  analogWriteFrequency(11, 5919.91);
  analogWriteFrequency(12, 6271.93);
  analogWriteFrequency(13, 6644.88);
  analogWriteFrequency(14, 7040.00);
  analogWriteFrequency(15, 7458.62);
  analogWriteFrequency(18, 7902.13);
  // can also use 19, 22, 28, 34, 36, 38
  analogWrite(2, 128);
  analogWrite(4, 128);
  analogWrite(5, 128);
  analogWrite(6, 128);
  analogWrite(7, 128);
  analogWrite(10, 128);
  analogWrite(11, 128);
  analogWrite(12, 128);
  analogWrite(13, 128);
  analogWrite(14, 128);
  analogWrite(15, 128);
  analogWrite(18, 128);
  
  // Also generate 6 more frequencies, just to
  // show that more than 12 are possible...
  analogWriteFrequency(19, 1200);
  analogWriteFrequency(22, 1300);
  analogWriteFrequency(28, 1400); // bottom side
  analogWriteFrequency(34, 1500); // bottom side
  analogWriteFrequency(36, 1600); // bottom side
  analogWriteFrequency(38, 1700); // bottom side
  analogWrite(19, 128);
  analogWrite(22, 128);
  analogWrite(28, 128);
  analogWrite(34, 128);
  analogWrite(36, 128);
  analogWrite(38, 128);
}

void loop() {
}


I believe this same question came up about 10 months ago, before we had Teensy 4.0.

https://forum.pjrc.com/threads/55631-Teensy-3-6-as-a-top-octave-generator

I'll post a followup over there too.
 
Of course, if you use the audio library and audio shield, you can synthesize and software mix about 100 waveforms, with control of the waveform shape and features like frequency or phase modulation, envelope shaping, modulation of PWM duty cycle, and so much more.

But if all you want is just 12 square waves at specific frequencies, the PWM pins on Teensy 4.0 can easily give you 12 independent frequencies.
 
!! from the man himself! Thanks Paul! funny Just saw you on tested on YouTube just by chance lol
 
So what other hardware would I need to produce 12 channels of audio? since I only need a pulsed output, can I just amplify the square waves?
 
For what it is worth, as per my own testing, Teensy 4 is fast enough to produce over 400 band-limited (anti-aliased) PolyBLEP square and/or sawtooth waves @44.1kHz (custom code, not using Audio library). It would be much more cost effective (just Teensy and DAC) than generating 12 top-octave squares and adding hardware counters to produce lower octaves.
 
For what it is worth, as per my own testing, Teensy 4 is fast enough to produce over 400 band-limited (anti-aliased) PolyBLEP square and/or sawtooth waves @44.1kHz (custom code, not using Audio library). It would be much more cost effective (just Teensy and DAC) than generating 12 top-octave squares and adding hardware counters to produce lower octaves.

yeah.. I'd say your probably right. but I already have the hardware, I'm just replacing the 12 oscillators with something more controllable, as what i have isn't, but (big but) for my next trick, I think I'm going tot go that route.. this is my first synth project :D
 
Just Cruisin right along! learning as I go! took your code Paul and added a couple variables for pitch bend and duty change, working on a LFO and an envelope generator as well using some low pass DAC's still trying to figure out how to post it on Github as a fork lol
 
Status
Not open for further replies.
Back
Top