2002-10-01 08:45:08 +02:00
|
|
|
/* This audio output filter changes the format of a data block. Valid
|
|
|
|
formats are: AFMT_U8, AFMT_S8, AFMT_S16_LE, AFMT_S16_BE
|
|
|
|
AFMT_U16_LE, AFMT_U16_BE, AFMT_S32_LE and AFMT_S32_BE.
|
|
|
|
*/
|
|
|
|
|
2005-02-24 17:48:18 +01:00
|
|
|
// Must be defined before any libc headers are included!
|
|
|
|
#define _ISOC9X_SOURCE
|
|
|
|
|
2002-10-01 08:45:08 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2005-02-24 17:48:18 +01:00
|
|
|
// Integer to float conversion through lrintf()
|
|
|
|
#ifdef HAVE_LRINTF
|
|
|
|
#include <math.h>
|
|
|
|
long int lrintf(float);
|
|
|
|
#else
|
|
|
|
#define lrintf(x) ((int)(x))
|
|
|
|
#endif
|
|
|
|
|
2006-11-29 00:13:08 +01:00
|
|
|
#include "af.h"
|
2006-11-29 16:02:45 +01:00
|
|
|
#include "libavutil/common.h"
|
2006-12-07 12:58:07 +01:00
|
|
|
#include "mpbswap.h"
|
2006-11-29 00:13:08 +01:00
|
|
|
#include "libvo/fastmemcpy.h"
|
|
|
|
|
2002-11-12 13:33:56 +01:00
|
|
|
/* Functions used by play to convert the input audio to the correct
|
|
|
|
format */
|
|
|
|
|
|
|
|
/* The below includes retrives functions for converting to and from
|
|
|
|
ulaw and alaw */
|
|
|
|
#include "af_format_ulaw.c"
|
|
|
|
#include "af_format_alaw.c"
|
|
|
|
|
|
|
|
// Switch endianess
|
|
|
|
static void endian(void* in, void* out, int len, int bps);
|
2005-10-04 23:49:56 +02:00
|
|
|
// From singed to unsigned and the other way
|
|
|
|
static void si2us(void* data, int len, int bps);
|
2002-11-12 13:33:56 +01:00
|
|
|
// Change the number of bits per sample
|
|
|
|
static void change_bps(void* in, void* out, int len, int inbps, int outbps);
|
|
|
|
// From float to int signed
|
2005-02-24 17:48:18 +01:00
|
|
|
static void float2int(float* in, void* out, int len, int bps);
|
2002-11-12 13:33:56 +01:00
|
|
|
// From signed int to float
|
2005-02-24 17:48:18 +01:00
|
|
|
static void int2float(void* in, float* out, int len, int bps);
|
2002-11-12 13:33:56 +01:00
|
|
|
|
2004-12-29 20:05:29 +01:00
|
|
|
static af_data_t* play(struct af_instance_s* af, af_data_t* data);
|
|
|
|
static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data);
|
|
|
|
static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data);
|
|
|
|
static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data);
|
|
|
|
|
2002-12-28 14:59:53 +01:00
|
|
|
// Helper functions to check sanity for input arguments
|
|
|
|
|
|
|
|
// Sanity check for bytes per sample
|
2004-11-20 11:32:52 +01:00
|
|
|
static int check_bps(int bps)
|
2002-11-13 10:09:50 +01:00
|
|
|
{
|
2004-05-16 12:48:59 +02:00
|
|
|
if(bps != 4 && bps != 3 && bps != 2 && bps != 1){
|
2002-12-28 14:59:53 +01:00
|
|
|
af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample"
|
2004-05-16 12:48:59 +02:00
|
|
|
" must be 1, 2, 3 or 4. Current value is %i \n",bps);
|
2002-11-13 10:09:50 +01:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
2002-12-28 14:59:53 +01:00
|
|
|
return AF_OK;
|
|
|
|
}
|
2002-11-13 10:09:50 +01:00
|
|
|
|
2002-12-28 14:59:53 +01:00
|
|
|
// Check for unsupported formats
|
2004-11-20 11:32:52 +01:00
|
|
|
static int check_format(int format)
|
2002-12-28 14:59:53 +01:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
switch(format & AF_FORMAT_SPECIAL_MASK){
|
2005-01-03 19:59:16 +01:00
|
|
|
case(AF_FORMAT_IMA_ADPCM):
|
2002-11-13 10:09:50 +01:00
|
|
|
case(AF_FORMAT_MPEG2):
|
|
|
|
case(AF_FORMAT_AC3):
|
|
|
|
af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
|
2005-01-06 15:32:08 +01:00
|
|
|
af_fmt2str(format,buf,256));
|
2002-11-13 10:09:50 +01:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
return AF_OK;
|
2002-12-28 14:59:53 +01:00
|
|
|
}
|
2002-11-13 10:09:50 +01:00
|
|
|
|
2002-10-01 08:45:08 +02:00
|
|
|
// Initialization and runtime control
|
|
|
|
static int control(struct af_instance_s* af, int cmd, void* arg)
|
|
|
|
{
|
|
|
|
switch(cmd){
|
2002-11-12 13:33:56 +01:00
|
|
|
case AF_CONTROL_REINIT:{
|
|
|
|
char buf1[256];
|
|
|
|
char buf2[256];
|
2004-12-29 20:05:29 +01:00
|
|
|
af_data_t *data = arg;
|
|
|
|
|
2002-10-01 08:45:08 +02:00
|
|
|
// Make sure this filter isn't redundant
|
2005-02-17 16:35:44 +01:00
|
|
|
if(af->data->format == data->format &&
|
|
|
|
af->data->bps == data->bps)
|
2002-10-01 08:45:08 +02:00
|
|
|
return AF_DETACH;
|
2002-12-28 14:59:53 +01:00
|
|
|
|
2002-11-13 10:09:50 +01:00
|
|
|
// Check for errors in configuraton
|
2005-02-17 16:35:44 +01:00
|
|
|
if((AF_OK != check_bps(data->bps)) ||
|
|
|
|
(AF_OK != check_format(data->format)) ||
|
2002-12-28 14:59:53 +01:00
|
|
|
(AF_OK != check_bps(af->data->bps)) ||
|
|
|
|
(AF_OK != check_format(af->data->format)))
|
2002-11-12 13:33:56 +01:00
|
|
|
return AF_ERROR;
|
|
|
|
|
2005-01-06 15:32:08 +01:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %s to %s\n",
|
2005-02-17 16:35:44 +01:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 15:32:08 +01:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2002-10-01 08:45:08 +02:00
|
|
|
|
2005-02-17 16:35:44 +01:00
|
|
|
af->data->rate = data->rate;
|
|
|
|
af->data->nch = data->nch;
|
2002-10-01 08:45:08 +02:00
|
|
|
af->mul.n = af->data->bps;
|
2005-02-17 16:35:44 +01:00
|
|
|
af->mul.d = data->bps;
|
2005-01-08 22:34:06 +01:00
|
|
|
af_frac_cancel(&af->mul);
|
2004-12-29 20:05:29 +01:00
|
|
|
|
|
|
|
af->play = play; // set default
|
|
|
|
|
|
|
|
// look whether only endianess differences are there
|
|
|
|
if ((af->data->format & ~AF_FORMAT_END_MASK) ==
|
|
|
|
(data->format & ~AF_FORMAT_END_MASK))
|
|
|
|
{
|
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n");
|
|
|
|
af->play = play_swapendian;
|
|
|
|
}
|
|
|
|
if ((data->format == AF_FORMAT_FLOAT_NE) &&
|
|
|
|
(af->data->format == AF_FORMAT_S16_NE))
|
|
|
|
{
|
2005-01-06 15:32:08 +01:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
|
2005-02-17 16:35:44 +01:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 15:32:08 +01:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2004-12-29 20:05:29 +01:00
|
|
|
af->play = play_float_s16;
|
|
|
|
}
|
|
|
|
if ((data->format == AF_FORMAT_S16_NE) &&
|
|
|
|
(af->data->format == AF_FORMAT_FLOAT_NE))
|
|
|
|
{
|
2005-01-06 15:32:08 +01:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
|
2005-02-17 16:35:44 +01:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 15:32:08 +01:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2004-12-29 20:05:29 +01:00
|
|
|
af->play = play_s16_float;
|
|
|
|
}
|
2002-10-01 08:45:08 +02:00
|
|
|
return AF_OK;
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
2002-10-31 12:06:19 +01:00
|
|
|
case AF_CONTROL_COMMAND_LINE:{
|
2005-01-03 19:59:16 +01:00
|
|
|
int format = af_str2fmt_short(arg);
|
2005-05-01 11:02:25 +02:00
|
|
|
if (format == -1) {
|
|
|
|
af_msg(AF_MSG_ERROR, "[format] %s is not a valid format\n", (char *)arg);
|
|
|
|
return AF_ERROR;
|
|
|
|
}
|
2005-01-03 19:59:16 +01:00
|
|
|
if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
|
2002-12-28 14:59:53 +01:00
|
|
|
return AF_ERROR;
|
|
|
|
return AF_OK;
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
2005-01-03 19:59:16 +01:00
|
|
|
case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
|
2002-12-28 14:59:53 +01:00
|
|
|
// Check for errors in configuraton
|
|
|
|
if(AF_OK != check_format(*(int*)arg))
|
2002-10-01 08:45:08 +02:00
|
|
|
return AF_ERROR;
|
|
|
|
|
2002-12-28 14:59:53 +01:00
|
|
|
af->data->format = *(int*)arg;
|
2005-01-03 19:59:16 +01:00
|
|
|
af->data->bps = af_fmt2bits(af->data->format)/8;
|
|
|
|
|
2002-10-01 08:45:08 +02:00
|
|
|
return AF_OK;
|
|
|
|
}
|
2005-01-03 19:59:16 +01:00
|
|
|
}
|
2002-10-01 08:45:08 +02:00
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deallocate memory
|
|
|
|
static void uninit(struct af_instance_s* af)
|
|
|
|
{
|
2007-02-10 19:12:03 +01:00
|
|
|
if (af->data)
|
|
|
|
free(af->data->audio);
|
|
|
|
free(af->data);
|
2004-05-01 22:16:54 +02:00
|
|
|
af->setup = 0;
|
2002-10-01 08:45:08 +02:00
|
|
|
}
|
|
|
|
|
2004-12-29 20:05:29 +01:00
|
|
|
static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
|
|
|
af_data_t* l = af->data; // Local data
|
|
|
|
af_data_t* c = data; // Current working data
|
|
|
|
int len = c->len/c->bps; // Lenght in samples of current audio block
|
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
endian(c->audio,l->audio,len,c->bps);
|
|
|
|
|
|
|
|
c->audio = l->audio;
|
|
|
|
c->format = l->format;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
|
|
|
af_data_t* l = af->data; // Local data
|
|
|
|
af_data_t* c = data; // Current working data
|
|
|
|
int len = c->len/4; // Lenght in samples of current audio block
|
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
float2int(c->audio, l->audio, len, 2);
|
|
|
|
|
|
|
|
c->audio = l->audio;
|
|
|
|
c->len = len*2;
|
|
|
|
c->bps = 2;
|
|
|
|
c->format = l->format;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
|
|
|
af_data_t* l = af->data; // Local data
|
|
|
|
af_data_t* c = data; // Current working data
|
|
|
|
int len = c->len/2; // Lenght in samples of current audio block
|
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int2float(c->audio, l->audio, len, 2);
|
|
|
|
|
|
|
|
c->audio = l->audio;
|
|
|
|
c->len = len*4;
|
|
|
|
c->bps = 4;
|
|
|
|
c->format = l->format;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2002-10-01 08:45:08 +02:00
|
|
|
// Filter data through filter
|
|
|
|
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
2002-11-12 13:33:56 +01:00
|
|
|
af_data_t* l = af->data; // Local data
|
|
|
|
af_data_t* c = data; // Current working data
|
|
|
|
int len = c->len/c->bps; // Lenght in samples of current audio block
|
2002-10-01 08:45:08 +02:00
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
2002-11-12 13:33:56 +01:00
|
|
|
// Change to cpu native endian format
|
|
|
|
if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
|
|
|
|
endian(c->audio,c->audio,len,c->bps);
|
2002-10-01 08:45:08 +02:00
|
|
|
|
2002-11-12 13:33:56 +01:00
|
|
|
// Conversion table
|
2004-12-28 03:00:23 +01:00
|
|
|
if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) {
|
2002-11-12 13:33:56 +01:00
|
|
|
from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
|
|
|
|
if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
|
|
|
|
to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
|
|
|
|
if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
2005-10-04 23:49:56 +02:00
|
|
|
si2us(l->audio,len,l->bps);
|
2004-12-28 03:00:23 +01:00
|
|
|
} else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) {
|
2002-11-12 13:33:56 +01:00
|
|
|
from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
|
|
|
|
if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
|
|
|
|
to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
|
|
|
|
if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
2005-10-04 23:49:56 +02:00
|
|
|
si2us(l->audio,len,l->bps);
|
2004-12-28 03:00:23 +01:00
|
|
|
} else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
|
2002-11-12 13:33:56 +01:00
|
|
|
switch(l->format&AF_FORMAT_SPECIAL_MASK){
|
|
|
|
case(AF_FORMAT_MU_LAW):
|
|
|
|
to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 08:45:08 +02:00
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 08:45:08 +02:00
|
|
|
break;
|
2002-11-13 10:09:50 +01:00
|
|
|
default:
|
|
|
|
float2int(c->audio, l->audio, len, l->bps);
|
|
|
|
if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
2005-10-04 23:49:56 +02:00
|
|
|
si2us(l->audio,len,l->bps);
|
2002-11-13 10:09:50 +01:00
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
2004-12-28 03:00:23 +01:00
|
|
|
} else {
|
2002-11-12 13:33:56 +01:00
|
|
|
// Input must be int
|
|
|
|
|
|
|
|
// Change signed/unsigned
|
|
|
|
if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
|
2005-10-04 23:49:56 +02:00
|
|
|
si2us(c->audio,len,c->bps);
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
|
|
|
// Convert to special formats
|
2002-11-13 10:09:50 +01:00
|
|
|
switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){
|
2002-11-12 13:33:56 +01:00
|
|
|
case(AF_FORMAT_MU_LAW):
|
|
|
|
to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 08:45:08 +02:00
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 08:45:08 +02:00
|
|
|
break;
|
2002-11-13 10:09:50 +01:00
|
|
|
case(AF_FORMAT_F):
|
|
|
|
int2float(c->audio, l->audio, len, c->bps);
|
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
default:
|
2002-11-13 10:09:50 +01:00
|
|
|
// Change the number of bits
|
|
|
|
if(c->bps != l->bps)
|
|
|
|
change_bps(c->audio,l->audio,len,c->bps,l->bps);
|
|
|
|
else
|
2002-11-14 10:47:46 +01:00
|
|
|
memcpy(l->audio,c->audio,len*c->bps);
|
2002-10-01 08:45:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 22:02:01 +02:00
|
|
|
|
|
|
|
// Switch from cpu native endian to the correct endianess
|
2002-11-12 13:33:56 +01:00
|
|
|
if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
|
|
|
|
endian(l->audio,l->audio,len,l->bps);
|
2002-10-01 08:45:08 +02:00
|
|
|
|
|
|
|
// Set output data
|
|
|
|
c->audio = l->audio;
|
2002-11-12 13:33:56 +01:00
|
|
|
c->len = len*l->bps;
|
2002-10-01 08:45:08 +02:00
|
|
|
c->bps = l->bps;
|
|
|
|
c->format = l->format;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate memory and set function pointers
|
|
|
|
static int open(af_instance_t* af){
|
|
|
|
af->control=control;
|
|
|
|
af->uninit=uninit;
|
|
|
|
af->play=play;
|
|
|
|
af->mul.n=1;
|
|
|
|
af->mul.d=1;
|
|
|
|
af->data=calloc(1,sizeof(af_data_t));
|
|
|
|
if(af->data == NULL)
|
|
|
|
return AF_ERROR;
|
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Description of this filter
|
|
|
|
af_info_t af_info_format = {
|
|
|
|
"Sample format conversion",
|
|
|
|
"format",
|
|
|
|
"Anders",
|
|
|
|
"",
|
2002-10-06 13:26:14 +02:00
|
|
|
AF_FLAGS_REENTRANT,
|
2002-10-01 08:45:08 +02:00
|
|
|
open
|
|
|
|
};
|
2002-11-12 13:33:56 +01:00
|
|
|
|
2004-05-16 12:48:59 +02:00
|
|
|
static inline uint32_t load24bit(void* data, int pos) {
|
|
|
|
#if WORDS_BIGENDIAN
|
|
|
|
return (((uint32_t)((uint8_t*)data)[3*pos])<<24) |
|
|
|
|
(((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
|
|
|
|
(((uint32_t)((uint8_t*)data)[3*pos+2])<<8);
|
|
|
|
#else
|
|
|
|
return (((uint32_t)((uint8_t*)data)[3*pos])<<8) |
|
|
|
|
(((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
|
|
|
|
(((uint32_t)((uint8_t*)data)[3*pos+2])<<24);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void store24bit(void* data, int pos, uint32_t expanded_value) {
|
|
|
|
#if WORDS_BIGENDIAN
|
|
|
|
((uint8_t*)data)[3*pos]=expanded_value>>24;
|
|
|
|
((uint8_t*)data)[3*pos+1]=expanded_value>>16;
|
|
|
|
((uint8_t*)data)[3*pos+2]=expanded_value>>8;
|
|
|
|
#else
|
|
|
|
((uint8_t*)data)[3*pos]=expanded_value>>8;
|
|
|
|
((uint8_t*)data)[3*pos+1]=expanded_value>>16;
|
|
|
|
((uint8_t*)data)[3*pos+2]=expanded_value>>24;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-11-12 13:33:56 +01:00
|
|
|
// Function implementations used by play
|
|
|
|
static void endian(void* in, void* out, int len, int bps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(2):{
|
|
|
|
for(i=0;i<len;i++){
|
2004-05-18 21:13:15 +02:00
|
|
|
((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]);
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):{
|
|
|
|
register uint8_t s;
|
|
|
|
for(i=0;i<len;i++){
|
|
|
|
s=((uint8_t*)in)[3*i];
|
|
|
|
((uint8_t*)out)[3*i]=((uint8_t*)in)[3*i+2];
|
2004-05-16 18:21:33 +02:00
|
|
|
if (in != out)
|
|
|
|
((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1];
|
2004-05-16 12:48:59 +02:00
|
|
|
((uint8_t*)out)[3*i+2]=s;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):{
|
|
|
|
for(i=0;i<len;i++){
|
2004-05-18 21:13:15 +02:00
|
|
|
((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]);
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-04 23:49:56 +02:00
|
|
|
static void si2us(void* data, int len, int bps)
|
2002-11-12 13:33:56 +01:00
|
|
|
{
|
2005-10-04 23:49:56 +02:00
|
|
|
register long i = -(len * bps);
|
|
|
|
register uint8_t *p = &((uint8_t *)data)[len * bps];
|
|
|
|
#if AF_FORMAT_NE == AF_FORMAT_LE
|
|
|
|
p += bps - 1;
|
|
|
|
#endif
|
|
|
|
if (len <= 0) return;
|
|
|
|
do {
|
|
|
|
p[i] ^= 0x80;
|
|
|
|
} while (i += bps);
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void change_bps(void* in, void* out, int len, int inbps, int outbps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(inbps){
|
|
|
|
case(1):
|
|
|
|
switch(outbps){
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8;
|
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24);
|
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
switch(outbps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8);
|
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16);
|
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
switch(outbps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24);
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16);
|
|
|
|
break;
|
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint32_t*)out)[i]=(uint32_t)load24bit(in, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):
|
|
|
|
switch(outbps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24);
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16);
|
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t*)in)[i]);
|
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 17:48:18 +01:00
|
|
|
static void float2int(float* in, void* out, int len, int bps)
|
2002-11-12 13:33:56 +01:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
((int8_t*)out)[i] = lrintf(127.0 * in[i]);
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
((int16_t*)out)[i] = lrintf(32767.0 * in[i]);
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
store24bit(out, i, lrintf(2147483647.0 * in[i]));
|
2004-05-16 12:48:59 +02:00
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
((int32_t*)out)[i] = lrintf(2147483647.0 * in[i]);
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 17:48:18 +01:00
|
|
|
static void int2float(void* in, float* out, int len, int bps)
|
2002-11-12 13:33:56 +01:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
out[i]=(1.0/128.0)*((int8_t*)in)[i];
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
out[i]=(1.0/32768.0)*((int16_t*)in)[i];
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
2004-05-16 12:48:59 +02:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
out[i]=(1.0/2147483648.0)*((int32_t)load24bit(in, i));
|
2004-05-16 12:48:59 +02:00
|
|
|
break;
|
2002-11-12 13:33:56 +01:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 17:48:18 +01:00
|
|
|
out[i]=(1.0/2147483648.0)*((int32_t*)in)[i];
|
2002-11-12 13:33:56 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|