Merged pcm2 branch.

This commit is contained in:
Jaroslav Kysela 2000-05-08 18:53:38 +00:00
parent 986c1500d2
commit 1cd6778173
40 changed files with 5053 additions and 3045 deletions

View file

@ -19,6 +19,15 @@
*
*/
#ifdef __KERNEL__
#include "../../include/driver.h"
#include "../../include/pcm.h"
#include "../../include/pcm_plugin.h"
#define snd_pcm_write(handle,buf,count) snd_pcm_oss_write3(handle,buf,count,1)
#define snd_pcm_writev(handle,vec,count) snd_pcm_oss_writev3(handle,vec,count,1)
#define snd_pcm_read(handle,buf,count) snd_pcm_oss_read3(handle,buf,count,1)
#define snd_pcm_readv(handle,vec,count) snd_pcm_oss_readv3(handle,vec,count,1)
#else
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -26,18 +35,19 @@
#include <errno.h>
#include <sys/uio.h>
#include "../pcm_local.h"
#endif
/*
* Basic block plugin
*/
typedef struct block_private_data {
int channel;
snd_pcm_plugin_handle_t *slave;
} block_t;
static ssize_t block_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_voice_t *src_voices,
const snd_pcm_plugin_voice_t *dst_voices,
snd_pcm_plugin_voice_t *dst_voices,
size_t samples)
{
block_t *data;
@ -51,40 +61,50 @@ static ssize_t block_transfer(snd_pcm_plugin_t *plugin,
if (data == NULL)
return -EINVAL;
vec = (struct iovec *)((char *)data + sizeof(*data));
if (data->channel == SND_PCM_CHANNEL_PLAYBACK) {
if (plugin->channel == SND_PCM_CHANNEL_PLAYBACK) {
if (src_voices == NULL)
return -EINVAL;
if ((result = snd_pcm_plugin_src_samples_to_size(plugin, samples)) < 0)
return result;
count = plugin->src_format.voices;
if (plugin->src_format.interleave) {
result = snd_pcm_write(plugin->handle, src_voices->addr, result);
result = snd_pcm_write(data->slave, src_voices->addr, result);
} else {
count = plugin->src_format.voices;
result /= count;
for (voice = 0; voice < count; voice++) {
vec[voice].iov_base = src_voices[voice].addr;
if (src_voices[voice].enabled)
vec[voice].iov_base = src_voices[voice].addr;
else
vec[voice].iov_base = 0;
vec[voice].iov_len = result;
}
result = snd_pcm_writev(plugin->handle, vec, count);
result = snd_pcm_writev(data->slave, vec, count);
}
if (result < 0)
return result;
return snd_pcm_plugin_src_size_to_samples(plugin, result);
} else if (data->channel == SND_PCM_CHANNEL_CAPTURE) {
} else if (plugin->channel == SND_PCM_CHANNEL_CAPTURE) {
if (dst_voices == NULL)
return -EINVAL;
if ((result = snd_pcm_plugin_dst_samples_to_size(plugin, samples)) < 0)
return result;
count = plugin->dst_format.voices;
if (plugin->dst_format.interleave) {
result = snd_pcm_read(plugin->handle, dst_voices->addr, result);
result = snd_pcm_read(data->slave, dst_voices->addr, result);
for (voice = 0; voice < count; voice++) {
dst_voices[voice].enabled = src_voices[voice].enabled;
}
} else {
count = plugin->dst_format.voices;
result /= count;
for (voice = 0; voice < count; voice++) {
vec[voice].iov_base = dst_voices[voice].addr;
dst_voices[voice].enabled = src_voices[voice].enabled;
if (dst_voices[voice].enabled)
vec[voice].iov_base = dst_voices[voice].addr;
else
vec[voice].iov_base = 0;
vec[voice].iov_len = result;
}
result = snd_pcm_readv(plugin->handle, vec, count);
result = snd_pcm_readv(data->slave, vec, count);
}
if (result < 0)
return result;
@ -94,29 +114,49 @@ static ssize_t block_transfer(snd_pcm_plugin_t *plugin,
}
}
int snd_pcm_plugin_build_block(snd_pcm_t *pcm, int channel,
static int block_src_voices(snd_pcm_plugin_t *plugin,
size_t samples,
snd_pcm_plugin_voice_t **voices)
{
int err;
unsigned int voice;
snd_pcm_plugin_voice_t *v;
err = snd_pcm_plugin_client_voices(plugin, samples, &v);
if (err < 0)
return err;
*voices = v;
for (voice = 0; voice < plugin->src_format.voices; ++voice, ++v)
v->wanted = 1;
return 0;
}
int snd_pcm_plugin_build_block(snd_pcm_plugin_handle_t *pcm,
int channel,
snd_pcm_plugin_handle_t *slave,
snd_pcm_format_t *format,
snd_pcm_plugin_t **r_plugin)
{
int err;
block_t *data;
snd_pcm_plugin_t *plugin;
if (r_plugin == NULL)
return -EINVAL;
*r_plugin = NULL;
if (pcm == NULL || channel < 0 || channel > 1 || format == NULL)
if (pcm == NULL || format == NULL)
return -EINVAL;
plugin = snd_pcm_plugin_build(pcm,
channel == SND_PCM_CHANNEL_PLAYBACK ?
"I/O block playback" :
"I/O block capture",
format, format,
sizeof(block_t) + sizeof(struct iovec) * format->voices);
if (plugin == NULL)
return -ENOMEM;
err = snd_pcm_plugin_build(pcm, channel,
"I/O block",
format, format,
sizeof(block_t) + sizeof(struct iovec) * format->voices,
&plugin);
if (err < 0)
return err;
data = (block_t *)plugin->extra_data;
data->channel = channel;
data->slave = slave;
plugin->transfer = block_transfer;
if (format->interleave && channel == SND_PCM_CHANNEL_PLAYBACK)
plugin->client_voices = block_src_voices;
*r_plugin = plugin;
return 0;
}