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

UAC1/UAC2 #35

Open
giuliomoro opened this issue May 16, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@giuliomoro
Copy link
Contributor

commented May 16, 2017

tried the usual configfs stuff in /opt/Bela/bela_gadget.sh:

mkdir -p functions/uac2.usb0
....
ln -s functions/uac2.usb0 configs/c.1/

so that the default values are loaded:

root@bela:/sys/kernel/config/usb_gadget/g# for a in functions/uac2.usb0/*; do echo $a:; cat $a; done
functions/uac2.usb0/c_chmask:
3
functions/uac2.usb0/c_srate:
64000
functions/uac2.usb0/c_ssize:
2
functions/uac2.usb0/p_chmask:
3
functions/uac2.usb0/p_srate:
48000
functions/uac2.usb0/p_ssize:
2

see here for some "documentation".

as a result, aplay -L gives:

default:CARD=UAC2Gadget
    UAC2_Gadget, UAC2 PCM
    Default Audio Device
sysdefault:CARD=UAC2Gadget
    UAC2_Gadget, UAC2 PCM
    Default Audio Device
dmix:CARD=UAC2Gadget,DEV=0
    UAC2_Gadget, UAC2 PCM
    Direct sample mixing device
dsnoop:CARD=UAC2Gadget,DEV=0
    UAC2_Gadget, UAC2 PCM
    Direct sample snooping device
hw:CARD=UAC2Gadget,DEV=0
    UAC2_Gadget, UAC2 PCM
    Direct hardware device without any conversions
plughw:CARD=UAC2Gadget,DEV=0
    UAC2_Gadget, UAC2 PCM
    Hardware device with all software conversions

but if I try to play a sound I get:

$ aplay -D hw:CARD=UAC2Gadget,DEV=0 /root/Bela/examples/terminal-only/samples/sample.wav
Playing WAVE '/root/Bela/examples/terminal-only/samples/sample.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
aplay: set_params:1305: Channels count non available

Also, it does NOT show up on the host (tried Mac and Linux) as an audio device.

@giuliomoro

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2017

If I use uac1 instead, then the default parameters are:

root@bela:/sys/kernel/config/usb_gadget/g# for a in functions/uac1.usb0/*; do echo $a:; cat $a; done
functions/uac1.usb0/audio_buf_size:
48000
functions/uac1.usb0/fn_cap:
/dev/snd/pcmC0D0c
functions/uac1.usb0/fn_cntl:
/dev/snd/controlC0
functions/uac1.usb0/fn_play:
/dev/snd/pcmC0D0p
functions/uac1.usb0/req_buf_size:
200
functions/uac1.usb0/req_count:
256

then if I mknod the device files appropriately (see here):

mknod /dev/snd/pcmC0D0c c 116 24
mknod /dev/snd/pcmC0D0p c 116 16
mknod /dev/snd/controlC0 c 116 0

then I get this when running;

root@bela:/sys/kernel/config/usb_gadget/g# ls /sys/class/udc/ > UDC
ls: write error: No such device

which in turn dmesges this:

[  214.519683] usb0: HOST MAC b6:e8:3f:ac:d9:86
[  214.519819] usb0: MAC 16:09:d3:c0:73:89
[  214.527247] configfs-gadget gadget: unable to open sound control device file: /dev/snd/controlC0
[  214.536150] configfs-gadget gadget: we need at least one control device
[  214.542844] configfs-gadget gadget: unbind function 'rndis'/dc7c4cc0
[  214.549258] configfs-gadget gadget: unbind function 'Mass Storage Function'/dafb4880
[  214.557072] configfs-gadget gadget: unbind function 'acm'/da867c00
[  214.563307] configfs-gadget gadget: unbind function 'gmidi function'/daada400
[  214.632260] configfs-gadget musb-hdrc.0.auto: failed to start g: -19

which is funny, because /dev/snd/controlC0 is actually there.
The above causes the unload of all the gadgets :(

@dr-offig

This comment has been minimized.

Copy link

commented Jul 24, 2018

Hi Guilio, did you ever figure this out? I'm trying to configure g_audio on a raspberry pi (aghast!). I have it playing stereo audio into my mac fine, but don't seem to be able to configure it for 4 channels. I can't quite get my head around the configfs stuff.

@giuliomoro

This comment has been minimized.

Copy link
Contributor Author

commented Aug 24, 2018

sorry didn't see this message before. Just found the email notification in the spam. No I never figured it out (I didn't spend any more time on it); I pointed a couple of people at this to give it a try and never heard back. So maybe it's not that straightforward? Do you have a link of your working config for the Pi?

@giuliomoro

This comment has been minimized.

Copy link
Contributor Author

commented Mar 11, 2019

probably a kernel version issue, plus I should have used plughw: instead of hw:, or at least specified the --channel count.

On a 4.14 kernel, this works :
In /opt/Bela/bela_gadget.sh:

mkdir -p functions/uac2.usb0            # Audio
echo 44100 > functions/uac2.usb0/c_srate
echo 44100 > functions/uac2.usb0/p_srate
...
ln -s functions/uac2.usb0 configs/c.1/

then reboot and ...

playback:

aplay -D plughw:CARD=UAC2Gadget,DEV=0 /root/Bela/examples/terminal-only/samples/sample.wav --channels 2

(it would probably work without plug if the audio file was stereo)

record:

arecord -D hw:CARD=UAC2Gadget,DEV=0  --rate 48000 --format S16_LE

loopback:

BUFFER=128; PERIOD=128
arecord -D hw:CARD=UAC2Gadget,DEV=0 --disable-resample --disable-format --disable-softvol --format S16_LE --rate 44100 --channels 2  --buffer-size $BUFFER --period-size $PERIOD | aplay -D hw:CARD=UAC2Gadget,DEV=0 --disable-resample --disable-format --disable-softvol --format S16_LE --rate 44100 --channels 2 --buffer-size $BUFFER --period-size $PERIOD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.