[Partially Solved]Using U2 as USB DAC

Post Reply
rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

[Partially Solved]Using U2 as USB DAC

Post by rickyzhang »

I'm exploring USB gadget driver and wondering if possible to use U2 as USB DAC. So I hook up U2 OTG usb cable to my PC and modprobe g_audio (disable legacy UAC1).

My host do loads snd-usb-audio module automatically:

Code: Select all

[45639.434037] usbcore: registered new interface driver snd-usb-audio


But u2 doesn't seem to work probably. The chip MAX98090 on U2 does have DAC function. Is it possible to fix it?
Last edited by rickyzhang on Mon Dec 28, 2015 11:22 pm, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 38033
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1999 times
Been thanked: 1206 times
Contact:

Re: Using U2 as USB DAC

Post by odroid »

I never tried the audio gadget.

What is the result of "cat /proc/asound/cards" on your PC?

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: Using U2 as USB DAC

Post by rickyzhang »

My bad. It is permission issue to prevent me to run aplay -l

Code: Select all

cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xf7620000 irq 45
 1 [NVidia         ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xf7080000 irq 17
 2 [NVidia_1       ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xf5080000 irq 19
 3 [Gadget         ]: USB-Audio - Linux USB Audio Gadget
                      Linux 3.8.13.30 with s3c-hsotg Linux USB Audio Gadget at usb-0000:00:1d.0-1.1,
However, when using aplay in host pc:

Code: Select all

sudo aplay -D hw:3,0 output_44100_s16le.wav 
Playing WAVE 'output_44100_s16le.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Warning: rate is not accurate (requested = 44100Hz, got = 64000Hz)
         please, try the plug plugin 
aplay: set_params:1297: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 64000
PERIOD_TIME: 125000
PERIOD_SIZE: 8000
PERIOD_BYTES: 32000
PERIODS: 4
BUFFER_TIME: 500000
BUFFER_SIZE: 32000
BUFFER_BYTES: 128000
TICK_TIME: 0
The test pcm file is verified by my Fiio DAC. The sample rate is correct. But u2 say it is not.
U2 dmesg:

Code: Select all

[ 9719.299514] s3c-hsotg s3c-hsotg: s3c_hsotg_irq: 04008038 00000010 (d00c3cd4) retry 8
[ 9719.299522] s3c-hsotg s3c-hsotg: s3c_hsotg_handle_rx: GRXSTSP=0x016c0080 (8@0)
[ 9719.299529] s3c-hsotg s3c-hsotg: SetupRX (Frame=0x000018bc, DOPEPCTL=0x00028000)
[ 9719.299536] s3c-hsotg s3c-hsotg: s3c_hsotg_rx_data: FIFO 8 bytes on ep0 but no req (DxEPCTl=0x00028000)
[ 9719.299543] s3c-hsotg s3c-hsotg: s3c_hsotg_irq: 04008038 00000010 (d00c3cd4) retry 7
[ 9719.299549] s3c-hsotg s3c-hsotg: s3c_hsotg_handle_rx: GRXSTSP=0x01680000 (0@0)
[ 9719.299554] s3c-hsotg s3c-hsotg: SetupDone (Frame=0x000018bc, DOPEPCTL=0x00028000)
[ 9719.299560] s3c-hsotg s3c-hsotg: s3c_hsotg_handle_outdone: no request active
[ 9719.299566] s3c-hsotg s3c-hsotg: s3c_hsotg_irq: 04088028 00080000 (d00c3cd4) retry 6
[ 9719.299571] s3c-hsotg s3c-hsotg: s3c_hsotg_irq: daint=00010000
[ 9719.299577] s3c-hsotg s3c-hsotg: s3c_hsotg_epint: ep0(out) DxEPINT=0x00000008
[ 9719.299582] s3c-hsotg s3c-hsotg: s3c_hsotg_epint: Setup/Timeout
No sound from U2 via audio jack when playing from host PC, but when I play it in U2. I can hear sound from u2.

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: Using U2 as USB DAC

Post by rickyzhang »

odroid wrote:I never tried the audio gadget.

What is the result of "cat /proc/asound/cards" on your PC?
I found this warning in dmesg in u2:

Code: Select all

[ 9387.237275] ------------[ cut here ]------------
[ 9387.237287] WARNING: at drivers/usb/gadget/s3c-hsotg.c:1464 s3c_hsotg_rx_data+0x128/0x138()
[ 9387.237291] Modules linked in: g_audio libcomposite aufs xt_CHECKSUM iptable_mangle ipt_MASQUERADE iptable_nat nf_nat_ipv4 bridge stp llc ip6t_REJECT bnep rfcomm xt_hl bluetooth ip6t_rt nf_conntrack_ipv6 nf_defrag_ipv6 ipt_REJECT xt_LOG xt_limit xt_tcpudp xt_addrtype nf_conntrack_ipv4 nf_defrag_ipv4 xt_conntrack ip6table_filter ip6_tables ipv6 nf_conntrack_netbios_ns nf_conntrack_broadcast nf_nat_ftp nf_nat nf_conntrack_ftp nf_conntrack iptable_filter ip_tables x_tables smsc95xx r8712u(C) usbnet fuse vfat fat gpio_keys
[ 9387.237385] [<c0014bf0>] (unwind_backtrace+0x0/0xf4) from [<c002499c>] (warn_slowpath_common+0x54/0x64)
[ 9387.237393] [<c002499c>] (warn_slowpath_common+0x54/0x64) from [<c0024a48>] (warn_slowpath_null+0x1c/0x24)
[ 9387.237401] [<c0024a48>] (warn_slowpath_null+0x1c/0x24) from [<c02c7494>] (s3c_hsotg_rx_data+0x128/0x138)
[ 9387.237411] [<c02c7494>] (s3c_hsotg_rx_data+0x128/0x138) from [<c02cb2cc>] (s3c_hsotg_irq+0x7f0/0x8e8)
[ 9387.237422] [<c02cb2cc>] (s3c_hsotg_irq+0x7f0/0x8e8) from [<c007cebc>] (handle_irq_event_percpu+0x54/0x17c)
[ 9387.237431] [<c007cebc>] (handle_irq_event_percpu+0x54/0x17c) from [<c007d020>] (handle_irq_event+0x3c/0x5c)
[ 9387.237440] [<c007d020>] (handle_irq_event+0x3c/0x5c) from [<c007fd0c>] (handle_fasteoi_irq+0x84/0x14c)
[ 9387.237448] [<c007fd0c>] (handle_fasteoi_irq+0x84/0x14c) from [<c007c744>] (generic_handle_irq+0x28/0x40)
[ 9387.237458] [<c007c744>] (generic_handle_irq+0x28/0x40) from [<c000eda0>] (handle_IRQ+0x40/0x90)
[ 9387.237466] [<c000eda0>] (handle_IRQ+0x40/0x90) from [<c000853c>] (gic_handle_irq+0x38/0x68)
[ 9387.237473] [<c000853c>] (gic_handle_irq+0x38/0x68) from [<c000da80>] (__irq_svc+0x40/0x70)
[ 9387.237478] Exception stack(0xe6395e80 to 0xe6395ec8)
[ 9387.237485] 5e80: c0623694 00000000 00000000 5cdc5cdc c0654de8 c0674d68 00001a07 c0654de8
[ 9387.237491] 5ea0: 000005c5 00000000 00000599 b649471f 00000006 e6395ec8 c04357f4 c04357f8
[ 9387.237495] 5ec0: 60000053 ffffffff
[ 9387.237504] [<c000da80>] (__irq_svc+0x40/0x70) from [<c04357f8>] (_raw_spin_unlock_irq+0xc/0x34)
[ 9387.237513] [<c04357f8>] (_raw_spin_unlock_irq+0xc/0x34) from [<c00274d4>] (do_syslog+0x208/0x588)
[ 9387.237524] [<c00274d4>] (do_syslog+0x208/0x588) from [<c01211d8>] (proc_reg_read+0x70/0x94)
[ 9387.237534] [<c01211d8>] (proc_reg_read+0x70/0x94) from [<c00d5a30>] (vfs_read+0x98/0x174)
[ 9387.237542] [<c00d5a30>] (vfs_read+0x98/0x174) from [<c00d5cc0>] (sys_read+0x3c/0x78)
[ 9387.237549] [<c00d5cc0>] (sys_read+0x3c/0x78) from [<c000de80>] (ret_fast_syscall+0x0/0x30)
[ 9387.237554] ---[ end trace 4aeee0c63c084887 ]---
Are there known issues regarding to s3c-hsotg controller driver? I skim through f_uac2. I wonder if OTG USB port from Samsung 4412 supports isochronous transfers.

User avatar
odroid
Site Admin
Posts: 38033
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1999 times
Been thanked: 1206 times
Contact:

Re: Using U2 as USB DAC

Post by odroid »

I have no idea about the isochronous mode.
We've used only bulk transferes with mass/ethernet/serial drivers. :(

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: Using U2 as USB DAC

Post by rickyzhang »

odroid wrote:I have no idea about the isochronous mode.
We've used only bulk transferes with mass/ethernet/serial drivers. :(
I'm using kernel 3.8 for u2. s3c-hsotg didn't add support for isochronous mode until 3.13. Are there any easy way you'd suggest to back port this feature to 3.8 or is it OK to use odroid-3.14.y-linaro?

User avatar
odroid
Site Admin
Posts: 38033
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1999 times
Been thanked: 1206 times
Contact:

Re: Using U2 as USB DAC

Post by odroid »

As far as I remember, the 3.14.y branch might not support the on board DAC max98090.
I have no idea whether it is easy or not to make a back port the USB drivers.

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: Using U2 as USB DAC

Post by rickyzhang »

odroid wrote:As far as I remember, the 3.14.y branch might not support the on board DAC max98090.
I have no idea whether it is easy or not to make a back port the USB drivers.
Thanks for your info. I will give a try to back port.

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by rickyzhang »

After I back port commit 1479e8411831c2112fa83b44664075e3ceea2533 to branch odroid-3.8.y so that enable isochronous mode in USB device controller, I can hear sound from u2 when play PCM from host PC.

one more thing, in U2 user space I need to pipe PCM from USB gadget audio to U2 sound card --> arecord -f dat -t wav -D hw:1,0 | aplay -D hw:0,0

Although I can hear sound now, the tempo of the sound doesn't sound correct. There is some work may needed for f_uac2 in gadget USB API. In any case, this is great to prove my idea is feasible.

User avatar
odroid
Site Admin
Posts: 38033
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1999 times
Been thanked: 1206 times
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by odroid »

Good to know you made it work.
Is there any sample-rate mismatch between the UAC and the MAX98090 driver?

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by rickyzhang »

On my host PC, I do find a warning that suggest that sample rate mismatch when playing 44.1kHz. I haven't figure it out why.

I may find a fix in commit 9bb87f168931cf55738ed2fbda3639575cede886 . The fix address playing speed but it is related to isochronous transfer.

To be honest, I'm not familiar with isochronous transfer, either. I need do some reading on USB specs. In any case, it seems there is a fix sitting there. I will let you know if I can sort it out.

User avatar
odroid
Site Admin
Posts: 38033
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1999 times
Been thanked: 1206 times
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by odroid »

It is worth to try playback a 48Khz music file to find a clue.

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by rickyzhang »

After digging into f_uac2.c source code, here are my findings:

1. The gadget driver send PCM from USB host Out to USB gadget virtual ALSA capture device.

2. hard coded capture sample rate --> static int c_srate = 64000;. That explains why it shows warning in host side : Warning: rate is not accurate (requested = 44100Hz, got = 64000Hz).

To make my U2 as USB DAC, there is more work needs to be done, eg redirect PCM to a physical (or configurable) ALSA audio output device, enable multiple sample rate and etc.

Regarding to the play back speed, although some hints in commit 9bb87f168931cf55738ed2fbda3639575cede886 suggest that it relates to Maximum USB packet size, I haven't figure it out yet after reading isochronous mode in USB 2.0 specs.

rickyzhang
Posts: 60
Joined: Thu Feb 28, 2013 1:20 pm
languages_spoken: english
ODROIDs: u2, xu4
Location: Cary, NC
Has thanked: 0
Been thanked: 0
Contact:

Re: [Partially Solved]Using U2 as USB DAC

Post by rickyzhang »

Regarding to play speed, I confirm that it is mismatch sample rate between gadget and host. In default, gadget driver use 64Khz as capture rate. After change into 44.1kHz, the speed sound OK.

However, I can hear click sound during playback in pipe. I will look into that.

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest