Skip to content
NoisyVolt
NoisyVolt

music electronics make code

  • Build
  • Code
  • Play
  • Watch
  • Listen
  • Sound
NoisyVolt

music electronics make code

Audio Test

andy, May 6, 2026May 6, 2026

Testing the hardware, integration and workflow to build a Teensy Synth

Create Folder AudioTest/

Create AudioTest.ino:

// =============================================================================
// AudioTest.ino  —  Teensy 4.0 + Audio Shield hardware test
// =============================================================================
// Outputs a 440Hz sine wave to both audio outputs.
// No extra libraries needed — just the built-in Teensy Audio library.
//
// Compile:
//   arduino-cli compile --fqbn teensy:avr:teensy40 \
//     --build-property "build.usbtype=USB_MIDI_SERIAL" .
//
// Upload:
//   arduino-cli upload --fqbn teensy:avr:teensy40 --port usb:0/140000/0/1 .
//
// Monitor:
//   arduino-cli monitor --port /dev/cu.usbmodemXXXX --config baudrate=115200
// =============================================================================

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

// ── Audio objects ─────────────────────────────────────────────────────────────
AudioSynthWaveform   sine;
AudioOutputI2S       audioOut;
AudioControlSGTL5000 audioShield;

// ── Patch cords ───────────────────────────────────────────────────────────────
AudioConnection cord1(sine, 0, audioOut, 0);  // left
AudioConnection cord2(sine, 0, audioOut, 1);  // right

// ── Config — tweak these to test ─────────────────────────────────────────────
const float FREQUENCY = 440.0f;  // Hz
const float AMPLITUDE = 0.4f;    // 0.0–1.0  (keep below 0.8 to avoid clipping)
const float VOLUME    = 0.6f;    // headphone / line-out level

// =============================================================================
void setup() {
  Serial.begin(115200);
  delay(200);

  AudioMemory(12);

  audioShield.enable();
  audioShield.volume(VOLUME);

  sine.begin(AMPLITUDE, FREQUENCY, WAVEFORM_SINE);

  Serial.println("=== AudioTest ===");
  Serial.printf("Frequency : %.1f Hz\n", FREQUENCY);
  Serial.printf("Amplitude : %.2f\n",    AMPLITUDE);
  Serial.printf("Volume    : %.2f\n",    VOLUME);
  Serial.println("You should hear a 440Hz tone.");
}

// =============================================================================
void loop() {
  // Report CPU + memory usage every 2 seconds
  static elapsedMillis t;
  if (t >= 2000) {
    t = 0;
    Serial.printf("CPU: %.1f%%  Mem: %d blocks\n",
      AudioProcessorUsageMax(),
      AudioMemoryUsageMax());
    AudioProcessorUsageMaxReset();
    AudioMemoryUsageMaxReset();
  }
}

you should hear a steady 440Hz tone and see this in the monitor every 2 seconds:

=== AudioTest ===
Frequency : 440.0 Hz
Amplitude : 0.40
Volume    : 0.60
You should hear a 440Hz tone.
CPU: 2.3%  Mem: 2 blocks
Build Code teensy

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • MIDI Loop Player
  • Sample Player on rPi
  • Display Test
  • Encoder Test
  • Audio Test

Archives

  • May 2026
  • April 2026
  • March 2026
Listen Watch Read Reference
©2026 NoisyVolt | WordPress Theme by SuperbThemes

Powered by
►
Necessary cookies enable essential site features like secure log-ins and consent preference adjustments. They do not store personal data.
None
►
Functional cookies support features like content sharing on social media, collecting feedback, and enabling third-party tools.
None
►
Analytical cookies track visitor interactions, providing insights on metrics like visitor count, bounce rate, and traffic sources.
None
►
Advertisement cookies deliver personalized ads based on your previous visits and analyze the effectiveness of ad campaigns.
None
►
Unclassified cookies are cookies that we are in the process of classifying, together with the providers of individual cookies.
None
Powered by