Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

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

  1. #1
    Junior Member
    Join Date
    Feb 2020
    Posts
    4

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

    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!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    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...tave-generator

    I'll post a followup over there too.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473
    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.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,473

  5. #5
    Junior Member
    Join Date
    Feb 2020
    Posts
    4
    !! from the man himself! Thanks Paul! funny Just saw you on tested on YouTube just by chance lol

  6. #6
    Junior Member
    Join Date
    Feb 2020
    Posts
    4
    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?

  7. #7
    Junior Member
    Join Date
    Feb 2020
    Posts
    4
    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.

  8. #8
    Junior Member
    Join Date
    Feb 2020
    Posts
    4
    Quote Originally Posted by tomas View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •