Visually Debugging Objects from Audio System Design Tool (using AudioAnalyzePrint )

Status
Not open for further replies.

hemmer

Member
Hi,

I have a Teensy 4.0 installed and working (can modify blink test example), but for now no Audio shield. Nevertheless, I would like design a program using the Audio System Design Tool and interrogate objects, such as AudioSynthWaveformModulated in order to understand better how they work and debug issues. I don't have access to an oscilloscope so I was hoping to plot the outputs using the SerialMonitor. I can view general messages printed by Serial.println() etc so the SerialMonitor is in general working I think. However when I try to use AudioAnalyzePrint object to do this, say, for a AudioSynthWaveformModulated I don't get any output. The documentation says "This object doesn't work very well and probably should not be used." and has "blah blah blah" so I'm struggling to work out how to use it. My attempt is below. If this is not recommended, is there another way to effectively get oscilloscope outputs for a given object?

I'm using USB Type "Serial" and viewing "COM5 (Teensy)" port, Arduino 1.8.16. I've picked an arbitrary output device as I didn't think this would matter (but I've tried i2s as well).

The context is: i'm trying to port some Teensy Audio algorithms to another dsp platform and am struggling to understand/build intuition about exactly how the objects work / would like a way to probe parts of the existing algorithms.

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

// GUItool: begin automatically generated code
AudioSynthWaveformModulated waveformMod1;   //xy=420.1999969482422,249.1999969482422
AudioAnalyzePrint        print1;         //xy=629.1999969482422,434.1999969482422
AudioOutputPWM           pwm1;           //xy=770.1999969482422,336.1999969482422
AudioConnection          patchCord1(waveformMod1, print1);
AudioConnection          patchCord2(waveformMod1, pwm1);
// GUItool: end automatically generated code


// the setup routine runs once when you press reset:
void setup() {

  int masterVolume = 1;
  waveformMod1.begin(WAVEFORM_SQUARE);
  waveformMod1.offset(1);
  waveformMod1.amplitude(masterVolume);
  waveformMod1.frequency(10);
  Serial.begin(9600);

  print1.name("debugger");
  Serial.println("Beep #");
}

// the loop routine runs over and over again forever:
void loop() {

  delay(500);               // wait for a second
  print1.trigger();
}

Output:
Code:
Beep #
trigger debugger
trigger debugger
trigger debugger
trigger debugger
trigger debugger
trigger debugger
trigger debugger

Thanks!
 
Code:
class AudioAnalyzePrint : public AudioStream
{
public:
	AudioAnalyzePrint(void) : AudioStream(1, inputQueueArray),
	  myname(NULL), state(0), trigger_edge(0), delay_length(0), print_length(500) {}
	virtual void update(void);
	void name(const char *str) { myname = str; }
	void trigger(void);
	void trigger(float level, int edge);
	void delay(uint32_t num) { delay_length = num; }
	[B]void length(uint32_t num) { print_length = num; [/B]}

I haven't used this, was not aware it existed but it looks useful.
It looks like you need to call the length function to tell it how many samples you wish to print and then call trigger.
 
Thanks for the response! Unfortunately that doesn't seem to help (also see that it is initialiser sets it to 500).

On reflection, an even better solution would be to expose the teensy as a USB Audio device and visualise the data in a scope in VCV Rack (extra context is that the project is to port a teensy Eurorack module to VCV). I've set the USB type to 'Serial + MIDI + Audio' and compiled the following but still no joy.

Question: can I use Teensy Audio objects + USB audio without the audio shield? If so does someone have a working minimal example? The only other reference I can find is this post which has the audio shield. Of course it can be another DAW other than VCV too.

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

// GUItool: begin automatically generated code
AudioSynthNoiseWhite     noise1;         //xy=417.1999969482422,285.1999969482422
AudioOutputI2S           i2s1;           //xy=606.2000122070312,309.20001220703125
AudioOutputUSB           usb1;           //xy=608.1999969482422,262.1999969482422
AudioConnection          patchCord1(noise1, 0, usb1, 0);
AudioConnection          patchCord2(noise1, 0, usb1, 1);
AudioConnection          patchCord3(noise1, 0, i2s1, 0);
AudioConnection          patchCord4(noise1, 0, i2s1, 1);
// GUItool: end automatically generated code

// the setup routine runs once when you press reset:
void setup() {
  noise1.amplitude(1);
  Serial.begin(9600);
  Serial.println("Setup complete");
}

// the loop routine runs over and over again forever:
void loop() {}

teensy_vcv.jpg
 
You can use usb-audio and other audio objects without an audio board.
you only should have a true audio input/output object in the setup.
e.g
AudioOutputI2S i2s1;
even if you do not use audio board or other I2S boards.
Reason is that usb input/output do not trigger the data processing, only ADC, I2S and maybe other true audio input/output objects trigger processing

So, procedure:
use audio tool to construct your processing including usb output object
add a dummy AudioOutputI2S object with no further connection

edit:
you need also allocate Audio memory blocks in setup (see examples is audio library)
 
Amazing that works perfectly!

teensy_vcv2.png


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

// GUItool: begin automatically generated code
AudioSynthNoiseWhite     noise1;         //xy=417.1999969482422,285.1999969482422
AudioOutputI2S           i2s1;           //xy=606.2000122070312,309.20001220703125
AudioOutputUSB           usb1;           //xy=608.1999969482422,262.1999969482422
AudioConnection          patchCord1(noise1, 0, usb1, 0);
AudioConnection          patchCord2(noise1, 0, usb1, 1);
AudioConnection          patchCord3(noise1, 0, i2s1, 0);
AudioConnection          patchCord4(noise1, 0, i2s1, 1);
// GUItool: end automatically generated code



// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
  AudioMemory(8);
    
  noise1.amplitude(1);
  
  Serial.println("Setup complete");
}

// the loop routine runs over and over again forever:
void loop() {}
 
Status
Not open for further replies.
Back
Top