* Right interface for cellphone modem audio (was Re: [PATCHv2 0/2] N900 Modem Speech Support)
[not found] ` <alpine.DEB.2.00.1503051844420.2610@ecabase.localdomain>
@ 2015-03-06 9:43 ` Pavel Machek
2015-03-06 20:49 ` Kai Vehmanen
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Machek @ 2015-03-06 9:43 UTC (permalink / raw)
To: Kai Vehmanen, perex, tiwai, alsa-devel
Cc: Sebastian Reichel, Peter Ujfalusi, Kai Vehmanen, Pali Rohar,
Aaro Koskinen, Ivaylo Dimitrov, linux-omap, linux-kernel,
linux-api
Hi!
> >>Userland access goes via /dev/cmt_speech. The API is implemented in
> >>libcmtspeechdata, which is used by ofono and the freesmartphone.org project.
> >Yes, the ABI is "tested" for some years, but it is not documented, and
> >it is very wrong ABI.
> >
> >I'm not sure what they do with the "read()". I was assuming it is
> >meant for passing voice data, but it can return at most 4 bytes,
> >AFAICT.
> >
> >We already have perfectly good ABI for passing voice data around. It
> >is called "ALSA". libcmtspeech will then become unneccessary, and the
> >daemon routing voice data will be as simple as "read sample from
>
> I'm no longer involved with cmt_speech (with this driver nor modems in
> general), but let me clarify some bits about the design.
Thanks a lot for your insights; high level design decisions are quite
hard to understand from C code.
> First, the team that designed the driver and the stack above had a lot of
> folks working also with ALSA (and the ALSA drivers have been merged to
> mainline long ago) and we considered ALSA on multiple occasions as the
> interface for this as well.
>
> Our take was that ALSA is not the right interface for cmt_speech. The
> cmt_speech interface in the modem is _not_ a PCM interface as modelled by
> ALSA. Specifically:
>
> - the interface is lossy in both directions
> - data is sent in packets, not a stream of samples (could be other things
> than PCM samples), with timing and meta-data
> - timing of uplink is of utmost importance
I see that you may not have data available in "downlink" scenario, but
how is it lossy in "uplink" scenario? Phone should always try to fill
the uplink, no? (Or do you detect silence and not transmit in this
case?) (Actually, I guess applications should be ready for "data not
ready" case even on "normal" hardware due to differing clocks.)
Packets vs. stream of samples... does userland need to know about the
packets? Could we simply hide it from the userland? As userland daemon
is (supposed to be) realtime, do we really need extra set of
timestamps? What other metadata are there?
Uplink timing... As the daemon is realtime, can it just send the data
at the right time? Also normally uplink would be filled, no?
> Some definite similarities:
> - the mmap interface to manage the PCM buffers (that is on purpose
> similar to that of ALSA)
>
> The interface was designed so that the audio mixer (e.g. Pulseaudio) is run
> with a soft real-time SCHED_FIFO/RR user-space thread that has full control
> over _when_ voice _packets_ are sent, and can receive packets with meta-data
> (see libcmtspeechdata interface, cmtspeech.h), and can detect and handle
> gaps in the received packets.
Well, packets are of fixed size, right? So the userland can simply
supply the right size in the common case. As for sending at the right
time... well... if the userspace is already real-time, that should be
easy.
Now, there's a difference in the downlink. Maybe ALSA people have an
idea what to do in this case? Perhaps we can just provide artificial
"zero" data?
> This is very different from modems that offer an actual PCM voice link for
> example over I2S to the application processor (there are lots of these on
> the market). When you walk out of coverage during a call with these modems,
> you'll still get samples over I2S, but not so with cmt_speech, so ALSA is
> not the right interface.
Yes, understood.
> Now, I'm not saying the interface is perfect, but just to give a bit of
> background, why a custom char-device interface was chosen.
Thanks and best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Right interface for cellphone modem audio (was Re: [PATCHv2 0/2] N900 Modem Speech Support)
2015-03-06 9:43 ` Right interface for cellphone modem audio (was Re: [PATCHv2 0/2] N900 Modem Speech Support) Pavel Machek
@ 2015-03-06 20:49 ` Kai Vehmanen
0 siblings, 0 replies; 2+ messages in thread
From: Kai Vehmanen @ 2015-03-06 20:49 UTC (permalink / raw)
To: Pavel Machek
Cc: perex-/Fr2/VpizcU, Takashi Iwai,
alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw, Sebastian Reichel,
Peter Ujfalusi, Kai Vehmanen, Pali Rohar, Aaro Koskinen,
Ivaylo Dimitrov, linux-omap-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
linux-api-u79uwXL29TY76Z2rM5mHXA
Hi,
On Fri, 6 Mar 2015, Pavel Machek wrote:
>> Our take was that ALSA is not the right interface for cmt_speech. The
>> cmt_speech interface in the modem is _not_ a PCM interface as modelled by
>> ALSA. Specifically:
>>
>> - the interface is lossy in both directions
>> - data is sent in packets, not a stream of samples (could be other things
>> than PCM samples), with timing and meta-data
>> - timing of uplink is of utmost importance
>
> I see that you may not have data available in "downlink" scenario, but
> how is it lossy in "uplink" scenario? Phone should always try to fill
> the uplink, no? (Or do you detect silence and not transmit in this
Lossy was perhaps not the best choice of words, non-continuous would be
a better choice in the uplink case. To adjust timing, some samples from
the continuous locally recorded PCM stream need to be skipped and/or
duplicated. This would normally be done between speech bursts to avoid
artifacts.
> Packets vs. stream of samples... does userland need to know about the
> packets? Could we simply hide it from the userland? As userland daemon
> is (supposed to be) realtime, do we really need extra set of
> timestamps? What other metadata are there?
Yes, we need flags that tell about the frame. Please see docs for
'frame_flags' and 'spc_flags' in libcmtspeechdata cmtspeech.h:
https://www.gitorious.org/libcmtspeechdata/libcmtspeechdata/source/9206835ea3c96815840a80ccba9eaeb16ff7e294:cmtspeech.h
Kernel space does not have enough info to handle these flags as the audio
mixer is not implemented in kernel, so they have to be passed to/from
user-space.
And some further info in libcmtspeechdata/docs/
https://www.gitorious.org/libcmtspeechdata/libcmtspeechdata/source/9206835ea3c96815840a80ccba9eaeb16ff7e294:doc/libcmtspeechdata_api_docs_main.txt
> Uplink timing... As the daemon is realtime, can it just send the data
> at the right time? Also normally uplink would be filled, no?
But how would you implement that via the ALSA API? With cmt_speech, a
speech packet is prepared in a mmap'ed buffer, flags are set to describe
the buffer, and at the correct time, write() is called to trigger
transmission in HW (see cmtspeech_ul_buffer_release() in
libcmtspeechdata() -> compare this to snd_pcm_mmap_commit() in ALSA). In
ALSA, the mmap commit and PCM write variants just add data to the
ringbuffer and update the appl pointer. Only initial start (and stop) on
stream have the "do something now" semantics in ALSA.
The ALSA compressed offload API did not exist back when we were working on
cmt_speech, but that's still not a good fit, although adds some of the
concepts (notably frames).
> Well, packets are of fixed size, right? So the userland can simply
> supply the right size in the common case. As for sending at the right
> time... well... if the userspace is already real-time, that should be
> easy
See above, ALSA just doesn't work like that, there's no syscall for "send
these samples now", the model is different.
Br, Kai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-06 20:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1425343454-6551-1-git-send-email-sre@kernel.org>
[not found] ` <20150305113013.GA3867@amd>
[not found] ` <alpine.DEB.2.00.1503051844420.2610@ecabase.localdomain>
2015-03-06 9:43 ` Right interface for cellphone modem audio (was Re: [PATCHv2 0/2] N900 Modem Speech Support) Pavel Machek
2015-03-06 20:49 ` Kai Vehmanen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox