1999-11-24 17:00:16 +00:00
|
|
|
/*
|
|
|
|
|
* Rate conversion Plug-In
|
|
|
|
|
* Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
#ifdef __KERNEL__
|
|
|
|
|
#include "../../include/driver.h"
|
|
|
|
|
#include "../../include/pcm_plugin.h"
|
|
|
|
|
#else
|
1999-11-24 17:00:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <endian.h>
|
|
|
|
|
#include <byteswap.h>
|
|
|
|
|
#include "../pcm_local.h"
|
1999-12-11 11:46:05 +00:00
|
|
|
#endif
|
1999-11-24 17:00:16 +00:00
|
|
|
|
1999-11-25 10:15:28 +00:00
|
|
|
#define SHIFT 11
|
1999-11-24 18:17:00 +00:00
|
|
|
#define BITS (1<<SHIFT)
|
|
|
|
|
#define MASK (BITS-1)
|
1999-12-06 00:01:26 +00:00
|
|
|
#define MAX_VOICES 6
|
1999-11-24 18:17:00 +00:00
|
|
|
|
1999-11-24 17:00:16 +00:00
|
|
|
/*
|
|
|
|
|
* Basic rate conversion plugin
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct rate_private_data {
|
1999-11-25 10:15:28 +00:00
|
|
|
int src_voices;
|
|
|
|
|
int dst_voices;
|
|
|
|
|
int src_rate;
|
|
|
|
|
int dst_rate;
|
1999-12-10 00:13:46 +00:00
|
|
|
int sample_size;
|
1999-12-10 14:43:25 +00:00
|
|
|
int expand: 1;
|
1999-11-24 17:00:16 +00:00
|
|
|
unsigned int pitch;
|
|
|
|
|
unsigned int pos;
|
1999-12-06 00:01:26 +00:00
|
|
|
signed short last_S1[MAX_VOICES];
|
|
|
|
|
signed short last_S2[MAX_VOICES];
|
1999-11-24 18:17:00 +00:00
|
|
|
ssize_t old_src_size, old_dst_size;
|
1999-11-24 17:00:16 +00:00
|
|
|
};
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
static void resample16_expand(struct rate_private_data *data, int voices,
|
|
|
|
|
signed short *src_ptr, int src_size,
|
|
|
|
|
signed short *dst_ptr, int dst_size)
|
1999-11-24 17:00:16 +00:00
|
|
|
{
|
|
|
|
|
unsigned int pos;
|
|
|
|
|
signed int val;
|
1999-12-09 09:21:56 +00:00
|
|
|
signed short S1, S2;
|
1999-12-06 00:01:26 +00:00
|
|
|
int voice;
|
1999-12-09 09:21:56 +00:00
|
|
|
signed short *src, *dst;
|
|
|
|
|
int size;
|
1999-11-24 17:00:16 +00:00
|
|
|
|
1999-12-09 09:21:56 +00:00
|
|
|
for (voice = 0; voice < voices; ++voice) {
|
|
|
|
|
pos = data->pos;
|
|
|
|
|
S1 = data->last_S1[voice];
|
|
|
|
|
S2 = data->last_S2[voice];
|
|
|
|
|
src = src_ptr + voice;
|
|
|
|
|
dst = dst_ptr + voice;
|
|
|
|
|
size = dst_size;
|
1999-11-25 10:15:28 +00:00
|
|
|
if (pos >> SHIFT) {
|
1999-12-09 09:21:56 +00:00
|
|
|
pos &= MASK;
|
|
|
|
|
S1 = S2;
|
|
|
|
|
S2 = *src;
|
1999-11-25 10:15:28 +00:00
|
|
|
}
|
1999-12-09 09:21:56 +00:00
|
|
|
while (size-- > 0) {
|
|
|
|
|
if (pos >> SHIFT) {
|
1999-12-10 14:43:25 +00:00
|
|
|
src += voices;
|
1999-12-09 09:21:56 +00:00
|
|
|
pos &= MASK;
|
|
|
|
|
S1 = S2;
|
1999-12-10 00:13:46 +00:00
|
|
|
if ((src - src_ptr) < src_size * voices)
|
|
|
|
|
S2 = *src;
|
1999-12-09 09:21:56 +00:00
|
|
|
}
|
|
|
|
|
val = S1 + ((S2 - S1) * (signed int)pos) / BITS;
|
1999-12-06 00:01:26 +00:00
|
|
|
if (val < -32768)
|
|
|
|
|
val = -32768;
|
|
|
|
|
else if (val > 32767)
|
|
|
|
|
val = 32767;
|
1999-12-09 09:21:56 +00:00
|
|
|
*dst = val;
|
|
|
|
|
dst += voices;
|
|
|
|
|
pos += data->pitch;
|
1999-12-06 00:01:26 +00:00
|
|
|
}
|
1999-12-09 09:21:56 +00:00
|
|
|
data->last_S1[voice] = S1;
|
|
|
|
|
data->last_S2[voice] = S2;
|
1999-12-10 00:13:46 +00:00
|
|
|
data->pos = pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
static void resample16_shrink(struct rate_private_data *data, int voices,
|
|
|
|
|
signed short *src_ptr, int src_size,
|
|
|
|
|
signed short *dst_ptr, int dst_size)
|
1999-12-10 14:43:25 +00:00
|
|
|
{
|
|
|
|
|
unsigned int pos;
|
|
|
|
|
signed int val;
|
|
|
|
|
signed short S1, S2;
|
|
|
|
|
int voice;
|
|
|
|
|
signed short *src, *dst;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
for (voice = 0; voice < voices; ++voice) {
|
|
|
|
|
pos = data->pos;
|
|
|
|
|
S1 = data->last_S1[voice];
|
|
|
|
|
S2 = data->last_S2[voice];
|
|
|
|
|
src = src_ptr + voice;
|
|
|
|
|
dst = dst_ptr + voice;
|
|
|
|
|
size = dst_size;
|
|
|
|
|
while (size > 0) {
|
|
|
|
|
S1 = S2;
|
|
|
|
|
if ((src - src_ptr) < (src_size * voices)) {
|
|
|
|
|
S2 = *src;
|
|
|
|
|
src += voices;
|
|
|
|
|
}
|
|
|
|
|
if (pos >> SHIFT) {
|
|
|
|
|
pos &= MASK;
|
|
|
|
|
val = S1 + ((S2 - S1) * (signed int)pos) / BITS;
|
|
|
|
|
if (val < -32768)
|
|
|
|
|
val = -32768;
|
|
|
|
|
else if (val > 32767)
|
|
|
|
|
val = 32767;
|
|
|
|
|
*dst = val;
|
|
|
|
|
dst += voices;
|
|
|
|
|
size--;
|
|
|
|
|
}
|
|
|
|
|
pos += data->pitch;
|
|
|
|
|
}
|
|
|
|
|
data->last_S1[voice] = S1;
|
|
|
|
|
data->last_S2[voice] = S2;
|
|
|
|
|
data->pos = pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
static void resample8_expand(struct rate_private_data *data, int voices,
|
|
|
|
|
unsigned char *src_ptr, int src_size,
|
|
|
|
|
unsigned char *dst_ptr, int dst_size)
|
1999-12-10 00:13:46 +00:00
|
|
|
{
|
|
|
|
|
unsigned int pos;
|
|
|
|
|
signed int val;
|
|
|
|
|
signed short S1, S2;
|
|
|
|
|
int voice;
|
|
|
|
|
unsigned char *src, *dst;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
for (voice = 0; voice < voices; ++voice) {
|
|
|
|
|
pos = data->pos;
|
|
|
|
|
S1 = data->last_S1[voice];
|
|
|
|
|
S2 = data->last_S2[voice];
|
|
|
|
|
src = src_ptr + voice;
|
|
|
|
|
dst = dst_ptr + voice;
|
|
|
|
|
size = dst_size;
|
|
|
|
|
if (pos >> SHIFT) {
|
|
|
|
|
pos &= MASK;
|
|
|
|
|
S1 = S2;
|
|
|
|
|
S2 = (*src << 8) ^ 0x8000;
|
|
|
|
|
}
|
|
|
|
|
while (size-- > 0) {
|
|
|
|
|
if (pos >> SHIFT) {
|
1999-12-10 14:43:25 +00:00
|
|
|
src += voices;
|
1999-12-10 00:13:46 +00:00
|
|
|
pos &= MASK;
|
|
|
|
|
S1 = S2;
|
|
|
|
|
if ((src - src_ptr) < src_size * voices)
|
|
|
|
|
S2 = (*src << 8) ^ 0x8000;
|
|
|
|
|
}
|
|
|
|
|
val = S1 + ((S2 - S1) * (signed int)pos) / BITS;
|
|
|
|
|
if (val < -32768)
|
|
|
|
|
val = -32768;
|
|
|
|
|
else if (val > 32767)
|
|
|
|
|
val = 32767;
|
|
|
|
|
*dst = (val >> 8) ^ 0x0080;
|
|
|
|
|
dst += voices;
|
|
|
|
|
pos += data->pitch;
|
|
|
|
|
}
|
|
|
|
|
data->last_S1[voice] = S1;
|
|
|
|
|
data->last_S2[voice] = S2;
|
|
|
|
|
data->pos = pos;
|
1999-11-24 17:00:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
static void resample8_shrink(struct rate_private_data *data, int voices,
|
|
|
|
|
unsigned char *src_ptr, int src_size,
|
|
|
|
|
unsigned char *dst_ptr, int dst_size)
|
1999-12-10 14:43:25 +00:00
|
|
|
{
|
|
|
|
|
unsigned int pos;
|
|
|
|
|
signed int val;
|
|
|
|
|
signed short S1, S2;
|
|
|
|
|
int voice;
|
|
|
|
|
unsigned char *src, *dst;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
for (voice = 0; voice < voices; ++voice) {
|
|
|
|
|
pos = data->pos;
|
|
|
|
|
S1 = data->last_S1[voice];
|
|
|
|
|
S2 = data->last_S2[voice];
|
|
|
|
|
src = src_ptr + voice;
|
|
|
|
|
dst = dst_ptr + voice;
|
|
|
|
|
size = dst_size;
|
|
|
|
|
while (size > 0) {
|
|
|
|
|
S1 = S2;
|
|
|
|
|
if ((src - src_ptr) < (src_size * voices)) {
|
|
|
|
|
S2 = (*src << 8) ^ 0x8000;
|
|
|
|
|
src += voices;
|
|
|
|
|
}
|
|
|
|
|
if (pos >> SHIFT) {
|
|
|
|
|
pos &= MASK;
|
|
|
|
|
val = S1 + ((S2 - S1) * (signed int)pos) / BITS;
|
|
|
|
|
if (val < -32768)
|
|
|
|
|
val = -32768;
|
|
|
|
|
else if (val > 32767)
|
|
|
|
|
val = 32767;
|
|
|
|
|
*dst = (val >> 8) ^ 0x0080;
|
|
|
|
|
dst += voices;
|
|
|
|
|
size--;
|
|
|
|
|
}
|
|
|
|
|
pos += data->pitch;
|
|
|
|
|
}
|
|
|
|
|
data->last_S1[voice] = S1;
|
|
|
|
|
data->last_S2[voice] = S2;
|
|
|
|
|
data->pos = pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-24 17:00:16 +00:00
|
|
|
static ssize_t rate_src_size(snd_pcm_plugin_t *plugin, size_t size)
|
|
|
|
|
{
|
|
|
|
|
struct rate_private_data *data;
|
1999-11-24 18:17:00 +00:00
|
|
|
ssize_t res;
|
1999-11-24 17:00:16 +00:00
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
if (plugin == NULL || size <= 0)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
data = (struct rate_private_data *)snd_pcm_plugin_extra_data(plugin);
|
1999-12-10 14:43:25 +00:00
|
|
|
if (data->expand) {
|
|
|
|
|
res = (((size * data->pitch) + (BITS/2)) >> SHIFT);
|
|
|
|
|
} else {
|
|
|
|
|
res = (((size << SHIFT) + (data->pitch / 2)) / data->pitch);
|
|
|
|
|
}
|
1999-12-10 00:13:46 +00:00
|
|
|
res = res / (data->src_voices*data->sample_size) * (data->src_voices*data->sample_size);
|
|
|
|
|
if (data->old_src_size > 0) {
|
1999-12-10 14:43:25 +00:00
|
|
|
ssize_t size1 = size, res1 = data->old_dst_size;
|
|
|
|
|
while (data->old_src_size < size1) {
|
|
|
|
|
size1 >>= 1;
|
|
|
|
|
res1 <<= 1;
|
1999-12-10 00:13:46 +00:00
|
|
|
}
|
1999-12-10 14:43:25 +00:00
|
|
|
while (data->old_src_size > size1) {
|
|
|
|
|
size1 <<= 1;
|
|
|
|
|
res1 >>= 1;
|
|
|
|
|
}
|
|
|
|
|
if (data->old_src_size == size1)
|
|
|
|
|
return res1;
|
1999-11-24 18:17:00 +00:00
|
|
|
}
|
1999-12-10 00:13:46 +00:00
|
|
|
data->old_src_size = size;
|
|
|
|
|
data->old_dst_size = res;
|
1999-11-24 18:17:00 +00:00
|
|
|
return res;
|
1999-11-24 17:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ssize_t rate_dst_size(snd_pcm_plugin_t *plugin, size_t size)
|
|
|
|
|
{
|
|
|
|
|
struct rate_private_data *data;
|
1999-11-24 18:17:00 +00:00
|
|
|
ssize_t res;
|
1999-11-24 17:00:16 +00:00
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
if (plugin == NULL || size <= 0)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
data = (struct rate_private_data *)snd_pcm_plugin_extra_data(plugin);
|
1999-12-10 14:43:25 +00:00
|
|
|
if (data->expand) {
|
|
|
|
|
res = (((size << SHIFT) + (data->pitch / 2)) / data->pitch);
|
|
|
|
|
} else {
|
|
|
|
|
res = (((size * data->pitch) + (BITS/2)) >> SHIFT);
|
|
|
|
|
}
|
1999-12-10 00:13:46 +00:00
|
|
|
res = res / (data->dst_voices*data->sample_size) * (data->dst_voices*data->sample_size);
|
|
|
|
|
if (data->old_dst_size > 0) {
|
1999-12-10 14:43:25 +00:00
|
|
|
ssize_t size1 = size, res1 = data->old_src_size;
|
|
|
|
|
while (data->old_dst_size < size1) {
|
|
|
|
|
size1 >>= 1;
|
|
|
|
|
res1 <<= 1;
|
|
|
|
|
}
|
|
|
|
|
while (data->old_dst_size > size1) {
|
|
|
|
|
size1 <<= 1;
|
|
|
|
|
res1 >>= 1;
|
1999-12-10 00:13:46 +00:00
|
|
|
}
|
1999-12-10 14:43:25 +00:00
|
|
|
if (data->old_dst_size == size1)
|
|
|
|
|
return res1;
|
1999-11-24 18:17:00 +00:00
|
|
|
}
|
1999-12-10 00:13:46 +00:00
|
|
|
data->old_dst_size = size;
|
|
|
|
|
data->old_src_size = res;
|
1999-11-24 18:17:00 +00:00
|
|
|
return res;
|
1999-11-24 17:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
1999-12-25 15:23:47 +00:00
|
|
|
static ssize_t rate_transfer(snd_pcm_plugin_t *plugin,
|
|
|
|
|
char *src_ptr, size_t src_size,
|
|
|
|
|
char *dst_ptr, size_t dst_size)
|
|
|
|
|
{
|
|
|
|
|
struct rate_private_data *data;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL || src_ptr == NULL || src_size < 0 ||
|
|
|
|
|
dst_ptr == NULL || dst_size < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (src_size == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
data = (struct rate_private_data *)snd_pcm_plugin_extra_data(plugin);
|
|
|
|
|
if (data == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (data->sample_size == 2) {
|
|
|
|
|
if (data->src_rate < data->dst_rate) {
|
|
|
|
|
resample16_expand(data, data->src_voices,
|
|
|
|
|
(signed short *)src_ptr, src_size / (data->src_voices * 2),
|
|
|
|
|
(signed short *)dst_ptr, dst_size / (data->dst_voices * 2));
|
|
|
|
|
} else {
|
|
|
|
|
resample16_shrink(data, data->src_voices,
|
|
|
|
|
(signed short *)src_ptr, src_size / (data->src_voices * 2),
|
|
|
|
|
(signed short *)dst_ptr, dst_size / (data->dst_voices * 2));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (data->src_rate < data->dst_rate) {
|
|
|
|
|
resample8_expand(data, data->src_voices,
|
|
|
|
|
src_ptr, src_size / data->src_voices,
|
|
|
|
|
dst_ptr, dst_size / data->dst_voices);
|
|
|
|
|
} else {
|
|
|
|
|
resample8_shrink(data, data->src_voices,
|
|
|
|
|
src_ptr, src_size / data->src_voices,
|
|
|
|
|
dst_ptr, dst_size / data->dst_voices);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rate_dst_size(plugin, src_size);
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-21 17:36:27 +00:00
|
|
|
static int rate_action(snd_pcm_plugin_t *plugin,
|
|
|
|
|
snd_pcm_plugin_action_t action,
|
|
|
|
|
unsigned long udata)
|
1999-12-25 15:23:47 +00:00
|
|
|
{
|
|
|
|
|
struct rate_private_data *data;
|
|
|
|
|
int voice;
|
|
|
|
|
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
data = (struct rate_private_data *)snd_pcm_plugin_extra_data(plugin);
|
|
|
|
|
switch (action) {
|
|
|
|
|
case INIT:
|
|
|
|
|
case PREPARE:
|
|
|
|
|
case DRAIN:
|
|
|
|
|
case FLUSH:
|
|
|
|
|
data->pos = 0;
|
|
|
|
|
for (voice = 0; voice < data->src_voices; ++voice) {
|
|
|
|
|
data->last_S1[voice] = data->last_S2[voice] = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0; /* silenty ignore other actions */
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-02 14:31:26 +00:00
|
|
|
int snd_pcm_plugin_build_rate(snd_pcm_format_t *src_format,
|
|
|
|
|
snd_pcm_format_t *dst_format,
|
1999-11-24 17:00:16 +00:00
|
|
|
snd_pcm_plugin_t **r_plugin)
|
|
|
|
|
{
|
|
|
|
|
struct rate_private_data *data;
|
|
|
|
|
snd_pcm_plugin_t *plugin;
|
1999-12-06 00:01:26 +00:00
|
|
|
int voice;
|
1999-11-24 17:00:16 +00:00
|
|
|
|
2000-01-08 20:11:33 +00:00
|
|
|
if (r_plugin == NULL)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
*r_plugin = NULL;
|
1999-12-02 14:31:26 +00:00
|
|
|
|
1999-12-11 11:46:05 +00:00
|
|
|
if (src_format->interleave != dst_format->interleave &&
|
|
|
|
|
src_format->voices > 1)
|
1999-12-02 14:31:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
if (src_format->format != dst_format->format)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
1999-12-02 14:31:26 +00:00
|
|
|
if (!dst_format->interleave)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (src_format->voices != dst_format->voices)
|
|
|
|
|
return -EINVAL;
|
1999-12-06 00:01:26 +00:00
|
|
|
if (dst_format->voices < 1 || dst_format->voices > MAX_VOICES)
|
1999-12-02 14:31:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
1999-12-10 00:13:46 +00:00
|
|
|
if (src_format->format != SND_PCM_SFMT_S16_LE &&
|
|
|
|
|
src_format->format != SND_PCM_SFMT_U8)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
1999-12-02 14:31:26 +00:00
|
|
|
if (src_format->rate == dst_format->rate)
|
1999-11-24 17:00:16 +00:00
|
|
|
return -EINVAL;
|
1999-12-10 14:43:25 +00:00
|
|
|
plugin = snd_pcm_plugin_build("rate conversion",
|
1999-11-24 17:00:16 +00:00
|
|
|
sizeof(struct rate_private_data));
|
|
|
|
|
if (plugin == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
data = (struct rate_private_data *)snd_pcm_plugin_extra_data(plugin);
|
1999-12-10 00:13:46 +00:00
|
|
|
data->sample_size = src_format->format == SND_PCM_SFMT_S16_LE ? 2 : 1;
|
1999-12-02 14:31:26 +00:00
|
|
|
data->src_voices = src_format->voices;
|
|
|
|
|
data->dst_voices = dst_format->voices;
|
|
|
|
|
data->src_rate = src_format->rate;
|
|
|
|
|
data->dst_rate = dst_format->rate;
|
1999-12-10 14:43:25 +00:00
|
|
|
if (src_format->rate < dst_format->rate) {
|
|
|
|
|
data->expand = 1;
|
|
|
|
|
data->pitch = ((src_format->rate << SHIFT) + (dst_format->rate >> 1)) / dst_format->rate;
|
|
|
|
|
} else {
|
|
|
|
|
data->expand = 0;
|
|
|
|
|
data->pitch = ((dst_format->rate << SHIFT) + (src_format->rate >> 1)) / src_format->rate;
|
|
|
|
|
}
|
1999-11-24 18:17:00 +00:00
|
|
|
data->pos = 0;
|
1999-12-06 00:01:26 +00:00
|
|
|
for (voice = 0; voice < data->src_voices; ++voice) {
|
|
|
|
|
data->last_S1[voice] = data->last_S2[voice] = 0;
|
|
|
|
|
}
|
1999-11-24 18:17:00 +00:00
|
|
|
data->old_src_size = data->old_dst_size = 0;
|
1999-11-24 17:00:16 +00:00
|
|
|
plugin->transfer = rate_transfer;
|
|
|
|
|
plugin->src_size = rate_src_size;
|
|
|
|
|
plugin->dst_size = rate_dst_size;
|
1999-11-25 10:15:28 +00:00
|
|
|
plugin->action = rate_action;
|
1999-11-24 17:00:16 +00:00
|
|
|
*r_plugin = plugin;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|