Re: [Alsa-user] USB Synchronization w/ALSA via g_audio

2018-07-13 Thread Clemens Ladisch via Alsa-user
Rob wrote:
> I am capturing data from my microphone, and transmitting it via
> pcm_write() to the USB gadget card, and arecording on the USB host.
> If I query the buffer, I begin to see a creeping fill on the device
> side buffers, such that after a few hours of constant streaming, the
> buffer is filled, and my pcm_write is returning "we only wrote SOME
> of your data".

The ALSA API was designed for 'normal' sound cards where only the
hardware itself can control the sample clock.  This means that the USB
audio gadget does not give you control over its clock, and that samples
are moved synchronously with the USB bus clock.

You'd have to measure the clock difference, and dynamically resample
the stream.  (Zita-ajbridge does something like this.)

Alternatively, it might be possible to extend the audio gadget driver
to add a mechanism to slightly adjust the sample rate, relative to the
bus clock.


Regards,
Clemens

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] USB Synchronization w/ALSA via g_audio

2018-07-13 Thread Rob
Hi Chris,

My goal is a low latency USB microphone that's always on; similar to an
intercom system.

I am capturing data from my microphone, and transmitting it via pcm_write()
to the USB gadget card, and arecording on the USB host. If I query the
buffer, I begin to see a creeping fill on the device side buffers, such
that after a few hours of constant streaming, the buffer is filled, and my
pcm_write is returning "we only wrote SOME of your data".  As this happens,
I start to notice more and more latency between my device's capture and the
host's playback, as I eventually have a whole buffer's worth of "old" audio
I'm queuing "now's audio" data behind. If I modify the UAC driver to
provide a larger buffer size, my pcm_write of "not a full buffer" takes
longer to happen, but when it does, my latency has gone from unnoticeable
to several seconds.

I figured (and may very well be wrong), that this was due to my device
clocks sending buffers at a rate *slightly* faster than the USB is able to
sink it to the host. Could this be something else?

Thanks,
Rob




On Thu, Jul 12, 2018 at 8:13 PM, chris hermansen 
wrote:

> Rob and list,
>
> On Thu, Jul 12, 2018, 19:27 Rob  wrote:
>
>> Hi all,
>>
>> I'm reading about the feedback mechanism for USB audio. I'm trying to see
>> if I can implement asynchronous mode.
>>
>
> What makes you think asynchronous mode isn't already implemented?
>
> Chris Hermansen
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] USB Synchronization w/ALSA via g_audio

2018-07-12 Thread chris hermansen
Rob and list,

On Thu, Jul 12, 2018, 19:27 Rob  wrote:

> Hi all,
>
> I'm reading about the feedback mechanism for USB audio. I'm trying to see
> if I can implement asynchronous mode.
>

What makes you think asynchronous mode isn't already implemented?

Chris Hermansen
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] USB Synchronization w/ALSA via g_audio

2018-07-12 Thread Rob
Hi all,

I'm reading about the feedback mechanism for USB audio. I'm trying to see
if I can implement asynchronous mode.

Basically I am feeding the USB gadget with PCM writes at a fixed rate, but
I am very slowly filling the buffer out to the sink on the other end.

Eventually, the buffer fills, and I am only able to write the available
free space, and I stat to develop latency problems. I believe this is due
to the subtle clock skew between my clocks.

What is a good strategy to prevent this? I found this link (
http://www.electronicdesign.com/embedded/achieving-bit-perfect-usb-audio),
and am curious if the ALSA users here have implemented something like this
(or with the g_audio kernel module).

Thanks,
Rob
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user