Merged pcmfinal branch.

This commit is contained in:
Jaroslav Kysela 2000-11-20 20:10:46 +00:00
parent 3cc2b957fb
commit 41bb7068f2
57 changed files with 5189 additions and 3088 deletions

View file

@ -69,8 +69,6 @@ typedef struct {
int getput_idx;
adpcm_f func;
int sformat;
int cformat;
int cxfer_mode, cmmap_shape;
adpcm_state_t *states;
} snd_pcm_adpcm_t;
@ -331,102 +329,82 @@ static int snd_pcm_adpcm_close(snd_pcm_t *pcm)
return 0;
}
static int snd_pcm_adpcm_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t * info)
static int snd_pcm_adpcm_hw_info(snd_pcm_t *pcm, snd_pcm_hw_info_t * info)
{
snd_pcm_adpcm_t *adpcm = pcm->private;
unsigned int req_mask = info->req_mask;
unsigned int sfmt = info->req.format.sfmt;
unsigned int format_mask, access_mask;
int err;
if (req_mask & SND_PCM_PARAMS_SFMT) {
if (adpcm->sformat == SND_PCM_SFMT_IMA_ADPCM ?
!snd_pcm_format_linear(sfmt) :
sfmt != SND_PCM_SFMT_IMA_ADPCM) {
info->req.fail_mask = SND_PCM_PARAMS_SFMT;
info->req.fail_reason = SND_PCM_PARAMS_FAIL_INVAL;
return -EINVAL;
}
info->access_mask &= (SND_PCM_ACCBIT_MMAP_INTERLEAVED |
SND_PCM_ACCBIT_RW_INTERLEAVED |
SND_PCM_ACCBIT_MMAP_NONINTERLEAVED |
SND_PCM_ACCBIT_RW_NONINTERLEAVED);
access_mask = info->access_mask;
if (access_mask == 0)
return -EINVAL;
if (adpcm->sformat == SND_PCM_FORMAT_IMA_ADPCM)
info->format_mask &= SND_PCM_FMTBIT_LINEAR;
else
info->format_mask &= SND_PCM_FMTBIT_IMA_ADPCM;
format_mask = info->format_mask;
if (format_mask == 0)
return -EINVAL;
info->format_mask = 1U << adpcm->sformat;
info->access_mask = SND_PCM_ACCBIT_MMAP;
err = snd_pcm_hw_info(adpcm->plug.slave, info);
if (info->format_mask)
info->format_mask = format_mask;
if (info->access_mask) {
adpcm->plug.saccess_mask = info->access_mask;
info->access_mask = access_mask;
}
info->req_mask |= SND_PCM_PARAMS_SFMT;
info->req_mask &= ~(SND_PCM_PARAMS_MMAP_SHAPE |
SND_PCM_PARAMS_XFER_MODE);
info->req.format.sfmt = adpcm->sformat;
err = snd_pcm_params_info(adpcm->plug.slave, info);
info->req_mask = req_mask;
info->req.format.sfmt = sfmt;
if (err < 0)
return err;
if (req_mask & SND_PCM_PARAMS_SFMT)
info->formats = 1 << sfmt;
else
info->formats = adpcm->sformat == SND_PCM_SFMT_IMA_ADPCM ?
SND_PCM_LINEAR_FORMATS : 1 << SND_PCM_SFMT_IMA_ADPCM;
info->flags &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
info->flags |= SND_PCM_INFO_INTERLEAVED | SND_PCM_INFO_NONINTERLEAVED;
return err;
info->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
snd_pcm_hw_info_complete(info);
return 0;
}
static int snd_pcm_adpcm_params(snd_pcm_t *pcm, snd_pcm_params_t * params)
static int snd_pcm_adpcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
{
snd_pcm_adpcm_t *adpcm = pcm->private;
snd_pcm_t *slave = adpcm->plug.slave;
unsigned int format, access;
int err;
if (adpcm->sformat == SND_PCM_SFMT_IMA_ADPCM ?
!snd_pcm_format_linear(params->format.sfmt) :
params->format.sfmt != SND_PCM_SFMT_IMA_ADPCM) {
params->fail_mask = SND_PCM_PARAMS_SFMT;
params->fail_reason = SND_PCM_PARAMS_FAIL_INVAL;
return -EINVAL;
}
adpcm->cformat = params->format.sfmt;
adpcm->cxfer_mode = params->xfer_mode;
adpcm->cmmap_shape = params->mmap_shape;
params->format.sfmt = adpcm->sformat;
params->xfer_mode = SND_PCM_XFER_UNSPECIFIED;
params->mmap_shape = SND_PCM_MMAP_UNSPECIFIED;
err = snd_pcm_params_mmap(slave, params);
params->format.sfmt = adpcm->cformat;
params->xfer_mode = adpcm->cxfer_mode;
params->mmap_shape = adpcm->cmmap_shape;
return err;
}
static int snd_pcm_adpcm_setup(snd_pcm_t *pcm, snd_pcm_setup_t * setup)
{
snd_pcm_adpcm_t *adpcm = pcm->private;
int err = snd_pcm_setup(adpcm->plug.slave, setup);
format = params->format;
access = params->access;
params->format = adpcm->sformat;
if (adpcm->plug.saccess_mask & SND_PCM_ACCBIT_MMAP_INTERLEAVED)
params->access = SND_PCM_ACCESS_MMAP_INTERLEAVED;
else if (adpcm->plug.saccess_mask & SND_PCM_ACCBIT_MMAP_NONINTERLEAVED)
params->access = SND_PCM_ACCESS_MMAP_NONINTERLEAVED;
else
assert(0);
err = snd_pcm_hw_params(slave, params);
params->format = format;
params->access = access;
if (err < 0)
return err;
assert(adpcm->sformat == setup->format.sfmt);
if (adpcm->cxfer_mode == SND_PCM_XFER_UNSPECIFIED)
setup->xfer_mode = SND_PCM_XFER_NONINTERLEAVED;
else
setup->xfer_mode = adpcm->cxfer_mode;
if (adpcm->cmmap_shape == SND_PCM_MMAP_UNSPECIFIED)
setup->mmap_shape = SND_PCM_MMAP_NONINTERLEAVED;
else
setup->mmap_shape = adpcm->cmmap_shape;
setup->format.sfmt = adpcm->cformat;
setup->mmap_bytes = 0;
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
if (adpcm->sformat == SND_PCM_SFMT_IMA_ADPCM) {
adpcm->getput_idx = get_index(adpcm->cformat, SND_PCM_SFMT_S16);
if (adpcm->sformat == SND_PCM_FORMAT_IMA_ADPCM) {
adpcm->getput_idx = get_index(format, SND_PCM_FORMAT_S16);
adpcm->func = adpcm_encode;
} else {
adpcm->getput_idx = put_index(SND_PCM_SFMT_S16, adpcm->sformat);
adpcm->getput_idx = put_index(SND_PCM_FORMAT_S16, adpcm->sformat);
adpcm->func = adpcm_decode;
}
} else {
if (adpcm->sformat == SND_PCM_SFMT_IMA_ADPCM) {
adpcm->getput_idx = put_index(SND_PCM_SFMT_S16, adpcm->cformat);
if (adpcm->sformat == SND_PCM_FORMAT_IMA_ADPCM) {
adpcm->getput_idx = put_index(SND_PCM_FORMAT_S16, format);
adpcm->func = adpcm_decode;
} else {
adpcm->getput_idx = get_index(adpcm->sformat, SND_PCM_SFMT_S16);
adpcm->getput_idx = get_index(adpcm->sformat, SND_PCM_FORMAT_S16);
adpcm->func = adpcm_encode;
}
}
if (adpcm->states)
free(adpcm->states);
adpcm->states = malloc(setup->format.channels * sizeof(*adpcm->states));
adpcm->states = malloc(params->channels * sizeof(*adpcm->states));
return 0;
}
@ -434,7 +412,7 @@ static int snd_pcm_adpcm_init(snd_pcm_t *pcm)
{
snd_pcm_adpcm_t *adpcm = pcm->private;
unsigned int k;
for (k = 0; k < pcm->setup.format.channels; ++k) {
for (k = 0; k < pcm->channels; ++k) {
adpcm->states[k].pred_val = 0;
adpcm->states[k].step_idx = 0;
}
@ -458,7 +436,7 @@ static ssize_t snd_pcm_adpcm_write_areas(snd_pcm_t *pcm,
size_t frames = snd_pcm_mmap_playback_xfer(slave, size - xfer);
adpcm->func(areas, offset,
snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
frames, pcm->setup.format.channels,
frames, pcm->channels,
adpcm->getput_idx, adpcm->states);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
@ -493,7 +471,7 @@ static ssize_t snd_pcm_adpcm_read_areas(snd_pcm_t *pcm,
size_t frames = snd_pcm_mmap_capture_xfer(slave, size - xfer);
adpcm->func(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
areas, offset,
frames, pcm->setup.format.channels,
frames, pcm->channels,
adpcm->getput_idx, adpcm->states);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
@ -516,7 +494,7 @@ static void snd_pcm_adpcm_dump(snd_pcm_t *pcm, FILE *fp)
snd_pcm_adpcm_t *adpcm = pcm->private;
fprintf(fp, "Ima-ADPCM conversion PCM (%s)\n",
snd_pcm_format_name(adpcm->sformat));
if (pcm->valid_setup) {
if (pcm->setup) {
fprintf(fp, "Its setup is:\n");
snd_pcm_dump_setup(pcm, fp);
}
@ -527,12 +505,12 @@ static void snd_pcm_adpcm_dump(snd_pcm_t *pcm, FILE *fp)
snd_pcm_ops_t snd_pcm_adpcm_ops = {
close: snd_pcm_adpcm_close,
info: snd_pcm_plugin_info,
params_info: snd_pcm_adpcm_params_info,
params: snd_pcm_adpcm_params,
setup: snd_pcm_adpcm_setup,
hw_info: snd_pcm_adpcm_hw_info,
hw_params: snd_pcm_adpcm_hw_params,
sw_params: snd_pcm_plugin_sw_params,
dig_info: snd_pcm_plugin_dig_info,
dig_params: snd_pcm_plugin_dig_params,
channel_info: snd_pcm_plugin_channel_info,
channel_params: snd_pcm_plugin_channel_params,
channel_setup: snd_pcm_plugin_channel_setup,
dump: snd_pcm_adpcm_dump,
nonblock: snd_pcm_plugin_nonblock,
async: snd_pcm_plugin_async,
@ -546,7 +524,7 @@ int snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name, int sformat, snd_pcm_t *sla
snd_pcm_adpcm_t *adpcm;
assert(pcmp && slave);
if (snd_pcm_format_linear(sformat) != 1 &&
sformat != SND_PCM_SFMT_IMA_ADPCM)
sformat != SND_PCM_FORMAT_IMA_ADPCM)
return -EINVAL;
adpcm = calloc(1, sizeof(snd_pcm_adpcm_t));
if (!adpcm) {
@ -614,7 +592,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name,
if (sformat < 0)
return -EINVAL;
if (snd_pcm_format_linear(sformat) != 1 &&
sformat != SND_PCM_SFMT_IMA_ADPCM)
sformat != SND_PCM_FORMAT_IMA_ADPCM)
return -EINVAL;
continue;
}