That8BitMan
Member
[SOLVED] No audio output Teensy 3.2 using either onboard DAC or USB passthrough
Hello,
I'm working on my final project for my music degree (the idea is exploring alternative input methods for interacting with electronic instruments) and I'm putting together a touch screen based synth using the Adafruit STMPE610. I had originally planned on going with a hardware based setup but after fighting with different circuits, I've decided to go with software which I'm much more comfortable with.
The issue I'm having is that I can't seem to get any audio to play through either the onboard DAC or through the digital USB interface that's passed through to the computer. I can see that the program is getting through to where the audio should be played but nothing seems to want to work.
After adding dac1.begin(), the program hangs and only prints out the initial project title. I don't think that function is required but after looking at the source code for the library, I found it so I thought I'd give it a go.
I'm not sure if I'm missing something in my setup function or if I specifically have to output audio in the loop function. I've watched the workshop for the audio library but I can't find much documentation for the library other than the included examples.
Here's a copy of the output to the serial monitor without dac1.begin() with me randomly pressing on the touch screen (code is under):
And the code:
Hello,
I'm working on my final project for my music degree (the idea is exploring alternative input methods for interacting with electronic instruments) and I'm putting together a touch screen based synth using the Adafruit STMPE610. I had originally planned on going with a hardware based setup but after fighting with different circuits, I've decided to go with software which I'm much more comfortable with.
The issue I'm having is that I can't seem to get any audio to play through either the onboard DAC or through the digital USB interface that's passed through to the computer. I can see that the program is getting through to where the audio should be played but nothing seems to want to work.
After adding dac1.begin(), the program hangs and only prints out the initial project title. I don't think that function is required but after looking at the source code for the library, I found it so I thought I'd give it a go.
I'm not sure if I'm missing something in my setup function or if I specifically have to output audio in the loop function. I've watched the workshop for the audio library but I can't find much documentation for the library other than the included examples.
Here's a copy of the output to the serial monitor without dac1.begin() with me randomly pressing on the touch screen (code is under):
Code:
=======================
Touch Synth
<name> - 2017
Music Major Project
=======================
Note on
Touch location (x,y,z) -> 1884 2371 49
Touch location (x,y,z) -> 1896 2365 37
Touch location (x,y,z) -> 1892 2365 34
Touch location (x,y,z) -> 1428 2152 37
Note off
Note on
Touch location (x,y,z) -> 1985 2440 55
Touch location (x,y,z) -> 1987 2420 39
Touch location (x,y,z) -> 2010 2381 36
Touch location (x,y,z) -> 2023 2327 34
Touch location (x,y,z) -> 2277 2552 34
Touch location (x,y,z) -> 2074 2648 40
Note off
Note on
Touch location (x,y,z) -> 2006 2575 35
Touch location (x,y,z) -> 2024 2568 35
Note off
Note on
Touch location (x,y,z) -> 1992 2522 34
Touch location (x,y,z) -> 2005 2525 31
Touch location (x,y,z) -> 2004 2523 31
Touch location (x,y,z) -> 2007 2514 33
Note off
Note on
Touch location (x,y,z) -> 2047 2409 36
Touch location (x,y,z) -> 2036 2410 32
Touch location (x,y,z) -> 2039 2405 31
Touch location (x,y,z) -> 2066 2399 37
Note off
Note on
Touch location (x,y,z) -> 2058 2367 36
Touch location (x,y,z) -> 2062 2372 34
Note off
Note on
Touch location (x,y,z) -> 2013 2398 34
Touch location (x,y,z) -> 2029 2399 32
Note off
And the code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
#include "Adafruit_STMPE610.h"
// ===== Audio GUI Tool code =====
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=97,100
AudioSynthWaveform waveform2; //xy=97,137
AudioMixer4 mixer1; //xy=349,119
AudioEffectEnvelope envelope1; //xy=514,104
AudioMixer4 mixer2; //xy=676,123
AudioOutputAnalog dac1; //xy=841,110
AudioConnection patchCord1(waveform1, 0, mixer1, 0);
AudioConnection patchCord2(waveform2, 0, mixer1, 1);
AudioConnection patchCord3(mixer1, envelope1);
AudioConnection patchCord4(envelope1, 0, mixer2, 0);
AudioConnection patchCord5(mixer2, 0, dac1, 0);
// GUItool: end automatically generated code
// ===== Pinout setup =====
const byte PWR_LED = 13;
const byte GATE_OUT = 6;
const byte SPI_SCK = 14;
const byte SPI_MOSI = 11;
const byte SPI_MISO = 12;
const byte STMPE_CS = 15; // Touch Screen Controller Chip Select
const byte aPot = 16;
const byte rPot = 17;
// ===== Touch Screen Object Declaration =====
// SDI to MOSI, SDO to MISO, and SCL to SPI CLOCK
// Tie MODE to 3.3V and POWER CYCLE the STMPE610 (there is no reset pin)
Adafruit_STMPE610 touch = Adafruit_STMPE610(STMPE_CS, SPI_MOSI, SPI_MISO, SPI_SCK);
// ===== Function Declarations =====
void error(int);
// ===== Global variables =====
int gTouchOn = 0;
int gNoteOn = 0;
void setup() {
Serial.begin(9600); // Setup serial
Serial.println("======================="); // ============================
Serial.println("Touch Synth"); //
Serial.println("Callum Blackmore - 2017"); // Print faux splash screen to
Serial.println("Music Major Project"); // serial output
Serial.println("======================="); //
//Serial.flush(); // ============================
pinMode(PWR_LED, OUTPUT); //Setup power LED
digitalWrite(PWR_LED, HIGH);
if (! touch.begin()) {
Serial.println("STMPE not found!");
error(1000);
}
AudioMemory(50);
//dac1.begin(); // <--- Code will hang here if uncommented
dac1.analogReference(INTERNAL);
waveform1.begin(WAVEFORM_SINE);
waveform2.begin(WAVEFORM_TRIANGLE);
mixer1.gain(0, 0.5);
mixer1.gain(1, 0.5);
mixer2.gain(0, 0.75);
envelope1.delay(0);
envelope1.attack(100);
envelope1.hold(0);
envelope1.decay(15);
envelope1.sustain(0.7);
envelope1.release(200);
}
void loop() {
// put your main code here, to run repeatedly:
uint16_t analogVal; // temp value for analog reads
uint16_t x, y; // Touch coordinates
uint8_t z; // ''
analogVal = analogRead(aPot); // =====
//Serial.print(analogVal); Serial.print(' ');
envelope1.attack(analogVal/10); // Read pots and update attack and release values
analogVal = analogRead(rPot); //
//Serial.print(analogVal); Serial.println(' ');
envelope1.release(analogVal/10); // =====
if(touch.touched())
{
gTouchOn = 1;
while (! touch.bufferEmpty())
{
touch.readData(&x, &y, &z);
waveform1.frequency((y*2)+100);
waveform2.frequency((y*2)+100);
Serial.print("Touch location (x,y,z) -> ");
Serial.print(x); Serial.print(' ');
Serial.print(y); Serial.print(' ');
Serial.print(z); Serial.println(' ');
}
touch.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
if(gNoteOn == 0)
{
Serial.print("Note on"); Serial.println(' ');
gNoteOn = 1;
envelope1.noteOn();
}
}
else if(!touch.touched() && gNoteOn == 1)
{
Serial.print("Note off"); Serial.println(' ');
envelope1.noteOff();
gNoteOn = 0;
gTouchOn = 0;
}
}
void error(int len){
while(1) {
digitalWrite(PWR_LED, HIGH);
delay(len);
digitalWrite(PWR_LED, LOW);
delay(len);
}
}
Last edited: