Hi folks,
I'd like to update the USB audio for Teensy 4 to handle more than 2 channels (starting with 4 but eventually 8) which it only currently supports, so that I can play 4/8 different channels from my computer and use them as outputs on the Teensy.
It seems that some people have worked on it: https://forum.pjrc.com/threads/60557-48kHz-8i80-USB-Audio
But never got to the end of it.
I've been trying as well, but I'm a bit stuck as I don't really understand what the code does in some places.
Here's what I've done so far:
- Update to the AUDIO_INTERFACE descriptor
usb_desc.c line 1574 (USB 2 480mb), updated bNrChannels to 4 (was 2)
This change allows the Teensyduino interface in Windows to show 4 outputs
Now I'm not sure if anything else needs updating in the descriptor.
- Update to USB audio library
usb_audio.h and usb_audio.cpp:
Updated the size of rx_buffer to double it:
Then I've updated the code to duplicate everywhere possible where right and left are being used.
Example:
However I do not understand enough what happens in some functions e.g copy_to_buffers with the bitwise operations.
Also I am unsure if there are other places in the libraries that will need updating e.g usb.c
Any help would be MUCH appreciated, even just some hints to know if I'm going in the right direction!
I'd be happy to collaborate if you are interested in this update.
Thanks
Ben
I'd like to update the USB audio for Teensy 4 to handle more than 2 channels (starting with 4 but eventually 8) which it only currently supports, so that I can play 4/8 different channels from my computer and use them as outputs on the Teensy.
It seems that some people have worked on it: https://forum.pjrc.com/threads/60557-48kHz-8i80-USB-Audio
But never got to the end of it.
I've been trying as well, but I'm a bit stuck as I don't really understand what the code does in some places.
Here's what I've done so far:
- Update to the AUDIO_INTERFACE descriptor
usb_desc.c line 1574 (USB 2 480mb), updated bNrChannels to 4 (was 2)
This change allows the Teensyduino interface in Windows to show 4 outputs
Now I'm not sure if anything else needs updating in the descriptor.
- Update to USB audio library
usb_audio.h and usb_audio.cpp:
Updated the size of rx_buffer to double it:
Code:
DMAMEM static uint8_t rx_buffer[AUDIO_RX_SIZE] __attribute__ ((aligned(64)));
Example:
Code:
void usb_audio_receive_callback(unsigned int len)
{
unsigned int count, avail;
audio_block_t *left, *right, *three, *four;
const uint32_t *data;
AudioInputUSB::receive_flag = 1;
len >>= 4; // 1 sample = 4 bytes: 2 left, 2 right
data = (const uint32_t *)rx_buffer;
count = AudioInputUSB::incoming_count;
left = AudioInputUSB::incoming_left;
right = AudioInputUSB::incoming_right;
three = AudioInputUSB::incoming_three;
four = AudioInputUSB::incoming_four;
if (left == NULL) {
left = AudioStream::allocate();
if (left == NULL) return;
AudioInputUSB::incoming_left = left;
}
if (right == NULL) {
right = AudioStream::allocate();
if (right == NULL) return;
AudioInputUSB::incoming_right = right;
}
if (three == NULL) {
three = AudioStream::allocate();
if (three == NULL) return;
AudioInputUSB::incoming_three = three;
}
if (four == NULL) {
four = AudioStream::allocate();
if (four == NULL) return;
AudioInputUSB::incoming_four = four;
}
....
}
However I do not understand enough what happens in some functions e.g copy_to_buffers with the bitwise operations.
Also I am unsure if there are other places in the libraries that will need updating e.g usb.c
Any help would be MUCH appreciated, even just some hints to know if I'm going in the right direction!
I'd be happy to collaborate if you are interested in this update.
Thanks
Ben