Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Problem changing AUDIO_BLOCK_SAMPLES

  1. #1
    Member
    Join Date
    Feb 2020
    Location
    Dublin, Ireland
    Posts
    43

    Problem changing AUDIO_BLOCK_SAMPLES

    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.

    Click image for larger version. 

Name:	test.jpg 
Views:	17 
Size:	18.5 KB 
ID:	20656

    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:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.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);
    
    
    void setup() {
    AudioMemory(20);
    sine1.frequency(220);
    }
    
    
    void loop() {
      
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	test.jpg 
Views:	10 
Size:	18.7 KB 
ID:	20655  

  2. #2
    Member
    Join Date
    Feb 2020
    Location
    Dublin, Ireland
    Posts
    43
    Hi,
    Could the fixing of USB Audio for Teensy 4.x have introduced a problem when
    AUDIO_BLOCK_SAMPLES is changed?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,757
    Quote Originally Posted by AlanK View Post
    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.

  4. #4
    Member
    Join Date
    Feb 2020
    Location
    Dublin, Ireland
    Posts
    43
    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...causes-problem
    Last edited by AlanK; 06-20-2020 at 07:39 AM.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,757
    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.

    Click image for larger version. 

Name:	file.png 
Views:	6 
Size:	32.6 KB 
ID:	20660

    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() {
    }

  6. #6
    Member
    Join Date
    Feb 2020
    Location
    Dublin, Ireland
    Posts
    43
    Hi Paul,

    Thanks for clarifying that,

    All the best,

    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •