I try to use Portenta with USB as an USB Audio device.
There are few files in Arduino LIB, e.g. "USBAudio.h", "PluggableAudioAudio.h" and "USBAudio.cpp".
I copied the files "USBAudio.h" and "USBAudio.cpp" under my project - compile it - and it is compile clean. Great.
I try to use this USBAudio (marked as "experimental" in comments).
I do this in my sketch:
USBAudio audio(true, 44100, 2, 44100, 2);
static uint8_t buf[177];
while (true) {
if (!audio.read(buf, sizeof(buf))) {
memset(buf, 0x1f, sizeof(buf));
}
if (audio.write_ready())
{
memset(buf, 0x1f, sizeof(buf));
audio.write(buf, sizeof(buf));
}
}
What works so far?
I can see the input (microphone) as well as the output (speaker) as an "Mbed Audio" device enumerated. Cool - the USB enumeration works.
What does not work
-
It looks like I can only chose 44.1 KHz in Portenta H7 code. When 48 KHz is tried - I do not see anymore the sample frequency settings in the Windows audio drivers. It looks to me: other than 44.1 KHz fails already on enumeration (guessing due to a different set of USB descriptors needed and Ardunio code is not generating/not sending it for other sample rates properly).
-
no data is transferred: I use tool Audacity to record or play sound. Audacity can crash. Or nothing happens. Tool does not progress. I do not see my values expected as 0x1F1F (constant DC value filled). Instead: nothing. It looks like the audio device on Portenta H7 does not send anything.
-
This "loopback" example does not work. My guess: Portenta H7 does not receive and does not send anything, after USB enumeration was OK.
Another issue:
I thought, this USB Audio comes out on the user USB, the breakout USB-A connector. And I need a second USB cable to connect my USB Audio with host. But not true. It uses also USB-C.
But instead: it uses also the USB-C connection. And it kills my USB-C UART there. So, I lose control to the board, I cannot talk to Portenta H7 via USB-C anymore.
A bit obvious (reconfiguring the USB-C now just and only for USB Audio) - but not nice. I would not be able to live with this drawback. I need my UART available all the time. Instead: put the USB Audio on the breakout board USB-A connector.
Who does have any luck or experience on this topic?
-
How to setup a second, separate USB connection for USB Audio? (not losing USB-C UART, using user USB-A on breakout is file)
-
How to see that this USB Audio is working? At least I want to see my buffers filled with data come in on host (working as an USB Audio Input on host, like a microphone).
I am also a bit confused about the "flow control":
When I see this code, running in endless loop, to read and write USB buffer (with Audio samples) - how does it synchronize with USB? Actually, every 1 ms a sample buffer is ready or due to be sent. But this code seems to run full speed, not in sync with USB Audio device. How can it work?
How could I be notified if a new sample buffer is available or ready to queue again?
(code looks really "experimental").
Who could help to setup an USB Audio Device which works on a host? (and transfers audio samples, at least in one direction)
And how to keep my UART via USB-C working when setting up USB Audio?