Skip to content
Snippets Groups Projects
Commit acf4e92f authored by Arnaud Ferraris's avatar Arnaud Ferraris Committed by Arnaud Ferraris
Browse files

q6voiced: port to libasound

Tinyalsa is an Android library, very rarely packaged by traditional
Linux distributions. It can easily be replaced with the more usual
`libasound` in this case, which will make packaging it easier.
parent 7ef3c3ca
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,9 @@ project('q6voiced', 'c')
pkg = import('pkgconfig')
dbus = dependency('dbus-1')
tinyalsa = dependency('tinyalsa')
alsa = dependency('alsa')
executable('q6voiced',
'q6voiced.c',
dependencies: [dbus, tinyalsa],
dependencies: [dbus, alsa],
install: true)
......@@ -2,20 +2,12 @@
#include <stdbool.h>
#include <stdio.h>
#include <dbus/dbus.h>
#include <tinyalsa/asoundlib.h>
/* Note: These parameters have little relevance (no audio data written) */
struct pcm_config pcm_config_voice_call = {
.channels = 1,
.rate = 8000,
.period_size = 160,
.period_count = 2,
.format = PCM_FORMAT_S16_LE,
};
#include <string.h>
#include <alsa/asoundlib.h>
struct q6voiced {
unsigned int card, device;
struct pcm *tx, *rx;
char card[64];
snd_pcm_t *tx, *rx;
};
static void q6voiced_open(struct q6voiced *v)
......@@ -27,14 +19,31 @@ static void q6voiced_open(struct q6voiced *v)
* Opening the PCM devices starts the stream.
* This should be replaced by a codec2codec link probably.
*/
v->tx = pcm_open(v->card, v->device, PCM_IN, &pcm_config_voice_call);
v->rx = pcm_open(v->card, v->device, PCM_OUT, &pcm_config_voice_call);
if (!pcm_is_ready(v->tx) || pcm_prepare(v->tx))
if (snd_pcm_open(&v->tx, v->card, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK) < 0 ||
snd_pcm_set_params(v->tx, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 1, 8000, 0, 500000) < 0 ||
snd_pcm_prepare(v->tx) < 0) {
perror("Failed to open tx");
if (!pcm_is_ready(v->rx) || pcm_prepare(v->rx))
goto error;
}
if (snd_pcm_open(&v->rx, v->card, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK) < 0 ||
snd_pcm_set_params(v->rx, SND_PCM_FORMAT_S16_LE, SND_PCM_ACCESS_RW_INTERLEAVED, 1, 8000, 0, 500000) < 0 ||
snd_pcm_prepare(v->rx) < 0) {
perror("Failed to open rx");
goto error;
}
printf("PCM devices were opened.\n");
return;
error:
if (v->tx) {
snd_pcm_close(v->tx);
v->tx = NULL;
}
if (v->rx) {
snd_pcm_close(v->rx);
v->rx = NULL;
}
}
static void q6voiced_close(struct q6voiced *v)
......@@ -42,8 +51,8 @@ static void q6voiced_close(struct q6voiced *v)
if (!v->tx)
return; /* Not active */
pcm_close(v->rx);
pcm_close(v->tx);
snd_pcm_close(v->tx);
snd_pcm_close(v->rx);
v->rx = v->tx = NULL;
printf("PCM devices were closed.\n");
......@@ -112,11 +121,13 @@ int main(int argc, char **argv)
DBusConnection *conn;
DBusError err;
if (argc != 2 || sscanf(argv[1], "hw:%u,%u", &v.card, &v.device) != 2) {
if (argc != 2) {
fprintf(stderr, "Usage: q6voiced hw:<card>,<device>\n");
return 1;
}
strlcpy(v.card, argv[1], sizeof(v.card) - 1);
// See: http://web.archive.org/web/20100309103206/http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html
// "Receiving a Signal"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment