Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB audio not supported #34

Open
hriday-mehta opened this issue Mar 1, 2021 · 11 comments
Open

USB audio not supported #34

hriday-mehta opened this issue Mar 1, 2021 · 11 comments
Assignees

Comments

@hriday-mehta
Copy link

Currently USB audio in/out is not supported by tympan. Any idea on when will it be supported?

@chipaudette
Copy link
Member

chipaudette commented Mar 1, 2021

Hi!

USB audio could be supported as long as you always use a 44kHz sample rate with 128 points per audio block. This inflexibility is due to the underlying Teensy code for USB-based audio. Re-engineering the USB code is beyond the scope of what we can do. But, if you can live with 44 kHz / 128 points, it can be made to work reasonably easily.

Would 44 kHz / 128 points meet your needs?

Chip

@chipaudette
Copy link
Member

Here is an example sending audio from the Tympan via USB to the PC: FreqDomainDemo_liveUSB_BLE. This the sketch that I used for this video demonstrating voice-shifting / USB audio.

Note that it uses the USB audio blocks from the Teensy library and then uses Tympan blocks to convert back and forth between the Teensy audio formant and the Tympan audio formant ("_F32").

As of the current date (June 10, 2021), this example sketch requires that you use the "develop" branch of the Tympan library. And, again as of the current date (June 10, 2021), the develop branch requires that you update your Teensyduino to a beta version, which you get from the Teensy forum here.

@chipaudette
Copy link
Member

I would like to wrap the Teensy's USB audio class in a Tympan "_F32" wrapper. I did this before, but it would cause compiler warnings if you didn't set your Arduino IDEA to have the "USB Type" include audio. Since most people didn't use the USB audio, this was an annoying warning, so I pulled the _F32 wrapped USB audio class out of the Tympan Library

I think that there is a way for our code to listen compiler flags to avoid these warning messages so that we know if USB Audio has been set in the Arduino IDE. If I can find out how to do that, we can put the _F32 USB audio class back in our library.

It's on the To-do list, for sure.

@nithinr07
Copy link

nithinr07 commented Jun 21, 2021

Hi,

I am trying to add an AudioOutputUSB block to the single-channel WDRC code. However, this code can't really run well on the Rev D with the 44.1kHz and 128 block size setting, so I was wondering if there is any way to send the audio through USB at lower sampling rates.

Thanks,
Nithin

@chipaudette
Copy link
Member

The USB audio functionality is the exactly the same code as the Teensy Audio Library USB audio code. That code is limited to 44.1kHz and 128-sampke block size. Sorry.

Does the FreqDomainDemo example that I linked above work ok? Is your problem occur only when you use the USB audio with the WDRC?

@nithinr07
Copy link

Yes, as long as the sampling rate is 44.1KHz and the audio block size is 128, it works, but unfortunately, the 8 band WDRC code can't support this on the Rev D I believe.

@chipaudette
Copy link
Member

chipaudette commented Jun 21, 2021

You are correct. the 8-band WDRC consumes too much CPU on the RevD to be run at 44 kHz. If you want the USB audio, you will have to use fewer bands.

It is possible that you could run the Tympan at 22.050 kHz / 64-sample blocks but you tell the USB audio code that you're running at 44.1k / 128. You would then have to write some custom code that you would insert just before your audio reaches the USB Audio class...your custom code would upsample your 22k/64 audio blocks to the 44k/128 rate required by the USB Audio. It seems to me like this should be possible, but I have never tried it. Therefore, there is no example code for you to follow. It would be a very impressive hack, though!

Assuming that you do not want to attempt such a hack, there is a group in Montreal that is looking to dig deep into the Teensy USB Audio code (and, therefore, the Tympan USB Audio code). They are trying to extend the code to enable the Tympan to send USB Audio at different sample rates. They might even be considering allowing it to send more than just two channels of audio.
That would be quite an enhancement! If they do it, I believe they are planning on working on it in July - September.

@nithinr07
Copy link

Also, just to point out, I noticed that there were distinct "clicks" in the USB output when the sampling rate was 44100 Hz. However, this problem was solved when I changed the sampling rate to 44117 Hz.

@chipaudette
Copy link
Member

Yes, the requirement for 44117 is part of the limitations (and odd behaviors) that come with the Teensy audio library.

Sorry.

@nithinr07
Copy link

Hello again!

So, I managed to make the Tympan run at 24,000 Hz / 128 sample block size by tweaking the Teensy library (the USB descriptors), but I wasn't able to lower the block size. I noticed that the WDRC code performs best at lower block sizes, so I was wondering if you could provide me with any leads regarding this.

Nithin

@chipaudette
Copy link
Member

chipaudette commented Jun 28, 2021

Wow! Congratulations on gettng the lower sample rate to work over USB! Very impressive!

As for shorter block sizes, the WDRC is actually more computationally efficient (ie, less CPU consumed) for the larger block sizes like 128. The only reason to go to shorter block sizes is if you care about latency.

Latency is the the delay that occurs between sound hitting the microphone and processed sound coming out of the earphone (see this blog post of mine). If you care to have a short latency, you would want to reduce the block size.

Do you care about latency?

  • If you do NOT care about latency, than your 128-point block size should be great!
  • If you do care about latnecy, then you should look into changing the Teensy header file AudioStream.h that is on your computer in the Arduino's installation directory. On my computer, it is here:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3

Change AUDIO_BLOCK_SIZE from 128 to something smaller. Change your Tympan code to match this new value. Try to compile and run. Perhaps that will give you shorter blocks over USB?

Again, this is only relevant if you want shorter latency. Since your goal is to send audio via USB to a computer (or recording?), I might suggest to you that latency is not relevant and that staying with 128 points is maybe satisfactory?

Chip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants