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

Add USB audio support #708

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add USB audio support #708

wants to merge 3 commits into from

Conversation

probonopd
Copy link
Owner

@probonopd probonopd commented Aug 23, 2024

Thanks @rsta2

To test this, you need a Raspberry Pi larger than 3, not be running in USB gadget mode, and need to set SoundDevice=usb in minidexed.ini.

#148 (comment)

Please note that the driver by default searches for 16-bit audio interfaces. If your USB audio interfaces uses 24 bits, you have to add the option soundopt=24 to the file cmdline.txt on the SD card.

If you are testing this, please let us know which hardware you are using and what the outcome was. Thanks!

Copy link

Build for testing:
MiniDexed_2024-08-23-9ade4be
Use at your own risk.

@rsta2
Copy link
Contributor

rsta2 commented Aug 23, 2024

@probonopd You are welcome. The RPi 4 or 5 must run in host mode, not gadget mode, and the USB audio interface must be connected, when the system is started (no hot-plugging here).

@probonopd
Copy link
Owner Author

probonopd commented Aug 23, 2024

Thanks for the clarification @rsta2, of course I meant "must run in host mode, not gadget mode". Corrected above.

@Koshdukai
Copy link

Koshdukai commented Aug 28, 2024

Well, tried the MiniDexed_2024-08-23-9ade4be in a RPi400 and it was able to connect to an Arturia MiniFuse1 but the audio comes out distorted.
Tried with no soundopt=24, with soundopt=16, soundopt=24 and soundopt=32 on the cmdline.txt but the style of digital distortion kept being similar.
Also tried SampleRate=48000 and SampleRate=44100 on the minidexed.ini with no change either.

So I guess, the SoundDevice=usb does work but there's something still needing to be tweaked, most likely on the settings side but all I know I could try would be audio bit depth and audio rate ...and even tried ChunkSize=256 and ChunkSize=512, just in case this refers to the "audio buffer" size, but no change.

@probonopd
Copy link
Owner Author

Thanks for testing @Koshdukai. Any chance you could record and upload this for us to listen to?

@Koshdukai
Copy link

I did try to attach a zip with a .wav of the audio but the attachment didn't "stick"
Trying again here
2-Audio 0001 [2024-08-28 200218].zip

ah, it worked this time :)

@rsta2
Copy link
Contributor

rsta2 commented Aug 29, 2024

I will try this MiniDexed test version by myself here soon.

@Koshdukai
Copy link

Koshdukai commented Aug 29, 2024

btw, I initially tried it with an old Propellerhead Balance interface that I'm already using with no issues with that same RPi400 running Zynthian, but this MiniDexed build didn't look like it was able to use it.
That's why I tried with the MiniFuse1, which is yet another small audio interface that I'm trying to put to some use instead of having it stored, doing nothing... like currently the old RPi2B which I was using for the MiniDexed.

@paolofalcoruegg
Copy link

Unfortunately I wasn't successful testing with my Alesis Core1 interface. I set soundopt=24 as well as SoundDevice=usb. I used a RPi4 that was working before with the current Production build of MiniDexed. Are there any logs that I could provide?

@rsta2
Copy link
Contributor

rsta2 commented Aug 29, 2024

I have to confirm, that this test version produces noise via USB audio streaming, but not a clear sound. I tested with an ASUS XONAR U5 interface with 48000 Sa/s and 16-bits sample size. Because after a lot of changes to MiniDexed in the meantime I cannot quickly say, what the reason is or may be.

I can only say, that USB audio works with my MiniSynth Pi, but MiniSynth Pi uses the (older) alternate programming interface, provided by the class CSoundBaseDevice, while MiniDexed uses the standard interface. I tested USB audio streaming successfully with the standard interface with Circle sample/34-sounddevices and the test/sound-controller, but these are not real synth apps and do not use multiple cores.

Taking into account that USB audio devices do not work with a fixed chunk size, this may affect the behavior of the class CSoundBaseDevice. The number of transferred audio samples changes with each USB transfer.

Now I have to port MiniSynth Pi to the standard interface of CSoundBaseDevice, to see, if this works or not. This will take a few days. Problems with specific interfaces could be sorted out afterwards.

@rsta2
Copy link
Contributor

rsta2 commented Aug 31, 2024

I got MiniDexed working with the initial USB build with these USB audio streaming devices:

  • ASUS XONAR U5 (16 or 24 bits sample size)
  • Unitek Y-247A (16 bits sample size)
  • C-Media PD552 (16 bits sample size)

The ChunkSize parameter is very critical. I used these parameters in minidexed.ini:

SoundDevice=usb
SampleRate=48000
ChunkSize=384

A chunk size of 256 did not work, neither did 1024. I think, it should be a multiple of SampleRate / 1000 and greater than 192.

It's important to add the following parameter to the file cmdline.txt on the SD card, if your USB audio streaming device does support a sample size of 24 bits only:

soundopt=24

The default is soundopt=16. soundopt=32 is not supported.

There are many different USB audio streaming devices out there and it's likely, that some of them will not work. To be able to debug the reason, if it does not work, the log messages starting with uaudio1 and sndusb, are of interest.

@probonopd
Copy link
Owner Author

Thank you very much for looking into this @rsta2.

