Is it possible to read two different notefreq items at the same time?

Status
Not open for further replies.

meech

Member
I am having an issue with reading the frequency of two different inputs in my code.

(live guitar input into adc1, recorded guitar track input from the usb)

When I initiate my code, the notefreq2 item will read my guitars note with great accuracy. However, when I play the guitar track from my computer through USB the teensy3.2 won't read it, and stops reading my guitar as well :(.
It doesn't matter whether I have played the guitar before the usb input or not, once the usb recieves a signal my code dies.

If i comment out one of the notefreq.begin(.15)'s then the other analyzer works perfectly how I want it to work. This goes for the usb notefreq analyzer, and the guitar notefreq analyzer.
It is only when both notefreq variables have been "Begun" that I encounter issues.

If anybody could help me with reading both frequencies at the same time it would be very appreciated. :)


Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputUSB            usb1;           //xy=116,100
AudioInputAnalog         adc1;           //xy=239,220
AudioMixer4              mixer1;         //xy=267,115
AudioMixer4              mixer2;         //xy=414,210
AudioAnalyzeNoteFrequency notefreq2;      //xy=416,265
AudioAnalyzeNoteFrequency notefreq1;      //xy=419,64
AudioOutputAnalog        dac1;           //xy=585,210
AudioConnection          patchCord1(usb1, 0, mixer1, 0);
AudioConnection          patchCord2(usb1, 1, mixer1, 1);
AudioConnection          patchCord3(adc1, notefreq2);
AudioConnection          patchCord4(adc1, 0, mixer2, 1);
AudioConnection          patchCord5(mixer1, notefreq1);
AudioConnection          patchCord6(mixer1, 0, mixer2, 0);
AudioConnection          patchCord7(mixer2, dac1);
// GUItool: end automatically generated code


void setup() {
  // put your setup code here, to run once:
  AudioMemory(30);
  notefreq1.begin(.15);//---If one of these two are commented out
  notefreq2.begin(.15);//---The other one works fine
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (notefreq1.available()) {
      float note = notefreq1.read();
      float prob = notefreq1.probability();
      Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
    }
  if (notefreq2.available()) {
      float note = notefreq2.read();
      float prob = notefreq2.probability();
      Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
  }
}

(this is the diagram of how everything is wired up)
Teensy3.2 wiring.png
 
The YIN algorithm used by notefreq consumes nearly all the CPU time on a Teensy 3.2. There's no way you can run 2 of them on Teensy 3.2.

This might be possible on Teensy 3.6, maybe?
 
Hmm, I do have a second teensy 3.2 that i got for if my first one failed... Is it possible to send the notefreq data from one teensy to another?
Sorry for the noob questions but im pretty new to working with microprocessors :)
 
Almost everything is technically possible with microprocessors if you have adequate programming skills. But since you are new to that, it‘s simply cheaper to buy a teensy 3.6 instead of investing many hours (even at minimum wage) into learning how to get two Teensys working together.
 
Is it possible to send the notefreq data from one teensy to another?

Yes, definitely possible. There are many possible ways, but Serial1 is usually the simplest if you just need to send data in 1 direction. Just connect TX1 (pin 1) from the transmitting board to RX1 (pin 0) on the receiving board, and of course their grounds need to be connected. Use Serial1.println() to transmit. On the receiving side, use Serial1.available() to tell when the data arrives, and Serial1.read() to read each byte. A little programming is needed to combine the bytes back to whatever number you transmitted.
 
Status
Not open for further replies.
Back
Top