Generating a precise note out of tones with the Audio Shield

Status
Not open for further replies.
Hello,

For a small project I am trying to generate a musical note composed of several tones. I use the standard sin generation objects and a mixer. For the moment I just want to have them all the same amplitude.
My problem is that the tones are sub Hz precision (16.35Hz , .. etc. ). Does the waveform object support such precision(float declarations)? Is there a "correct way" to implement it with the audio shield libraries?

Thanks a lot for any direction.
 
AFAIK, float frequencies are supported. As a simple start, you could use the conversion formula for midi notes (0 - 127, 1 per halftone, 60 is middle C) as follows:

float f = 440 * exp2f((n-69.0f)/12.0f)

Since n, 69 and 12 are basically integers, some forced type conversion is necessary to obtain a precise float division result. With n=12, you obtain midi note C1 which corresponds to the 16.35... Hz which you cited.
 
Thanks a lot for the information.
Basically my task is simpler as I get 12 tones with their frequency as an input and I need only to generate them and mix to output a single note. My worry was that all the discussions here were revolving around int values of frequency and the waveform object in the web interface does not specify the type of the input values... So before digging the source code I came here.
Thanks again.
 
The answer is yes, the waveform object supports sub-audible tones.

Checked just now, with this code.

Code:
#include <Audio.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=255,168
AudioOutputAnalog        dac1;           //xy=411,190
AudioConnection          patchCord1(waveform1, dac1);
// GUItool: end automatically generated code

void setup() {
  AudioMemory(15);
  waveform1.begin(WAVEFORM_SINE);
  waveform1.frequency(16.35);
  waveform1.amplitude(0.95);
}

void loop() {
}

Here's what my frequency counter measures when connected to the DAC pin.

freq.JPG
 
Great! Thanks. I had used a scope on the audio shield audio connector but was not sure.
This goes to the DAC of the Teency (I use 3.5), I assume the audio shield (SGTL5000) would also output correctly the the 16.35Hz on its connector?
 
Yes, you'll get the same output signal. The frequency depends on the synthesis in software, which ultimately is tied to Teensy's clock, which is derived from the 16 MHz crystal.

However, if using the headphone output, remember that it's a DC offset "virtual ground". The DAC also has DC offset, but no special VGND like the audio shield.

If you use the line out, remember yhe audio shield has 2.2 uF capacitors in series, as you can see in its schematic. Make sure whatever you're driving has a high enough input impedance that this series capacitor doesn't form a high-pass filter. Usually this isn't an issue until you get to even lower frequencies, but the high-pass effect does depend on both the capacitor and the input impedance of whatever receives the signal.
 
I use the headphone output, that is meant to be used with headphones in a medical teaching lab in our university. For the moment just evaluating the possible solutions. All the hardware in Teensy 3.2 and the Audio Adaptor Board by pjrc :), the compilation is done with Teensyduino. I use 12 x waveform generators plus 4 mixers (12x wave =>3x mix => mix => i2s1) with the output to the i2s1 object. So based on the comments I assume it shall work.
Thanks again for the comments, now I need to interface it to my Linux through the serial/usb port, but that is another story.
 
Status
Not open for further replies.
Back
Top