Copy link

Build for testing:
MiniDexed_2024-08-31-9b93d18
Use at your own risk.

@Koshdukai
Copy link

ah so it was ChunkSize related, as I was kinda suspecting/hoping :)
Will try with the "SampleRate / 1000 and greater than 192" rule, which basically should be these:
SampleRate=48000
ChunkSize=384

In 44.1KHz case, I'm guessing 441 should work but I'm wondering how to deal with any of the non-integer multiples below it.

Anyway, time to test this latest build :)
Thanks @rsta2 and @probonopd !

@Koshdukai
Copy link

Koshdukai commented Aug 31, 2024

Got it working on the Arturia MiniFuse1 with both soundopt=16 or soundopt=24 (it supports both formats, so that checks out).
Tried with SampleRate=48000 and ChunkSize=384 and the audio is near perfect, except for a cyclic "click" (like a DC jump, probably 1 or a couple audio samples/frames wide)
Also tried with with ChunkSize=768, but I still get it:
image
So no matter if soundopt is 16 or 24 and obeying the SampleRate/1000*n>192 rule, that cyclic click shows up.
MiniDexed_2024-08-31-9b93d18 Arturia MiniFuse1 soundopt=16 SampleRate=48000 ChunkSize=768.zip

I'm now going to check if minimum changes to the ChunkSize affect that cycle, hopefully finding a value that makes it disapear... if still ChunkSize related.

btw, Propellerhead Balance still doesn't work (but that's ok) giving a "Cannot initialize function" usbdev error.

@Koshdukai
Copy link

Koshdukai commented Aug 31, 2024

After a lot of testing with various 48 multiples for the ChunkSize, I end up returning to the 384 value

SoundDevice=usb
SampleRate=48000

#ChunkSize=192
#ChunkSize=240
#ChunkSize=288
#ChunkSize=336
#ChunkSize=383 -> fuzzy
#125b/s:ChunkSize=384 -> click
ChunkSize=384
#ChunkSize=385 -> click
#ChunkSize=386 -> garbled
#ChunkSize=432
#100b/s:ChunkSize=480
#96b/s:ChunkSize=500
#80b/s:ChunkSize=600
#75b/s:ChunkSize=640
#64b/s:ChunkSize=750
#ChunkSize=768 -> more clicks
#60b/s:ChunkSize=800
#50b/s:ChunkSize=960
#48b/s:ChunkSize=1000
#40b/s:ChunkSize=1200
#32b/s:ChunkSize=1500
#ChunkSize=1536
#30b/s:ChunkSize=1600
#ChunkSize=3072

even trying some of the usually suggested ones for 48KHz on Windows:
image

@rsta2
Copy link
Contributor

rsta2 commented Aug 31, 2024

@Koshdukai Thanks for testing! Please try soundopt=24 in cmdline.txt with the Propellerhead Balance. Unfortunately I cannot hear these clicks here with ChunkSize=384 with my interfaces. Let's see, what happens with other interfaces.

@Koshdukai
Copy link

I think I tried both, without and with 16 or 24 on Balance but I'll recheck ASAP :)

@miotislucifugis
Copy link

This is a pretty exciting development. Apologies if Im getting to far ahead, but would it be possible to set up USB audio so it defaults to I2s (or other "internal" audio hardware) if no USB audio source was detected and switches to USB audio out when a device was connected?

@rsta2
Copy link
Contributor

rsta2 commented Sep 1, 2024 via email

@Koshdukai
Copy link

Koshdukai commented Sep 1, 2024

Please try soundopt=24 in cmdline.txt with the Propellerhead Balance.

Just re-checked and confirmed that it doesn't make a difference. Balance still gives the "Cannot initialize function" usbdev error.
It works fine with regular linux builds or Zynthan, so there might be some specific difference on this one that might be known already on the regular builds doing usb audio handling (maybe?)

oh! speaking of weird USB audio... let me check the TE OP-1 :D

Edit: nope. Should be soundopt=16 (but also tried 24) & SampleRate=44100 but isn't detected either.

@rsta2
Copy link
Contributor

rsta2 commented Sep 1, 2024

@Koshdukai Thanks for testing! :D

@rsta2
Copy link
Contributor

rsta2 commented Sep 2, 2024

@paolofalcoruegg When you attach a HDMI display, you will get the MiniDexed log. I'm interested in the lines, which are starting with "uaudio" or "sndusb" (after the time).

@rsta2
Copy link
Contributor

rsta2 commented Sep 3, 2024

Here is a list of the USB audio streaming devices, which have been successfully tested with Circle. Other devices may or may not work.

Unfortunately there is no quick way to support many more devices. Each problem would have to be sorted out separately with user support, which can take longer. We did this before for some devices. My assumption was, that Circle would already work with more devices, but maybe this was wrong.

Finally I have to say, that Circle is a bare metal environment, which has been developed by very few developers. You cannot compare it with Linux in this field. Someone who creates a new USB audio interface, will probably test it with Linux on its own, but not with Circle. And I cannot buy all these interfaces to test them.

Copy link

Build for testing:
MiniDexed_2024-09-22-2f74d22
Use at your own risk.

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

Successfully merging this pull request may close these issues.

5 participants