#include "pcm_local.h"
#include "pcm_plugin.h"
-typedef struct {
- int pred_val; /* Calculated predicted value */
- int step_idx; /* Previous StepSize lookup index */
-} adpcm_state_t;
-
typedef void (*adpcm_f)(const snd_pcm_channel_area_t *src_areas,
snd_pcm_uframes_t src_offset,
const snd_pcm_channel_area_t *dst_areas,
snd_pcm_uframes_t dst_offset,
unsigned int channels, snd_pcm_uframes_t frames, int getputidx,
- adpcm_state_t *states);
+ snd_pcm_adpcm_state_t *states);
typedef struct {
/* This field need to be the first */
int getput_idx;
adpcm_f func;
int sformat;
- adpcm_state_t *states;
+ snd_pcm_adpcm_state_t *states;
} snd_pcm_adpcm_t;
/* First table lookup for Ima-ADPCM quantizer */
15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
};
-static char adpcm_encoder(int sl, adpcm_state_t * state)
+static char adpcm_encoder(int sl, snd_pcm_adpcm_state_t * state)
{
short diff; /* Difference between sl and predicted sample */
short pred_diff; /* Predicted difference to next sample */
}
-static int adpcm_decoder(unsigned char code, adpcm_state_t * state)
+static int adpcm_decoder(unsigned char code, snd_pcm_adpcm_state_t * state)
{
short pred_diff; /* Predicted difference to next sample */
short step; /* holds previous StepSize value */
return (state->pred_val);
}
-static void adpcm_decode(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset,
- unsigned int channels, snd_pcm_uframes_t frames, int putidx,
- adpcm_state_t *states)
+void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx,
+ snd_pcm_adpcm_state_t *states)
{
#define PUT16_LABELS
#include "plugin_ops.h"
}
}
-static void adpcm_encode(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset,
- unsigned int channels, snd_pcm_uframes_t frames, int getidx,
- adpcm_state_t *states)
+void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int getidx,
+ snd_pcm_adpcm_state_t *states)
{
#define GET16_LABELS
#include "plugin_ops.h"
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
if (adpcm->sformat == SND_PCM_FORMAT_IMA_ADPCM) {
- adpcm->getput_idx = get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
- adpcm->func = adpcm_encode;
+ adpcm->getput_idx = snd_pcm_linear_get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
+ adpcm->func = snd_pcm_adpcm_encode;
} else {
- adpcm->getput_idx = put_index(SND_PCM_FORMAT_S16, adpcm->sformat);
- adpcm->func = adpcm_decode;
+ adpcm->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, adpcm->sformat);
+ adpcm->func = snd_pcm_adpcm_decode;
}
} else {
if (adpcm->sformat == SND_PCM_FORMAT_IMA_ADPCM) {
- adpcm->getput_idx = put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
- adpcm->func = adpcm_decode;
+ adpcm->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
+ adpcm->func = snd_pcm_adpcm_decode;
} else {
- adpcm->getput_idx = get_index(adpcm->sformat, SND_PCM_FORMAT_S16);
- adpcm->func = adpcm_encode;
+ adpcm->getput_idx = snd_pcm_linear_get_index(adpcm->sformat, SND_PCM_FORMAT_S16);
+ adpcm->func = snd_pcm_adpcm_encode;
}
}
assert(!adpcm->states);
return ((a_val & 0x80) ? t : -t);
}
-static void alaw_decode(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset,
- unsigned int channels, snd_pcm_uframes_t frames, int putidx)
+void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx)
{
#define PUT16_LABELS
#include "plugin_ops.h"
}
}
-static void alaw_encode(const snd_pcm_channel_area_t *src_areas,
+void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *src_areas,
snd_pcm_uframes_t src_offset,
const snd_pcm_channel_area_t *dst_areas,
snd_pcm_uframes_t dst_offset,
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
if (alaw->sformat == SND_PCM_FORMAT_A_LAW) {
- alaw->getput_idx = get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
- alaw->func = alaw_encode;
+ alaw->getput_idx = snd_pcm_linear_get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
+ alaw->func = snd_pcm_alaw_encode;
} else {
- alaw->getput_idx = put_index(SND_PCM_FORMAT_S16, alaw->sformat);
- alaw->func = alaw_decode;
+ alaw->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, alaw->sformat);
+ alaw->func = snd_pcm_alaw_decode;
}
} else {
if (alaw->sformat == SND_PCM_FORMAT_A_LAW) {
- alaw->getput_idx = put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
- alaw->func = alaw_decode;
+ alaw->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
+ alaw->func = snd_pcm_alaw_decode;
} else {
- alaw->getput_idx = get_index(alaw->sformat, SND_PCM_FORMAT_S16);
- alaw->func = alaw_encode;
+ alaw->getput_idx = snd_pcm_linear_get_index(alaw->sformat, SND_PCM_FORMAT_S16);
+ alaw->func = snd_pcm_alaw_encode;
}
}
return 0;
int sformat;
} snd_pcm_linear_t;
-static void linear_transfer(const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
+int snd_pcm_linear_convert_index(int src_format, int dst_format)
+{
+ int src_endian, dst_endian, sign, src_width, dst_width;
+
+ sign = (snd_pcm_format_signed(src_format) !=
+ snd_pcm_format_signed(dst_format));
+#ifdef SND_LITTLE_ENDIAN
+ src_endian = snd_pcm_format_big_endian(src_format);
+ dst_endian = snd_pcm_format_big_endian(dst_format);
+#else
+ src_endian = snd_pcm_format_little_endian(src_format);
+ dst_endian = snd_pcm_format_little_endian(dst_format);
+#endif
+
+ if (src_endian < 0)
+ src_endian = 0;
+ if (dst_endian < 0)
+ dst_endian = 0;
+
+ src_width = snd_pcm_format_width(src_format) / 8 - 1;
+ dst_width = snd_pcm_format_width(dst_format) / 8 - 1;
+
+ return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
+}
+
+int snd_pcm_linear_get_index(int src_format, int dst_format)
+{
+ int sign, width, endian;
+ sign = (snd_pcm_format_signed(src_format) !=
+ snd_pcm_format_signed(dst_format));
+ width = snd_pcm_format_width(src_format) / 8 - 1;
+#ifdef SND_LITTLE_ENDIAN
+ endian = snd_pcm_format_big_endian(src_format);
+#else
+ endian = snd_pcm_format_little_endian(src_format);
+#endif
+ if (endian < 0)
+ endian = 0;
+ return width * 4 + endian * 2 + sign;
+}
+
+int snd_pcm_linear_put_index(int src_format, int dst_format)
+{
+ int sign, width, endian;
+ sign = (snd_pcm_format_signed(src_format) !=
+ snd_pcm_format_signed(dst_format));
+ width = snd_pcm_format_width(dst_format) / 8 - 1;
+#ifdef SND_LITTLE_ENDIAN
+ endian = snd_pcm_format_big_endian(dst_format);
+#else
+ endian = snd_pcm_format_little_endian(dst_format);
+#endif
+ if (endian < 0)
+ endian = 0;
+ return width * 4 + endian * 2 + sign;
+}
+
+void snd_pcm_linear_convert(const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
unsigned int channels, snd_pcm_uframes_t frames, int convidx)
{
if (err < 0)
return err;
if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
- linear->conv_idx = conv_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0),
- linear->sformat);
+ linear->conv_idx = snd_pcm_linear_convert_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0),
+ linear->sformat);
else
- linear->conv_idx = conv_index(linear->sformat,
- snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
+ linear->conv_idx = snd_pcm_linear_convert_index(linear->sformat,
+ snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
return 0;
}
assert(size > 0);
while (xfer < size) {
snd_pcm_uframes_t frames = snd_pcm_mmap_playback_xfer(slave, size - xfer);
- linear_transfer(areas, offset,
- snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
- pcm->channels, frames, linear->conv_idx);
+ snd_pcm_linear_convert(areas, offset,
+ snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
+ pcm->channels, frames, linear->conv_idx);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
break;
assert(size > 0);
while (xfer < size) {
snd_pcm_uframes_t frames = snd_pcm_mmap_capture_xfer(slave, size - xfer);
- linear_transfer(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
- areas, offset,
- pcm->channels, frames, linear->conv_idx);
+ snd_pcm_linear_convert(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
+ areas, offset,
+ pcm->channels, frames, linear->conv_idx);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
break;
return ((u_val & 0x80) ? (0x84 - t) : (t - 0x84));
}
-static void mulaw_decode(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset,
- unsigned int channels, snd_pcm_uframes_t frames, int putidx)
+void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx)
{
#define PUT16_LABELS
#include "plugin_ops.h"
}
}
-static void mulaw_encode(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset,
- unsigned int channels, snd_pcm_uframes_t frames, int getidx)
+void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int getidx)
{
#define GET16_LABELS
#include "plugin_ops.h"
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
if (mulaw->sformat == SND_PCM_FORMAT_MU_LAW) {
- mulaw->getput_idx = get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
- mulaw->func = mulaw_encode;
+ mulaw->getput_idx = snd_pcm_linear_get_index(snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0), SND_PCM_FORMAT_S16);
+ mulaw->func = snd_pcm_mulaw_encode;
} else {
- mulaw->getput_idx = put_index(SND_PCM_FORMAT_S16, mulaw->sformat);
- mulaw->func = mulaw_decode;
+ mulaw->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, mulaw->sformat);
+ mulaw->func = snd_pcm_mulaw_decode;
}
} else {
if (mulaw->sformat == SND_PCM_FORMAT_MU_LAW) {
- mulaw->getput_idx = put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
- mulaw->func = mulaw_decode;
+ mulaw->getput_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0));
+ mulaw->func = snd_pcm_mulaw_decode;
} else {
- mulaw->getput_idx = get_index(mulaw->sformat, SND_PCM_FORMAT_S16);
- mulaw->func = mulaw_encode;
+ mulaw->getput_idx = snd_pcm_linear_get_index(mulaw->sformat, SND_PCM_FORMAT_S16);
+ mulaw->func = snd_pcm_mulaw_encode;
}
}
return 0;
snd_pcm_t *req_slave;
int close_slave;
snd_pcm_t *slave;
- ttable_entry_t *ttable;
+ snd_pcm_route_ttable_entry_t *ttable;
unsigned int tt_ssize, tt_cused, tt_sused;
} snd_pcm_plug_t;
{
snd_pcm_plug_t *plug = pcm->private;
unsigned int tt_ssize, tt_cused, tt_sused;
- ttable_entry_t *ttable;
+ snd_pcm_route_ttable_entry_t *ttable;
int err;
assert(snd_pcm_format_linear(slv->format));
if (clt->channels == slv->channels)
n = slv->channels;
}
while (n-- > 0) {
- ttable_entry_t v = FULL;
+ snd_pcm_route_ttable_entry_t v = FULL;
if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
clt->channels > slv->channels) {
int srcs = clt->channels / slv->channels;
int snd_pcm_plug_open(snd_pcm_t **pcmp,
char *name,
- ttable_entry_t *ttable,
+ snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_ssize,
unsigned int tt_cused, unsigned int tt_sused,
snd_pcm_t *slave, int close_slave)
int err;
snd_pcm_t *spcm;
snd_config_t *tt = NULL;
- ttable_entry_t *ttable = NULL;
+ snd_pcm_route_ttable_entry_t *ttable = NULL;
unsigned int cused, sused;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
return snd_pcm_hw_params(plugin->slave, params);
}
-int conv_index(int src_format, int dst_format)
-{
- int src_endian, dst_endian, sign, src_width, dst_width;
-
- sign = (snd_pcm_format_signed(src_format) !=
- snd_pcm_format_signed(dst_format));
-#ifdef SND_LITTLE_ENDIAN
- src_endian = snd_pcm_format_big_endian(src_format);
- dst_endian = snd_pcm_format_big_endian(dst_format);
-#else
- src_endian = snd_pcm_format_little_endian(src_format);
- dst_endian = snd_pcm_format_little_endian(dst_format);
-#endif
-
- if (src_endian < 0)
- src_endian = 0;
- if (dst_endian < 0)
- dst_endian = 0;
-
- src_width = snd_pcm_format_width(src_format) / 8 - 1;
- dst_width = snd_pcm_format_width(dst_format) / 8 - 1;
-
- return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
-}
-
-int get_index(int src_format, int dst_format)
-{
- int sign, width, endian;
- sign = (snd_pcm_format_signed(src_format) !=
- snd_pcm_format_signed(dst_format));
- width = snd_pcm_format_width(src_format) / 8 - 1;
-#ifdef SND_LITTLE_ENDIAN
- endian = snd_pcm_format_big_endian(src_format);
-#else
- endian = snd_pcm_format_little_endian(src_format);
-#endif
- if (endian < 0)
- endian = 0;
- return width * 4 + endian * 2 + sign;
-}
-
-int put_index(int src_format, int dst_format)
-{
- int sign, width, endian;
- sign = (snd_pcm_format_signed(src_format) !=
- snd_pcm_format_signed(dst_format));
- width = snd_pcm_format_width(dst_format) / 8 - 1;
-#ifdef SND_LITTLE_ENDIAN
- endian = snd_pcm_format_big_endian(dst_format);
-#else
- endian = snd_pcm_format_little_endian(dst_format);
-#endif
- if (endian < 0)
- endian = 0;
- return width * 4 + endian * 2 + sign;
-}
-
snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops = {
status: snd_pcm_plugin_status,
state: snd_pcm_plugin_state,
int snd_pcm_plugin_munmap_control(snd_pcm_t *pcm);
int snd_pcm_plugin_munmap(snd_pcm_t *pcm);
int snd_pcm_plugin_poll_descriptor(snd_pcm_t *pcm);
-int get_index(int src_format, int dst_format);
-int put_index(int src_format, int dst_format);
-int conv_index(int src_format, int dst_format);
int snd_pcm_plugin_hw_params_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
int snd_pcm_plugin_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
#define ROUTE_PLUGIN_RESOLUTION 16
#if ROUTE_PLUGIN_FLOAT
-typedef float ttable_entry_t;
+typedef float snd_pcm_route_ttable_entry_t;
#define HALF 0.5
#define FULL 1.0
#else
-typedef int ttable_entry_t;
+typedef int snd_pcm_route_ttable_entry_t;
#define HALF (ROUTE_PLUGIN_RESOLUTION / 2)
#define FULL ROUTE_PLUGIN_RESOLUTION
#endif
+int snd_pcm_linear_get_index(int src_format, int dst_format);
+int snd_pcm_linear_put_index(int src_format, int dst_format);
+int snd_pcm_linear_convert_index(int src_format, int dst_format);
int snd_pcm_copy_open(snd_pcm_t **pcmp, char *name, snd_pcm_t *slave, int close_slave);
int snd_pcm_linear_open(snd_pcm_t **pcmp, char *name, int sformat, snd_pcm_t *slave, int close_slave);
int snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name, int sformat, snd_pcm_t *slave, int close_slave);
int snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name, int sformat, snd_pcm_t *slave, int close_slave);
int snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name, int sformat, snd_pcm_t *slave, int close_slave);
-int snd_pcm_route_load_ttable(snd_config_t *tt, ttable_entry_t *ttable,
+int snd_pcm_route_load_ttable(snd_config_t *tt, snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_csize, unsigned int tt_ssize,
unsigned int *tt_cused, unsigned int *tt_sused,
int schannels);
int snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
int sformat, unsigned int schannels,
- ttable_entry_t *ttable,
+ snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_ssize,
unsigned int tt_cused, unsigned int tt_sused,
snd_pcm_t *slave, int close_slave);
(1 << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
(1 << SND_PCM_ACCESS_RW_NONINTERLEAVED))
+void snd_pcm_linear_convert(const snd_pcm_channel_area_t *src_areas, snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas, snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int convidx);
+void snd_pcm_alaw_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx);
+void snd_pcm_alaw_encode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int getidx);
+void snd_pcm_mulaw_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx);
+void snd_pcm_mulaw_encode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int getidx);
+
+typedef struct _snd_pcm_adpcm_state {
+ int pred_val; /* Calculated predicted value */
+ int step_idx; /* Previous StepSize lookup index */
+} snd_pcm_adpcm_state_t;
+
+void snd_pcm_adpcm_decode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int putidx,
+ snd_pcm_adpcm_state_t *states);
+void snd_pcm_adpcm_encode(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset,
+ unsigned int channels, snd_pcm_uframes_t frames, int getidx,
+ snd_pcm_adpcm_state_t *states);
int16_t sample;
int sum;
unsigned int pos;
-} rate_state_t;
+} snd_pcm_rate_state_t;
typedef snd_pcm_uframes_t (*rate_f)(const snd_pcm_channel_area_t *src_areas,
snd_pcm_uframes_t src_offset, snd_pcm_uframes_t src_frames,
unsigned int channels,
int getidx, int putidx,
unsigned int arg,
- rate_state_t *states);
+ snd_pcm_rate_state_t *states);
typedef struct {
/* This field need to be the first */
rate_f func;
int sformat;
int srate;
- rate_state_t *states;
+ snd_pcm_rate_state_t *states;
} snd_pcm_rate_t;
-static snd_pcm_uframes_t resample_expand(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset, snd_pcm_uframes_t src_frames,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset, snd_pcm_uframes_t *dst_framesp,
- unsigned int channels,
- int getidx, int putidx,
- unsigned int get_threshold,
- rate_state_t *states)
+snd_pcm_uframes_t snd_pcm_rate_expand(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset, snd_pcm_uframes_t src_frames,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset, snd_pcm_uframes_t *dst_framesp,
+ unsigned int channels,
+ int getidx, int putidx,
+ unsigned int get_threshold,
+ snd_pcm_rate_state_t *states)
{
#define GET16_LABELS
#define PUT16_LABELS
return src_frames1;
}
-static snd_pcm_uframes_t resample_shrink(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset, snd_pcm_uframes_t src_frames,
- const snd_pcm_channel_area_t *dst_areas,
- snd_pcm_uframes_t dst_offset, snd_pcm_uframes_t *dst_framesp,
- unsigned int channels,
- int getidx, int putidx,
- unsigned int get_increment,
- rate_state_t *states)
+snd_pcm_uframes_t snd_pcm_rate_shrink(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset, snd_pcm_uframes_t src_frames,
+ const snd_pcm_channel_area_t *dst_areas,
+ snd_pcm_uframes_t dst_offset, snd_pcm_uframes_t *dst_framesp,
+ unsigned int channels,
+ int getidx, int putidx,
+ unsigned int get_increment,
+ snd_pcm_rate_state_t *states)
{
#define GET16_LABELS
#define PUT16_LABELS
src_rate = slave->rate;
dst_rate = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_RATE, 0);
}
- rate->get_idx = get_index(src_format, SND_PCM_FORMAT_S16);
- rate->put_idx = put_index(SND_PCM_FORMAT_S16, dst_format);
+ rate->get_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_S16);
+ rate->put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, dst_format);
if (src_rate < dst_rate) {
- rate->func = resample_expand;
+ rate->func = snd_pcm_rate_expand;
/* pitch is get_threshold */
} else {
- rate->func = resample_shrink;
+ rate->func = snd_pcm_rate_shrink;
/* pitch is get_increment */
}
rate->pitch = (((u_int64_t)dst_rate * DIV) + src_rate / 2) / src_rate;
for (k = 0; k < pcm->channels; ++k) {
rate->states[k].sum = 0;
rate->states[k].sample = 0;
- if (rate->func == resample_expand) {
+ if (rate->func == snd_pcm_rate_expand) {
/* Get a sample on entry */
rate->states[k].pos = rate->pitch + DIV;
} else {
#if ROUTE_PLUGIN_FLOAT
float as_float;
#endif
-} ttable_src_t;
+} snd_pcm_route_ttable_src_t;
-typedef struct ttable_dst ttable_dst_t;
+typedef struct snd_pcm_route_ttable_dst snd_pcm_route_ttable_dst_t;
typedef struct {
enum {UINT32=0, UINT64=1, FLOAT=2} sum_idx;
int src_size;
int dst_sfmt;
unsigned int ndsts;
- ttable_dst_t *dsts;
-} route_params_t;
+ snd_pcm_route_ttable_dst_t *dsts;
+} snd_pcm_route_params_t;
typedef void (*route_f)(const snd_pcm_channel_area_t *src_areas,
const snd_pcm_channel_area_t *dst_area,
snd_pcm_uframes_t dst_offset,
snd_pcm_uframes_t frames,
- const ttable_dst_t *ttable,
- const route_params_t *params);
+ const snd_pcm_route_ttable_dst_t *ttable,
+ const snd_pcm_route_params_t *params);
-struct ttable_dst {
+struct snd_pcm_route_ttable_dst {
int att; /* Attenuated */
unsigned int nsrcs;
- ttable_src_t* srcs;
+ snd_pcm_route_ttable_src_t* srcs;
route_f func;
};
snd_pcm_plugin_t plug;
int sformat;
int schannels;
- route_params_t params;
+ snd_pcm_route_params_t params;
} snd_pcm_route_t;
-static void route1_zero(const snd_pcm_channel_area_t *src_areas ATTRIBUTE_UNUSED,
- snd_pcm_uframes_t src_offset ATTRIBUTE_UNUSED,
- const snd_pcm_channel_area_t *dst_area,
- snd_pcm_uframes_t dst_offset,
- snd_pcm_uframes_t frames,
- const ttable_dst_t* ttable ATTRIBUTE_UNUSED,
- const route_params_t *params)
+void snd_pcm_route_convert1_zero(const snd_pcm_channel_area_t *src_areas ATTRIBUTE_UNUSED,
+ snd_pcm_uframes_t src_offset ATTRIBUTE_UNUSED,
+ const snd_pcm_channel_area_t *dst_area,
+ snd_pcm_uframes_t dst_offset,
+ snd_pcm_uframes_t frames,
+ const snd_pcm_route_ttable_dst_t* ttable ATTRIBUTE_UNUSED,
+ const snd_pcm_route_params_t *params)
{
#if 0
if (dst_area->wanted)
#endif
}
-static void route1_one(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_area,
- snd_pcm_uframes_t dst_offset,
- snd_pcm_uframes_t frames,
- const ttable_dst_t* ttable,
- const route_params_t *params)
+void snd_pcm_route_convert1_one(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_area,
+ snd_pcm_uframes_t dst_offset,
+ snd_pcm_uframes_t frames,
+ const snd_pcm_route_ttable_dst_t* ttable,
+ const snd_pcm_route_params_t *params)
{
#define CONV_LABELS
#include "plugin_ops.h"
break;
}
if (srcidx == ttable->nsrcs) {
- route1_zero(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
+ snd_pcm_route_convert1_zero(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
return;
}
}
}
-static void route1_many(const snd_pcm_channel_area_t *src_areas,
- snd_pcm_uframes_t src_offset,
- const snd_pcm_channel_area_t *dst_area,
- snd_pcm_uframes_t dst_offset,
- snd_pcm_uframes_t frames,
- const ttable_dst_t* ttable,
- const route_params_t *params)
+void snd_pcm_route_convert1_many(const snd_pcm_channel_area_t *src_areas,
+ snd_pcm_uframes_t src_offset,
+ const snd_pcm_channel_area_t *dst_area,
+ snd_pcm_uframes_t dst_offset,
+ snd_pcm_uframes_t frames,
+ const snd_pcm_route_ttable_dst_t* ttable,
+ const snd_pcm_route_params_t *params)
{
#define GET_LABELS
#define PUT32_LABELS
int dst_step;
char *srcs[nsrcs];
int src_steps[nsrcs];
- ttable_src_t src_tt[nsrcs];
+ snd_pcm_route_ttable_src_t src_tt[nsrcs];
u_int32_t sample = 0;
int srcidx, srcidx1 = 0;
for (srcidx = 0; srcidx < nsrcs; ++srcidx) {
}
nsrcs = srcidx1;
if (nsrcs == 0) {
- route1_zero(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
+ snd_pcm_route_convert1_zero(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
return;
} else if (nsrcs == 1 && src_tt[0].as_int == ROUTE_PLUGIN_RESOLUTION) {
- route1_one(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
+ snd_pcm_route_convert1_one(src_areas, src_offset, dst_area, dst_offset, frames, ttable, params);
return;
}
dst_step = snd_pcm_channel_area_step(dst_area);
while (frames-- > 0) {
- ttable_src_t *ttp = src_tt;
+ snd_pcm_route_ttable_src_t *ttp = src_tt;
sum_t sum;
/* Zero sum */
}
}
-static void route_transfer(const snd_pcm_channel_area_t *src_areas,
+void snd_pcm_route_convert(const snd_pcm_channel_area_t *src_areas,
snd_pcm_uframes_t src_offset,
const snd_pcm_channel_area_t *dst_areas,
snd_pcm_uframes_t dst_offset,
snd_pcm_uframes_t dst_channels,
snd_pcm_uframes_t frames,
- route_params_t *params)
+ snd_pcm_route_params_t *params)
{
unsigned int dst_channel;
- ttable_dst_t *dstp;
+ snd_pcm_route_ttable_dst_t *dstp;
const snd_pcm_channel_area_t *dst_area;
dstp = params->dsts;
dst_area = dst_areas;
for (dst_channel = 0; dst_channel < dst_channels; ++dst_channel) {
if (dst_channel >= params->ndsts)
- route1_zero(src_areas, src_offset, dst_area, dst_offset, frames, dstp, params);
+ snd_pcm_route_convert1_zero(src_areas, src_offset, dst_area, dst_offset, frames, dstp, params);
else
dstp->func(src_areas, src_offset, dst_area, dst_offset, frames, dstp, params);
dstp++;
static int snd_pcm_route_close(snd_pcm_t *pcm)
{
snd_pcm_route_t *route = pcm->private;
- route_params_t *params = &route->params;
+ snd_pcm_route_params_t *params = &route->params;
int err = 0;
unsigned int dst_channel;
if (route->plug.close_slave)
src_format = slave->format;
dst_format = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0);
}
- route->params.get_idx = get_index(src_format, SND_PCM_FORMAT_U16);
- route->params.put_idx = put_index(SND_PCM_FORMAT_U32, dst_format);
- route->params.conv_idx = conv_index(src_format, dst_format);
+ route->params.get_idx = snd_pcm_linear_get_index(src_format, SND_PCM_FORMAT_U16);
+ route->params.put_idx = snd_pcm_linear_put_index(SND_PCM_FORMAT_U32, dst_format);
+ route->params.conv_idx = snd_pcm_linear_convert_index(src_format, dst_format);
route->params.src_size = snd_pcm_format_width(src_format) / 8;
route->params.dst_sfmt = dst_format;
#if ROUTE_PLUGIN_FLOAT
}
static snd_pcm_sframes_t snd_pcm_route_write_areas(snd_pcm_t *pcm,
- const snd_pcm_channel_area_t *areas,
- snd_pcm_uframes_t offset,
- snd_pcm_uframes_t size,
- snd_pcm_uframes_t *slave_sizep)
+ const snd_pcm_channel_area_t *areas,
+ snd_pcm_uframes_t offset,
+ snd_pcm_uframes_t size,
+ snd_pcm_uframes_t *slave_sizep)
{
snd_pcm_route_t *route = pcm->private;
snd_pcm_t *slave = route->plug.slave;
assert(size > 0);
while (xfer < size) {
snd_pcm_uframes_t frames = snd_pcm_mmap_playback_xfer(slave, size - xfer);
- route_transfer(areas, offset,
- snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
- slave->channels, frames, &route->params);
+ snd_pcm_route_convert(areas, offset,
+ snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
+ slave->channels, frames, &route->params);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
break;
}
static snd_pcm_sframes_t snd_pcm_route_read_areas(snd_pcm_t *pcm,
- const snd_pcm_channel_area_t *areas,
- snd_pcm_uframes_t offset,
- snd_pcm_uframes_t size,
- snd_pcm_uframes_t *slave_sizep)
+ const snd_pcm_channel_area_t *areas,
+ snd_pcm_uframes_t offset,
+ snd_pcm_uframes_t size,
+ snd_pcm_uframes_t *slave_sizep)
{
snd_pcm_route_t *route = pcm->private;
snd_pcm_t *slave = route->plug.slave;
assert(size > 0);
while (xfer < size) {
snd_pcm_uframes_t frames = snd_pcm_mmap_capture_xfer(slave, size - xfer);
- route_transfer(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
- areas, offset,
- pcm->channels, frames, &route->params);
+ snd_pcm_route_convert(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
+ areas, offset,
+ pcm->channels, frames, &route->params);
err = snd_pcm_mmap_forward(slave, frames);
if (err < 0)
break;
snd_pcm_format_name(route->sformat));
snd_output_puts(out, "Transformation table:\n");
for (dst = 0; dst < route->params.ndsts; dst++) {
- ttable_dst_t *d = &route->params.dsts[dst];
+ snd_pcm_route_ttable_dst_t *d = &route->params.dsts[dst];
unsigned int src;
if (d->nsrcs == 0)
continue;
snd_output_printf(out, "%d <- ", dst);
src = 0;
while (1) {
- ttable_src_t *s = &d->srcs[src];
+ snd_pcm_route_ttable_src_t *s = &d->srcs[src];
if (d->att)
snd_output_printf(out, "%d*%g", s->channel, s->as_float);
else
munmap: snd_pcm_plugin_munmap,
};
-int route_load_ttable(route_params_t *params, int stream,
+int route_load_ttable(snd_pcm_route_params_t *params, int stream,
unsigned int tt_ssize,
- ttable_entry_t *ttable,
+ snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_cused, unsigned int tt_sused)
{
unsigned int src_channel, dst_channel;
- ttable_dst_t *dptr;
+ snd_pcm_route_ttable_dst_t *dptr;
unsigned int sused, dused, smul, dmul;
if (stream == SND_PCM_STREAM_PLAYBACK) {
sused = tt_cused;
return -ENOMEM;
params->dsts = dptr;
for (dst_channel = 0; dst_channel < dused; ++dst_channel) {
- ttable_entry_t t = 0;
+ snd_pcm_route_ttable_entry_t t = 0;
int att = 0;
int nsrcs = 0;
- ttable_src_t srcs[sused];
+ snd_pcm_route_ttable_src_t srcs[sused];
for (src_channel = 0; src_channel < sused; ++src_channel) {
- ttable_entry_t v;
+ snd_pcm_route_ttable_entry_t v;
v = ttable[src_channel * smul + dst_channel * dmul];
assert(v >= 0 && v <= FULL);
if (v != 0) {
dptr->att = att;
dptr->nsrcs = nsrcs;
if (nsrcs == 0)
- dptr->func = route1_zero;
+ dptr->func = snd_pcm_route_convert1_zero;
else if (nsrcs == 1 && !att)
- dptr->func = route1_one;
+ dptr->func = snd_pcm_route_convert1_one;
else
- dptr->func = route1_many;
+ dptr->func = snd_pcm_route_convert1_many;
if (nsrcs > 0) {
dptr->srcs = calloc(nsrcs, sizeof(*srcs));
if (!dptr->srcs)
int snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
int sformat, unsigned int schannels,
- ttable_entry_t *ttable,
+ snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_ssize,
unsigned int tt_cused, unsigned int tt_sused,
snd_pcm_t *slave, int close_slave)
return 0;
}
-int snd_pcm_route_load_ttable(snd_config_t *tt, ttable_entry_t *ttable,
+int snd_pcm_route_load_ttable(snd_config_t *tt, snd_pcm_route_ttable_entry_t *ttable,
unsigned int tt_csize, unsigned int tt_ssize,
unsigned int *tt_cused, unsigned int *tt_sused,
int schannels)
int sformat = -1;
long schannels = -1;
snd_config_t *tt = NULL;
- ttable_entry_t ttable[MAX_CHANNELS*MAX_CHANNELS];
+ snd_pcm_route_ttable_entry_t ttable[MAX_CHANNELS*MAX_CHANNELS];
unsigned int cused, sused;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);