2005-10-30 21:58:22 +03:00
|
|
|
/*
|
|
|
|
* QEMU ALSA audio driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Vassili Karpov (malc)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include <alsa/asoundlib.h>
|
2007-11-17 20:35:54 +03:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "audio.h"
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
#define AUDIO_CAP "alsa"
|
|
|
|
#include "audio_int.h"
|
|
|
|
|
|
|
|
typedef struct ALSAVoiceOut {
|
|
|
|
HWVoiceOut hw;
|
|
|
|
void *pcm_buf;
|
|
|
|
snd_pcm_t *handle;
|
|
|
|
} ALSAVoiceOut;
|
|
|
|
|
|
|
|
typedef struct ALSAVoiceIn {
|
|
|
|
HWVoiceIn hw;
|
|
|
|
snd_pcm_t *handle;
|
|
|
|
void *pcm_buf;
|
|
|
|
} ALSAVoiceIn;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int size_in_usec_in;
|
|
|
|
int size_in_usec_out;
|
|
|
|
const char *pcm_name_in;
|
|
|
|
const char *pcm_name_out;
|
|
|
|
unsigned int buffer_size_in;
|
|
|
|
unsigned int period_size_in;
|
|
|
|
unsigned int buffer_size_out;
|
|
|
|
unsigned int period_size_out;
|
|
|
|
unsigned int threshold;
|
|
|
|
|
2007-07-12 14:59:21 +04:00
|
|
|
int buffer_size_in_overridden;
|
|
|
|
int period_size_in_overridden;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2007-07-12 14:59:21 +04:00
|
|
|
int buffer_size_out_overridden;
|
|
|
|
int period_size_out_overridden;
|
2005-11-20 19:24:34 +03:00
|
|
|
int verbose;
|
2005-10-30 21:58:22 +03:00
|
|
|
} conf = {
|
2008-07-09 23:25:30 +04:00
|
|
|
.buffer_size_out = 1024,
|
2006-07-04 20:51:32 +04:00
|
|
|
.pcm_name_out = "default",
|
|
|
|
.pcm_name_in = "default",
|
2005-10-30 21:58:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct alsa_params_req {
|
2008-01-14 07:24:29 +03:00
|
|
|
int freq;
|
|
|
|
snd_pcm_format_t fmt;
|
|
|
|
int nchannels;
|
2008-06-21 21:14:57 +04:00
|
|
|
int size_in_usec;
|
2008-07-09 23:25:28 +04:00
|
|
|
int override_mask;
|
2005-10-30 21:58:22 +03:00
|
|
|
unsigned int buffer_size;
|
|
|
|
unsigned int period_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct alsa_params_obt {
|
|
|
|
int freq;
|
|
|
|
audfmt_e fmt;
|
2008-01-14 07:24:29 +03:00
|
|
|
int endianness;
|
2005-10-30 21:58:22 +03:00
|
|
|
int nchannels;
|
2005-11-05 21:55:28 +03:00
|
|
|
snd_pcm_uframes_t samples;
|
2005-10-30 21:58:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
AUD_log (AUDIO_CAP, "Reason: %s\n", snd_strerror (err));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GCC_FMT_ATTR (3, 4) alsa_logerr2 (
|
|
|
|
int err,
|
|
|
|
const char *typ,
|
|
|
|
const char *fmt,
|
|
|
|
...
|
|
|
|
)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
AUD_vlog (AUDIO_CAP, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
AUD_log (AUDIO_CAP, "Reason: %s\n", snd_strerror (err));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_anal_close (snd_pcm_t **handlep)
|
|
|
|
{
|
|
|
|
int err = snd_pcm_close (*handlep);
|
|
|
|
if (err) {
|
|
|
|
alsa_logerr (err, "Failed to close PCM handle %p\n", *handlep);
|
|
|
|
}
|
|
|
|
*handlep = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_write (SWVoiceOut *sw, void *buf, int len)
|
|
|
|
{
|
|
|
|
return audio_pcm_sw_write (sw, buf, len);
|
|
|
|
}
|
|
|
|
|
2008-01-14 07:24:29 +03:00
|
|
|
static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
switch (fmt) {
|
|
|
|
case AUD_FMT_S8:
|
|
|
|
return SND_PCM_FORMAT_S8;
|
|
|
|
|
|
|
|
case AUD_FMT_U8:
|
|
|
|
return SND_PCM_FORMAT_U8;
|
|
|
|
|
|
|
|
case AUD_FMT_S16:
|
|
|
|
return SND_PCM_FORMAT_S16_LE;
|
|
|
|
|
|
|
|
case AUD_FMT_U16:
|
|
|
|
return SND_PCM_FORMAT_U16_LE;
|
|
|
|
|
2007-02-18 01:19:29 +03:00
|
|
|
case AUD_FMT_S32:
|
|
|
|
return SND_PCM_FORMAT_S32_LE;
|
|
|
|
|
|
|
|
case AUD_FMT_U32:
|
|
|
|
return SND_PCM_FORMAT_U32_LE;
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
default:
|
|
|
|
dolog ("Internal logic error: Bad audio format %d\n", fmt);
|
|
|
|
#ifdef DEBUG_AUDIO
|
|
|
|
abort ();
|
|
|
|
#endif
|
|
|
|
return SND_PCM_FORMAT_U8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-14 07:24:29 +03:00
|
|
|
static int alsa_to_audfmt (snd_pcm_format_t alsafmt, audfmt_e *fmt,
|
|
|
|
int *endianness)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
switch (alsafmt) {
|
|
|
|
case SND_PCM_FORMAT_S8:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_S8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_U8:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_U8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_S16_LE:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_S16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_U16_LE:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_U16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_S16_BE:
|
|
|
|
*endianness = 1;
|
|
|
|
*fmt = AUD_FMT_S16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_U16_BE:
|
|
|
|
*endianness = 1;
|
|
|
|
*fmt = AUD_FMT_U16;
|
|
|
|
break;
|
|
|
|
|
2007-02-18 01:19:29 +03:00
|
|
|
case SND_PCM_FORMAT_S32_LE:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_S32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_U32_LE:
|
|
|
|
*endianness = 0;
|
|
|
|
*fmt = AUD_FMT_U32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_S32_BE:
|
|
|
|
*endianness = 1;
|
|
|
|
*fmt = AUD_FMT_S32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_PCM_FORMAT_U32_BE:
|
|
|
|
*endianness = 1;
|
|
|
|
*fmt = AUD_FMT_U32;
|
|
|
|
break;
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
default:
|
|
|
|
dolog ("Unrecognized audio format %d\n", alsafmt);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_dump_info (struct alsa_params_req *req,
|
|
|
|
struct alsa_params_obt *obt)
|
|
|
|
{
|
|
|
|
dolog ("parameter | requested value | obtained value\n");
|
|
|
|
dolog ("format | %10d | %10d\n", req->fmt, obt->fmt);
|
|
|
|
dolog ("channels | %10d | %10d\n",
|
|
|
|
req->nchannels, obt->nchannels);
|
|
|
|
dolog ("frequency | %10d | %10d\n", req->freq, obt->freq);
|
|
|
|
dolog ("============================================\n");
|
|
|
|
dolog ("requested: buffer size %d period size %d\n",
|
|
|
|
req->buffer_size, req->period_size);
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("obtained: samples %ld\n", obt->samples);
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
snd_pcm_sw_params_t *sw_params;
|
|
|
|
|
|
|
|
snd_pcm_sw_params_alloca (&sw_params);
|
|
|
|
|
|
|
|
err = snd_pcm_sw_params_current (handle, sw_params);
|
|
|
|
if (err < 0) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("Could not fully initialize DAC\n");
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_logerr (err, "Failed to get current software parameters\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold);
|
|
|
|
if (err < 0) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("Could not fully initialize DAC\n");
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_logerr (err, "Failed to set software threshold to %ld\n",
|
|
|
|
threshold);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_sw_params (handle, sw_params);
|
|
|
|
if (err < 0) {
|
2005-11-05 21:55:28 +03:00
|
|
|
dolog ("Could not fully initialize DAC\n");
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_logerr (err, "Failed to set software parameters\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_open (int in, struct alsa_params_req *req,
|
|
|
|
struct alsa_params_obt *obt, snd_pcm_t **handlep)
|
|
|
|
{
|
|
|
|
snd_pcm_t *handle;
|
|
|
|
snd_pcm_hw_params_t *hw_params;
|
2007-12-16 06:02:09 +03:00
|
|
|
int err;
|
2008-06-21 21:14:57 +04:00
|
|
|
int size_in_usec;
|
2007-12-16 06:02:09 +03:00
|
|
|
unsigned int freq, nchannels;
|
2005-10-30 21:58:22 +03:00
|
|
|
const char *pcm_name = in ? conf.pcm_name_in : conf.pcm_name_out;
|
|
|
|
snd_pcm_uframes_t obt_buffer_size;
|
|
|
|
const char *typ = in ? "ADC" : "DAC";
|
2008-01-14 07:24:29 +03:00
|
|
|
snd_pcm_format_t obtfmt;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
freq = req->freq;
|
|
|
|
nchannels = req->nchannels;
|
2008-06-21 21:14:57 +04:00
|
|
|
size_in_usec = req->size_in_usec;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
snd_pcm_hw_params_alloca (&hw_params);
|
|
|
|
|
|
|
|
err = snd_pcm_open (
|
|
|
|
&handle,
|
|
|
|
pcm_name,
|
|
|
|
in ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
|
|
|
|
SND_PCM_NONBLOCK
|
|
|
|
);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to open `%s':\n", pcm_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_any (handle, hw_params);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to initialize hardware parameters\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_set_access (
|
|
|
|
handle,
|
|
|
|
hw_params,
|
|
|
|
SND_PCM_ACCESS_RW_INTERLEAVED
|
|
|
|
);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to set access type\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_set_format (handle, hw_params, req->fmt);
|
2008-01-14 07:24:29 +03:00
|
|
|
if (err < 0 && conf.verbose) {
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_logerr2 (err, typ, "Failed to set format %d\n", req->fmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_set_rate_near (handle, hw_params, &freq, 0);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to set frequency %d\n", req->freq);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_set_channels_near (
|
|
|
|
handle,
|
|
|
|
hw_params,
|
|
|
|
&nchannels
|
|
|
|
);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to set number of channels %d\n",
|
|
|
|
req->nchannels);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nchannels != 1 && nchannels != 2) {
|
|
|
|
alsa_logerr2 (err, typ,
|
|
|
|
"Can not handle obtained number of channels %d\n",
|
|
|
|
nchannels);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-06-21 21:14:57 +04:00
|
|
|
if (req->buffer_size) {
|
2008-06-22 00:09:32 +04:00
|
|
|
unsigned long obt;
|
|
|
|
|
2008-06-21 21:14:57 +04:00
|
|
|
if (size_in_usec) {
|
|
|
|
int dir = 0;
|
|
|
|
unsigned int btime = req->buffer_size;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
err = snd_pcm_hw_params_set_buffer_time_near (
|
|
|
|
handle,
|
|
|
|
hw_params,
|
2008-06-21 21:14:57 +04:00
|
|
|
&btime,
|
|
|
|
&dir
|
2005-11-05 21:55:28 +03:00
|
|
|
);
|
2008-06-22 00:09:32 +04:00
|
|
|
obt = btime;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-06-21 21:14:57 +04:00
|
|
|
snd_pcm_uframes_t bsize = req->buffer_size;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2008-06-21 21:14:57 +04:00
|
|
|
err = snd_pcm_hw_params_set_buffer_size_near (
|
|
|
|
handle,
|
|
|
|
hw_params,
|
|
|
|
&bsize
|
|
|
|
);
|
2008-06-22 00:09:32 +04:00
|
|
|
obt = bsize;
|
2008-06-21 21:14:57 +04:00
|
|
|
}
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to set buffer %s to %d\n",
|
|
|
|
size_in_usec ? "time" : "size", req->buffer_size);
|
|
|
|
goto err;
|
|
|
|
}
|
2008-06-22 00:09:32 +04:00
|
|
|
|
2008-07-09 23:25:28 +04:00
|
|
|
if ((req->override_mask & 2) && (obt - req->buffer_size))
|
2008-06-22 00:09:32 +04:00
|
|
|
dolog ("Requested buffer %s %u was rejected, using %lu\n",
|
|
|
|
size_in_usec ? "time" : "size", req->buffer_size, obt);
|
2008-06-21 21:14:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req->period_size) {
|
2008-06-22 00:09:32 +04:00
|
|
|
unsigned long obt;
|
|
|
|
|
2008-06-21 21:14:57 +04:00
|
|
|
if (size_in_usec) {
|
|
|
|
int dir = 0;
|
|
|
|
unsigned int ptime = req->period_size;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2008-06-21 21:14:57 +04:00
|
|
|
err = snd_pcm_hw_params_set_period_time_near (
|
|
|
|
handle,
|
2005-10-30 21:58:22 +03:00
|
|
|
hw_params,
|
2008-06-21 21:14:57 +04:00
|
|
|
&ptime,
|
|
|
|
&dir
|
2005-10-30 21:58:22 +03:00
|
|
|
);
|
2008-06-22 00:09:32 +04:00
|
|
|
obt = ptime;
|
2008-06-21 21:14:57 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-07-09 23:25:24 +04:00
|
|
|
int dir = 0;
|
2008-06-21 21:14:57 +04:00
|
|
|
snd_pcm_uframes_t psize = req->period_size;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2008-07-09 23:25:24 +04:00
|
|
|
err = snd_pcm_hw_params_set_period_size_near (
|
2005-10-30 21:58:22 +03:00
|
|
|
handle,
|
|
|
|
hw_params,
|
2008-07-09 23:25:24 +04:00
|
|
|
&psize,
|
|
|
|
&dir
|
2005-10-30 21:58:22 +03:00
|
|
|
);
|
2008-06-22 00:09:32 +04:00
|
|
|
obt = psize;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
2008-06-21 21:14:57 +04:00
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to set period %s to %d\n",
|
|
|
|
size_in_usec ? "time" : "size", req->period_size);
|
|
|
|
goto err;
|
|
|
|
}
|
2008-06-22 00:09:32 +04:00
|
|
|
|
2008-07-09 23:25:28 +04:00
|
|
|
if ((req->override_mask & 1) && (obt - req->period_size))
|
2008-06-22 00:09:32 +04:00
|
|
|
dolog ("Requested period %s %u was rejected, using %lu\n",
|
|
|
|
size_in_usec ? "time" : "size", req->period_size, obt);
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params (handle, hw_params);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to apply audio parameters\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = snd_pcm_hw_params_get_buffer_size (hw_params, &obt_buffer_size);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to get buffer size\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2008-01-14 07:24:29 +03:00
|
|
|
err = snd_pcm_hw_params_get_format (hw_params, &obtfmt);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr2 (err, typ, "Failed to get format\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alsa_to_audfmt (obtfmt, &obt->fmt, &obt->endianness)) {
|
|
|
|
dolog ("Invalid format was returned %d\n", obtfmt);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
err = snd_pcm_prepare (handle);
|
|
|
|
if (err < 0) {
|
2005-11-05 21:55:28 +03:00
|
|
|
alsa_logerr2 (err, typ, "Could not prepare handle %p\n", handle);
|
2005-10-30 21:58:22 +03:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in && conf.threshold) {
|
|
|
|
snd_pcm_uframes_t threshold;
|
|
|
|
int bytes_per_sec;
|
|
|
|
|
2008-01-14 07:24:29 +03:00
|
|
|
bytes_per_sec = freq << (nchannels == 2);
|
|
|
|
|
|
|
|
switch (obt->fmt) {
|
|
|
|
case AUD_FMT_S8:
|
|
|
|
case AUD_FMT_U8:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUD_FMT_S16:
|
|
|
|
case AUD_FMT_U16:
|
|
|
|
bytes_per_sec <<= 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUD_FMT_S32:
|
|
|
|
case AUD_FMT_U32:
|
|
|
|
bytes_per_sec <<= 2;
|
|
|
|
break;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
threshold = (conf.threshold * bytes_per_sec) / 1000;
|
|
|
|
alsa_set_threshold (handle, threshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
obt->nchannels = nchannels;
|
|
|
|
obt->freq = freq;
|
2005-11-05 21:55:28 +03:00
|
|
|
obt->samples = obt_buffer_size;
|
2008-01-14 07:24:29 +03:00
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
*handlep = handle;
|
|
|
|
|
2008-01-14 07:24:29 +03:00
|
|
|
if (conf.verbose &&
|
|
|
|
(obt->fmt != req->fmt ||
|
|
|
|
obt->nchannels != req->nchannels ||
|
|
|
|
obt->freq != req->freq)) {
|
|
|
|
dolog ("Audio paramters for %s\n", typ);
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_dump_info (req, obt);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
alsa_dump_info (req, obt);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
alsa_anal_close (&handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_recover (snd_pcm_t *handle)
|
|
|
|
{
|
|
|
|
int err = snd_pcm_prepare (handle);
|
|
|
|
if (err < 0) {
|
|
|
|
alsa_logerr (err, "Failed to prepare handle %p\n", handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
static snd_pcm_sframes_t alsa_get_avail (snd_pcm_t *handle)
|
|
|
|
{
|
|
|
|
snd_pcm_sframes_t avail;
|
|
|
|
|
|
|
|
avail = snd_pcm_avail_update (handle);
|
|
|
|
if (avail < 0) {
|
|
|
|
if (avail == -EPIPE) {
|
|
|
|
if (!alsa_recover (handle)) {
|
|
|
|
avail = snd_pcm_avail_update (handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (avail < 0) {
|
|
|
|
alsa_logerr (avail,
|
|
|
|
"Could not obtain number of available frames\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return avail;
|
|
|
|
}
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
static int alsa_run_out (HWVoiceOut *hw)
|
|
|
|
{
|
|
|
|
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
|
|
|
|
int rpos, live, decr;
|
|
|
|
int samples;
|
|
|
|
uint8_t *dst;
|
2008-12-04 01:48:44 +03:00
|
|
|
struct st_sample *src;
|
2005-10-30 21:58:22 +03:00
|
|
|
snd_pcm_sframes_t avail;
|
|
|
|
|
|
|
|
live = audio_pcm_hw_get_live_out (hw);
|
|
|
|
if (!live) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
avail = alsa_get_avail (alsa->handle);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (avail < 0) {
|
2005-11-20 19:24:34 +03:00
|
|
|
dolog ("Could not get number of available playback frames\n");
|
2005-10-30 21:58:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
decr = audio_MIN (live, avail);
|
|
|
|
samples = decr;
|
|
|
|
rpos = hw->rpos;
|
|
|
|
while (samples) {
|
|
|
|
int left_till_end_samples = hw->samples - rpos;
|
2005-11-20 19:24:34 +03:00
|
|
|
int len = audio_MIN (samples, left_till_end_samples);
|
2005-10-30 21:58:22 +03:00
|
|
|
snd_pcm_sframes_t written;
|
|
|
|
|
|
|
|
src = hw->mix_buf + rpos;
|
|
|
|
dst = advance (alsa->pcm_buf, rpos << hw->info.shift);
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
hw->clip (dst, src, len);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
while (len) {
|
|
|
|
written = snd_pcm_writei (alsa->handle, dst, len);
|
2005-11-11 03:06:10 +03:00
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
if (written <= 0) {
|
2005-11-11 03:06:10 +03:00
|
|
|
switch (written) {
|
2005-11-20 19:24:34 +03:00
|
|
|
case 0:
|
|
|
|
if (conf.verbose) {
|
|
|
|
dolog ("Failed to write %d frames (wrote zero)\n", len);
|
2005-11-11 03:06:10 +03:00
|
|
|
}
|
|
|
|
goto exit;
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
case -EPIPE:
|
|
|
|
if (alsa_recover (alsa->handle)) {
|
|
|
|
alsa_logerr (written, "Failed to write %d frames\n",
|
|
|
|
len);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (conf.verbose) {
|
|
|
|
dolog ("Recovering from playback xrun\n");
|
|
|
|
}
|
2005-11-11 03:06:10 +03:00
|
|
|
continue;
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
case -EAGAIN:
|
|
|
|
goto exit;
|
|
|
|
|
2005-11-11 03:06:10 +03:00
|
|
|
default:
|
|
|
|
alsa_logerr (written, "Failed to write %d frames to %p\n",
|
2005-11-20 19:24:34 +03:00
|
|
|
len, dst);
|
2005-11-11 03:06:10 +03:00
|
|
|
goto exit;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-11 03:06:10 +03:00
|
|
|
rpos = (rpos + written) % hw->samples;
|
|
|
|
samples -= written;
|
2005-11-20 19:24:34 +03:00
|
|
|
len -= written;
|
2005-11-11 03:06:10 +03:00
|
|
|
dst = advance (dst, written << hw->info.shift);
|
|
|
|
src += written;
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
hw->rpos = rpos;
|
|
|
|
return decr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_fini_out (HWVoiceOut *hw)
|
|
|
|
{
|
|
|
|
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
|
|
|
|
|
|
|
|
ldebug ("alsa_fini\n");
|
|
|
|
alsa_anal_close (&alsa->handle);
|
|
|
|
|
|
|
|
if (alsa->pcm_buf) {
|
|
|
|
qemu_free (alsa->pcm_buf);
|
|
|
|
alsa->pcm_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-04 01:48:44 +03:00
|
|
|
static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
|
|
|
|
struct alsa_params_req req;
|
|
|
|
struct alsa_params_obt obt;
|
|
|
|
snd_pcm_t *handle;
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings obt_as;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
req.fmt = aud_to_alsafmt (as->fmt);
|
|
|
|
req.freq = as->freq;
|
|
|
|
req.nchannels = as->nchannels;
|
2005-10-30 21:58:22 +03:00
|
|
|
req.period_size = conf.period_size_out;
|
|
|
|
req.buffer_size = conf.buffer_size_out;
|
2008-07-03 15:29:15 +04:00
|
|
|
req.size_in_usec = conf.size_in_usec_out;
|
2008-07-09 23:25:28 +04:00
|
|
|
req.override_mask = !!conf.period_size_out_overridden
|
|
|
|
| (!!conf.buffer_size_out_overridden << 1);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
if (alsa_open (0, &req, &obt, &handle)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
obt_as.freq = obt.freq;
|
|
|
|
obt_as.nchannels = obt.nchannels;
|
2008-01-14 07:24:29 +03:00
|
|
|
obt_as.fmt = obt.fmt;
|
|
|
|
obt_as.endianness = obt.endianness;
|
2005-11-05 21:55:28 +03:00
|
|
|
|
2006-07-05 01:47:22 +04:00
|
|
|
audio_pcm_init_info (&hw->info, &obt_as);
|
2005-11-05 21:55:28 +03:00
|
|
|
hw->samples = obt.samples;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (!alsa->pcm_buf) {
|
2005-11-11 03:06:10 +03:00
|
|
|
dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n",
|
|
|
|
hw->samples, 1 << hw->info.shift);
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_anal_close (&handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
alsa->handle = handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int pause)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
int err;
|
2005-11-20 19:24:34 +03:00
|
|
|
|
|
|
|
if (pause) {
|
|
|
|
err = snd_pcm_drop (handle);
|
|
|
|
if (err < 0) {
|
2005-11-20 21:53:05 +03:00
|
|
|
alsa_logerr (err, "Could not stop %s\n", typ);
|
2005-11-20 19:24:34 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
err = snd_pcm_prepare (handle);
|
|
|
|
if (err < 0) {
|
2005-11-20 21:53:05 +03:00
|
|
|
alsa_logerr (err, "Could not prepare handle for %s\n", typ);
|
2005-11-20 19:24:34 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
|
|
|
{
|
2005-10-30 21:58:22 +03:00
|
|
|
ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case VOICE_ENABLE:
|
|
|
|
ldebug ("enabling voice\n");
|
2005-11-20 19:24:34 +03:00
|
|
|
return alsa_voice_ctl (alsa->handle, "playback", 0);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
case VOICE_DISABLE:
|
|
|
|
ldebug ("disabling voice\n");
|
2005-11-20 19:24:34 +03:00
|
|
|
return alsa_voice_ctl (alsa->handle, "playback", 1);
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
2005-11-20 19:24:34 +03:00
|
|
|
|
|
|
|
return -1;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
2008-12-04 01:48:44 +03:00
|
|
|
static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as)
|
2005-10-30 21:58:22 +03:00
|
|
|
{
|
|
|
|
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
|
|
|
|
struct alsa_params_req req;
|
|
|
|
struct alsa_params_obt obt;
|
|
|
|
snd_pcm_t *handle;
|
2008-12-04 01:48:44 +03:00
|
|
|
struct audsettings obt_as;
|
2005-10-30 21:58:22 +03:00
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
req.fmt = aud_to_alsafmt (as->fmt);
|
|
|
|
req.freq = as->freq;
|
|
|
|
req.nchannels = as->nchannels;
|
2005-10-30 21:58:22 +03:00
|
|
|
req.period_size = conf.period_size_in;
|
|
|
|
req.buffer_size = conf.buffer_size_in;
|
2008-06-21 21:14:57 +04:00
|
|
|
req.size_in_usec = conf.size_in_usec_in;
|
2008-07-09 23:25:28 +04:00
|
|
|
req.override_mask = !!conf.period_size_in_overridden
|
|
|
|
| (!!conf.buffer_size_in_overridden << 1);
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
if (alsa_open (1, &req, &obt, &handle)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-05 21:55:28 +03:00
|
|
|
obt_as.freq = obt.freq;
|
|
|
|
obt_as.nchannels = obt.nchannels;
|
2008-01-14 07:24:29 +03:00
|
|
|
obt_as.fmt = obt.fmt;
|
|
|
|
obt_as.endianness = obt.endianness;
|
2005-11-05 21:55:28 +03:00
|
|
|
|
2006-07-05 01:47:22 +04:00
|
|
|
audio_pcm_init_info (&hw->info, &obt_as);
|
2005-11-05 21:55:28 +03:00
|
|
|
hw->samples = obt.samples;
|
|
|
|
|
|
|
|
alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
|
2005-10-30 21:58:22 +03:00
|
|
|
if (!alsa->pcm_buf) {
|
2005-11-11 03:06:10 +03:00
|
|
|
dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
|
|
|
|
hw->samples, 1 << hw->info.shift);
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_anal_close (&handle);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
alsa->handle = handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_fini_in (HWVoiceIn *hw)
|
|
|
|
{
|
|
|
|
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
|
|
|
|
|
|
|
|
alsa_anal_close (&alsa->handle);
|
|
|
|
|
|
|
|
if (alsa->pcm_buf) {
|
|
|
|
qemu_free (alsa->pcm_buf);
|
|
|
|
alsa->pcm_buf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_run_in (HWVoiceIn *hw)
|
|
|
|
{
|
|
|
|
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
|
|
|
|
int hwshift = hw->info.shift;
|
|
|
|
int i;
|
|
|
|
int live = audio_pcm_hw_get_live_in (hw);
|
|
|
|
int dead = hw->samples - live;
|
2005-11-20 19:24:34 +03:00
|
|
|
int decr;
|
2005-10-30 21:58:22 +03:00
|
|
|
struct {
|
|
|
|
int add;
|
|
|
|
int len;
|
|
|
|
} bufs[2] = {
|
|
|
|
{ hw->wpos, 0 },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
2005-11-20 19:24:34 +03:00
|
|
|
snd_pcm_sframes_t avail;
|
2005-10-30 21:58:22 +03:00
|
|
|
snd_pcm_uframes_t read_samples = 0;
|
|
|
|
|
|
|
|
if (!dead) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
avail = alsa_get_avail (alsa->handle);
|
|
|
|
if (avail < 0) {
|
|
|
|
dolog ("Could not get number of captured frames\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!avail && (snd_pcm_state (alsa->handle) == SND_PCM_STATE_PREPARED)) {
|
|
|
|
avail = hw->samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
decr = audio_MIN (dead, avail);
|
|
|
|
if (!decr) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hw->wpos + decr > hw->samples) {
|
2005-10-30 21:58:22 +03:00
|
|
|
bufs[0].len = (hw->samples - hw->wpos);
|
2005-11-20 19:24:34 +03:00
|
|
|
bufs[1].len = (decr - (hw->samples - hw->wpos));
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2005-11-20 19:24:34 +03:00
|
|
|
bufs[0].len = decr;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; ++i) {
|
|
|
|
void *src;
|
2008-12-04 01:48:44 +03:00
|
|
|
struct st_sample *dst;
|
2005-10-30 21:58:22 +03:00
|
|
|
snd_pcm_sframes_t nread;
|
|
|
|
snd_pcm_uframes_t len;
|
|
|
|
|
|
|
|
len = bufs[i].len;
|
|
|
|
|
|
|
|
src = advance (alsa->pcm_buf, bufs[i].add << hwshift);
|
|
|
|
dst = hw->conv_buf + bufs[i].add;
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
nread = snd_pcm_readi (alsa->handle, src, len);
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
if (nread <= 0) {
|
2005-10-30 21:58:22 +03:00
|
|
|
switch (nread) {
|
2005-11-20 19:24:34 +03:00
|
|
|
case 0:
|
|
|
|
if (conf.verbose) {
|
|
|
|
dolog ("Failed to read %ld frames (read zero)\n", len);
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
goto exit;
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
case -EPIPE:
|
|
|
|
if (alsa_recover (alsa->handle)) {
|
|
|
|
alsa_logerr (nread, "Failed to read %ld frames\n", len);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (conf.verbose) {
|
|
|
|
dolog ("Recovering from capture xrun\n");
|
|
|
|
}
|
2005-10-30 21:58:22 +03:00
|
|
|
continue;
|
|
|
|
|
2005-11-20 19:24:34 +03:00
|
|
|
case -EAGAIN:
|
|
|
|
goto exit;
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
default:
|
|
|
|
alsa_logerr (
|
|
|
|
nread,
|
|
|
|
"Failed to read %ld frames from %p\n",
|
|
|
|
len,
|
|
|
|
src
|
|
|
|
);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hw->conv (dst, src, nread, &nominal_volume);
|
|
|
|
|
|
|
|
src = advance (src, nread << hwshift);
|
|
|
|
dst += nread;
|
|
|
|
|
|
|
|
read_samples += nread;
|
|
|
|
len -= nread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
hw->wpos = (hw->wpos + read_samples) % hw->samples;
|
|
|
|
return read_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_read (SWVoiceIn *sw, void *buf, int size)
|
|
|
|
{
|
|
|
|
return audio_pcm_sw_read (sw, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
|
|
|
|
{
|
2005-11-20 19:24:34 +03:00
|
|
|
ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case VOICE_ENABLE:
|
|
|
|
ldebug ("enabling voice\n");
|
|
|
|
return alsa_voice_ctl (alsa->handle, "capture", 0);
|
|
|
|
|
|
|
|
case VOICE_DISABLE:
|
|
|
|
ldebug ("disabling voice\n");
|
|
|
|
return alsa_voice_ctl (alsa->handle, "capture", 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2005-10-30 21:58:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *alsa_audio_init (void)
|
|
|
|
{
|
|
|
|
return &conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alsa_audio_fini (void *opaque)
|
|
|
|
{
|
|
|
|
(void) opaque;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct audio_option alsa_options[] = {
|
|
|
|
{"DAC_SIZE_IN_USEC", AUD_OPT_BOOL, &conf.size_in_usec_out,
|
|
|
|
"DAC period/buffer size in microseconds (otherwise in frames)", NULL, 0},
|
|
|
|
{"DAC_PERIOD_SIZE", AUD_OPT_INT, &conf.period_size_out,
|
2008-06-21 21:14:57 +04:00
|
|
|
"DAC period size (0 to go with system default)",
|
|
|
|
&conf.period_size_out_overridden, 0},
|
2005-10-30 21:58:22 +03:00
|
|
|
{"DAC_BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_size_out,
|
2008-06-21 21:14:57 +04:00
|
|
|
"DAC buffer size (0 to go with system default)",
|
|
|
|
&conf.buffer_size_out_overridden, 0},
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
{"ADC_SIZE_IN_USEC", AUD_OPT_BOOL, &conf.size_in_usec_in,
|
|
|
|
"ADC period/buffer size in microseconds (otherwise in frames)", NULL, 0},
|
|
|
|
{"ADC_PERIOD_SIZE", AUD_OPT_INT, &conf.period_size_in,
|
2008-06-21 21:14:57 +04:00
|
|
|
"ADC period size (0 to go with system default)",
|
|
|
|
&conf.period_size_in_overridden, 0},
|
2005-10-30 21:58:22 +03:00
|
|
|
{"ADC_BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_size_in,
|
2008-06-21 21:14:57 +04:00
|
|
|
"ADC buffer size (0 to go with system default)",
|
|
|
|
&conf.buffer_size_in_overridden, 0},
|
2005-10-30 21:58:22 +03:00
|
|
|
|
|
|
|
{"THRESHOLD", AUD_OPT_INT, &conf.threshold,
|
|
|
|
"(undocumented)", NULL, 0},
|
|
|
|
|
|
|
|
{"DAC_DEV", AUD_OPT_STR, &conf.pcm_name_out,
|
|
|
|
"DAC device name (for instance dmix)", NULL, 0},
|
|
|
|
|
|
|
|
{"ADC_DEV", AUD_OPT_STR, &conf.pcm_name_in,
|
|
|
|
"ADC device name", NULL, 0},
|
2005-11-20 19:24:34 +03:00
|
|
|
|
|
|
|
{"VERBOSE", AUD_OPT_BOOL, &conf.verbose,
|
|
|
|
"Behave in a more verbose way", NULL, 0},
|
|
|
|
|
2005-10-30 21:58:22 +03:00
|
|
|
{NULL, 0, NULL, NULL, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2008-10-06 22:08:30 +04:00
|
|
|
static struct audio_pcm_ops alsa_pcm_ops = {
|
2005-10-30 21:58:22 +03:00
|
|
|
alsa_init_out,
|
|
|
|
alsa_fini_out,
|
|
|
|
alsa_run_out,
|
|
|
|
alsa_write,
|
|
|
|
alsa_ctl_out,
|
|
|
|
|
|
|
|
alsa_init_in,
|
|
|
|
alsa_fini_in,
|
|
|
|
alsa_run_in,
|
|
|
|
alsa_read,
|
|
|
|
alsa_ctl_in
|
|
|
|
};
|
|
|
|
|
|
|
|
struct audio_driver alsa_audio_driver = {
|
|
|
|
INIT_FIELD (name = ) "alsa",
|
|
|
|
INIT_FIELD (descr = ) "ALSA http://www.alsa-project.org",
|
|
|
|
INIT_FIELD (options = ) alsa_options,
|
|
|
|
INIT_FIELD (init = ) alsa_audio_init,
|
|
|
|
INIT_FIELD (fini = ) alsa_audio_fini,
|
|
|
|
INIT_FIELD (pcm_ops = ) &alsa_pcm_ops,
|
|
|
|
INIT_FIELD (can_be_default = ) 1,
|
|
|
|
INIT_FIELD (max_voices_out = ) INT_MAX,
|
|
|
|
INIT_FIELD (max_voices_in = ) INT_MAX,
|
|
|
|
INIT_FIELD (voice_size_out = ) sizeof (ALSAVoiceOut),
|
|
|
|
INIT_FIELD (voice_size_in = ) sizeof (ALSAVoiceIn)
|
|
|
|
};
|