T4 Audio library Synth that tracks external input frequency

dslocum

Well-known member
Hi,

I'm working on a small synth using a T4.0 w/Audio library. I want the "oscillators" to track the pitch / frequency of a simple (sine / square) external audio waveform. I already have some good success with a prototype, but my problem is that the audio library and my external input reading causes audible glitches.

I've tried:

1. polling the audio input pin, looking for the rising edges and measuring micros() differences. This fails because the input signal will never hit the start / stop of the micros() time consistently.
2. Using an interrupt
Code:
  // setup signal input pin ISR
  pinMode(signalInPin, INPUT_PULLUP);  // MUST use this with IOC interrupts!
  // https://forum.pjrc.com/threads/66146-T4-0-ISR-Rising-Edge-Voltage-Trigger-Level?p=269780&viewfull=1#post269780 
  attachInterrupt(digitalPinToInterrupt(signalInPin), Input_ISR, RISING);
This is better in some ways, but it seems to frequently miss my external interrupts.
I found the following, but I'm not sure where to find a mapping of pins to ports in order to try it.
https://www.pjrc.com/fast-pulse-counting-with-interrupts-and-why-nested-priority-really-helps/

I've thought about using one of the Teensy's counters like in the Frequency counter examples, but I can't seem to wrap my head around how this will work with so much that is going on in the audio library.

Any suggestions or pointers are appreciated. Thanks

Doug
 

I think I looked at that library as well, but I'll take another look. I can read a PIC data sheet, but these chips are much more than my current pay grade! :-/

Any "top of your head" thoughts on how that might (or not) interfere with the audio library oscillators? I'll be running 8 oscillators and a software state variable filter.
 
Looking at the FreqMeasure library. It says I must connect my external input to pin 22. Is that the physical pin 22 (D20 / A6) or pin 24 (D22)? I can't use D20, as that's driving my PT8211 audio DAC. Just want to clarify before I start hacking up my prototype board.
 
OK, I looked at FreqMeasureMulti so I didn't have to use pin 22. I then reworked my PCB to put my external input onto Teensy's pin 22 and reorganized my code.

My application first starts 8 oscillators and a filter, and I can verify those are working fine. FreqMeasureMulti DOES detect the input frequency but in a simple loop, it bobbles wildly around the correct input frequency.

Code:
void loop() {
  int rawfreq = 0;

  if (freq1.available()) {
    rawfreq = freq1.read();
    Serial.println(freq1.countToFrequency( rawfreq ););    
  }
    
  // put our analog and switch reading stuff here
  //   sequence thru ADC front panel reads to save time
  switch (GuiState) {
    case 0: readKeys(); break;
    case 1: setFilterRes(); break;
    case 2: setFilterFreq(); break;
    case 3: setBankBDetune(); break;
    case 4: setBankCrossfade(); break;
  }
  GuiState++;
  if (GuiState > 4)
    GuiState = 0;

}
 
I used the Arduino GUI to install FreqMeasure, then tried to compile the Serial_Output example sketch. Got error: "Unknown chip, please edit me with timer+counter definitions"

I notice that the 1062 chip isn't listed in FreqMeasureCapture.h. Is there a more recent version for the T4.0 ? What else could I look for?

Thanks
 
Which version of Teensyduino is installed? To check, in Arduino click Help > About.

1.56 is the latest.

Edit: oh, I see… uninstall the copy by the library manager. Teensyduino installs a newer copy, but anything you manually install overrides it.
 
I've uninstalled the old GitHub version and reinstalled the most recent Teensyduino so I should have the latest. Now compiles fine, but the numbers from the input are still wild. This is with several oscillators running that were simply started in SETUP.

Code:
300.95
5000000.00
328.95
300.84
328.85
300.81
328.87
300.87
326.96
157.53
300.77
328.79
300.76
5172414.00
328.75

Code:
void loop() {
  int rawfreq = 0;

  if (FreqMeasure.available()) {
    rawfreq = FreqMeasure.read();
    smoothedPitch = FreqMeasure.countToFrequency( rawfreq );
    Serial.println(smoothedPitch);    
 
  }
}
 
I should add that the input is a square wave from an analog VCO and I'm verified that there's nothing funny (ringing, noise, etc) going into the T4 that would cause these counts - at least from a hardware standpoint.
 
Back
Top