On some systems the ALSA output buffer is pretty big, and
if the audio samples are not being passed into the buffer
quickly enough, it becomes starved for data, resulting
in an error called underrun.
Previously, when it happenned, GAPK used to stop processing
with the following message (where X is a random number):
[+] PQ: Adding ALSA output (dev='default', blk_len=320)
[!] pq_execute(): abort, item returned -1
[+] Processed X frames
According to the ALSA documentation, the pcm_handle
changes its state when the problem happens, and should
be recovered using the snd_pcm_prepare() call. This change
actually does that.
This testsuite takes a PCM auidio file and encodes from it every
supported format, and compares that output with a known sample (from an
earlier, trusted version of gakp, shipped as part of this project).
I then re-decodes this file to PCM and also compares that with a shipped
reference re-decode.
While EFR has a canonical format of 31 bytes, the codec_efr.c *does not*
use that canonical format as input. Rather, it uses the format of .amr
files with a 0x3C header as first byte. So the resulting encode/decode
functions should not assume 31 bytes, but 32 bytes.
I noticed that ti-hr format doesn't pass an encode-decode-playback test,
and discussion with tnt resulted in the following conclusion:
19:29 <@tnt> looking at fr and efr, it's always msb_xxx
19:30 <@tnt> and if I ever used it, then most likely it was for decoding
meaning ti_hr_to_canon would have been used and not the
other way around.
The RTP EFR payload is a bit like the FR payload: one nibble magic
marker, then followed by the actual codec bits. So we need to
add/remove that magic marker and shift the remainder by one nibble.
The ETSI reference codec actually uses an array of 20/22 16bit values
rather than a "canonical" format. The conversion is what fmt_hr_ref.c
is doing. However, codec_hr.c must then subsequently not check for the
canonical input/output sizes, but those specific to it.
After merging this change, there is support for the AMR codec (by means
of libopencore-amr, which is already used for EFR).
In terms of gapk formats, we introdude
* the "amr-opencore" format, which serves both as the canonical format,
and as the input format to opencore-amrnb itself.
* the "rtp-amr" format, which is the payload of RFC4867 octet-aligned mode
You can use the following command for a real-time RTP playback for AMR
frames:
./gapk -I 0.0.0.0/30000 -f rtp-amr -A default -g rawpcm-s16le
In fact, it should probably be better to silently ignore all those
errors as opposed to aborting the entire processing queue? But that's
for another patch...
Basically the reference code has a bunch of global state.
With some minimal patchihg (previous commit) we can ensure that all
that state is within .bss
So what we do it to save/restore the bss section between calls of the
reference code so we can process several in // and we don't have to
completely fix all reference to global state in the reference codec.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Patches are without function-name and without context to minimize what
we have to include.
The current patchset does exactly what the previous 'sed' did, but this
will make it easier to add more.
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Since automake 1.13 INCLUDES is depricates and causes a warning
Inspired from similar patches by Alexander Huemer for other osmocom
projects
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Instead of having only file-based I/O, this enables gapk to receive and
send RTP streams, e.g. from live GSM network equipment like
sysmoBTS/nanoBTS.
Support is currently simplistic. On transmit, there is hard-coded codec
type of full-rate GSM. On receive-side, we should auto-detect the
format based on frame size and/or payload type, but we don't do that yet
at all.