Problem changing AUDIO_BLOCK_SAMPLES

Status
Not open for further replies.

AlanK

Well-known member
Hi,

I had reduced AUDIO_BLOCK_SAMPLES to 32 previously to reduce latency in an audio project and it worked perfectly (and significantly reduced the latency). That was using a Teensy 4.0 with audio shield using the latest version of Teensyduino available in September 2019. There were no problems. I've now done the same thing using version 1.52 (Arduino with a Teensy 4.1 with USB audio output and it is not working. This shows what is happening to a 220 Hz sine wave - the frequency is correct.

test.jpg

I don't have access to the other hardware to test it. The problem is happening with all audio source types. You can test it with the simplest code:
Code:
[FONT=Verdana]#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>[/FONT][FONT=Verdana]
[/FONT]
[FONT=Verdana]AudioSynthWaveformSine   sine1;          //xy=235,197
AudioOutputI2S           i2s1;           //xy=405,161
AudioOutputUSB           usb1;           //xy=427,231
AudioConnection          patchCord1(sine1, 0, i2s1, 1);
AudioConnection          patchCord2(sine1, 0, i2s1, 0);
AudioConnection          patchCord3(sine1, 0, usb1, 0);
AudioConnection          patchCord4(sine1, 0, usb1, 1);

[/FONT]
[FONT=Verdana]void setup() {
AudioMemory(20);
sine1.frequency(220);
}

[/FONT]
[FONT=Verdana]void loop() {
  [/FONT]
[FONT=Verdana]}[/FONT]
 

Attachments

  • test.jpg
    test.jpg
    18.7 KB · Views: 68
Hi,
Could the fixing of USB Audio for Teensy 4.x have introduced a problem when
AUDIO_BLOCK_SAMPLES is changed?
 
That was using a Teensy 4.0 with audio shield using the latest version of Teensyduino available in September 2019.

I don't see how you could have run this program last year, since AudioOutputUSB has only existed for the last few months.
 
Hi Paul,
I didn't - it was working with AUDIO_BLOCK_SAMPLES set to 32 on a 4.0 using an audio shield for output. I've been working on other aspects of my software, and have moved to a 4.1 - currently the only audio output I have is USB audio. I've just changed AUDIO_BLOCK_SAMPLES again from 128 to 32 and encountered this problem.

This seems to be the same problem - raised in November:
https://forum.pjrc.com/threads/58322-Changing-AUDIO_BLOCK_SAMPLES-causes-problem
 
Last edited:
Sadly, USB audio does not work with smaller block sizes. Other parts of the audio library also depend on 128 sample block size and do not work properly when it's changed to 32.

But I2S does work, and so does do the waveform synths. I'm pretty sure the code you tried on Teensy 4.0 last year using only I2S output will still work properly.

I tried your USB+I2S example with block size 32 and the audio shield. The proper waveform does appear on the output. The problem is only that USB doesn't support different block sizes. It must be 128 for USB to work.

file.png

Code:
#include <Audio.h>

AudioSynthWaveformSine   sine1;          //xy=235,197
AudioOutputI2S           i2s1;           //xy=405,161
AudioOutputUSB           usb1;           //xy=427,231
AudioConnection          patchCord1(sine1, 0, i2s1, 1);
AudioConnection          patchCord2(sine1, 0, i2s1, 0);
AudioConnection          patchCord3(sine1, 0, usb1, 0);
AudioConnection          patchCord4(sine1, 0, usb1, 1);
AudioControlSGTL5000     sgtl5000_1;

void setup() {
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.75);
  AudioMemory(20);
  sine1.frequency(220);
}

void loop() {
}
 
Status
Not open for further replies.
Back
Top