2002-10-01 06:45:08 +00: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 16:48:18 +00:00
|
|
|
// Must be defined before any libc headers are included!
|
|
|
|
#define _ISOC9X_SOURCE
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2005-02-24 16:48:18 +00: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-28 23:13:08 +00:00
|
|
|
#include "af.h"
|
2006-11-29 15:02:45 +00:00
|
|
|
#include "libavutil/common.h"
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2006-11-28 23:13:08 +00:00
|
|
|
#include "libvo/fastmemcpy.h"
|
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
/* Functions used by play to convert the input audio to the correct
|
|
|
|
format */
|
|
|
|
|
2007-09-19 15:44:09 +00:00
|
|
|
/* The below includes retrieves functions for converting to and from
|
2002-11-12 12:33:56 +00:00
|
|
|
ulaw and alaw */
|
|
|
|
#include "af_format_ulaw.c"
|
|
|
|
#include "af_format_alaw.c"
|
|
|
|
|
2007-09-19 15:44:09 +00:00
|
|
|
// Switch endianness
|
2002-11-12 12:33:56 +00:00
|
|
|
static void endian(void* in, void* out, int len, int bps);
|
2007-09-19 15:44:09 +00:00
|
|
|
// From signed to unsigned and the other way
|
2005-10-04 21:49:56 +00:00
|
|
|
static void si2us(void* data, int len, int bps);
|
2002-11-12 12:33:56 +00: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 16:48:18 +00:00
|
|
|
static void float2int(float* in, void* out, int len, int bps);
|
2002-11-12 12:33:56 +00:00
|
|
|
// From signed int to float
|
2005-02-24 16:48:18 +00:00
|
|
|
static void int2float(void* in, float* out, int len, int bps);
|
2002-11-12 12:33:56 +00:00
|
|
|
|
2004-12-29 19:05:29 +00: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 13:59:53 +00:00
|
|
|
// Helper functions to check sanity for input arguments
|
|
|
|
|
|
|
|
// Sanity check for bytes per sample
|
2004-11-20 10:32:52 +00:00
|
|
|
static int check_bps(int bps)
|
2002-11-13 09:09:50 +00:00
|
|
|
{
|
2004-05-16 10:48:59 +00:00
|
|
|
if(bps != 4 && bps != 3 && bps != 2 && bps != 1){
|
2002-12-28 13:59:53 +00:00
|
|
|
af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample"
|
2004-05-16 10:48:59 +00:00
|
|
|
" must be 1, 2, 3 or 4. Current value is %i \n",bps);
|
2002-11-13 09:09:50 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
2002-12-28 13:59:53 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
2002-11-13 09:09:50 +00:00
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
// Check for unsupported formats
|
2004-11-20 10:32:52 +00:00
|
|
|
static int check_format(int format)
|
2002-12-28 13:59:53 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
switch(format & AF_FORMAT_SPECIAL_MASK){
|
2005-01-03 18:59:16 +00:00
|
|
|
case(AF_FORMAT_IMA_ADPCM):
|
2002-11-13 09:09:50 +00: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 14:32:08 +00:00
|
|
|
af_fmt2str(format,buf,256));
|
2002-11-13 09:09:50 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
return AF_OK;
|
2002-12-28 13:59:53 +00:00
|
|
|
}
|
2002-11-13 09:09:50 +00:00
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Initialization and runtime control
|
|
|
|
static int control(struct af_instance_s* af, int cmd, void* arg)
|
|
|
|
{
|
|
|
|
switch(cmd){
|
2002-11-12 12:33:56 +00:00
|
|
|
case AF_CONTROL_REINIT:{
|
|
|
|
char buf1[256];
|
|
|
|
char buf2[256];
|
2004-12-29 19:05:29 +00:00
|
|
|
af_data_t *data = arg;
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
// Make sure this filter isn't redundant
|
2005-02-17 15:35:44 +00:00
|
|
|
if(af->data->format == data->format &&
|
|
|
|
af->data->bps == data->bps)
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_DETACH;
|
2002-12-28 13:59:53 +00:00
|
|
|
|
2007-09-16 09:00:45 +00:00
|
|
|
// Check for errors in configuration
|
2005-02-17 15:35:44 +00:00
|
|
|
if((AF_OK != check_bps(data->bps)) ||
|
|
|
|
(AF_OK != check_format(data->format)) ||
|
2002-12-28 13:59:53 +00:00
|
|
|
(AF_OK != check_bps(af->data->bps)) ||
|
|
|
|
(AF_OK != check_format(af->data->format)))
|
2002-11-12 12:33:56 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
|
2005-01-06 14:32:08 +00:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %s to %s\n",
|
2005-02-17 15:35:44 +00:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 14:32:08 +00:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2005-02-17 15:35:44 +00:00
|
|
|
af->data->rate = data->rate;
|
|
|
|
af->data->nch = data->nch;
|
2007-11-01 06:52:01 +00:00
|
|
|
af->mul = (double)af->data->bps / data->bps;
|
2004-12-29 19:05:29 +00:00
|
|
|
|
|
|
|
af->play = play; // set default
|
|
|
|
|
2007-09-19 15:44:09 +00:00
|
|
|
// look whether only endianness differences are there
|
2004-12-29 19:05:29 +00:00
|
|
|
if ((af->data->format & ~AF_FORMAT_END_MASK) ==
|
|
|
|
(data->format & ~AF_FORMAT_END_MASK))
|
|
|
|
{
|
2007-09-19 15:44:09 +00:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianness conversion only\n");
|
2004-12-29 19:05:29 +00:00
|
|
|
af->play = play_swapendian;
|
|
|
|
}
|
|
|
|
if ((data->format == AF_FORMAT_FLOAT_NE) &&
|
|
|
|
(af->data->format == AF_FORMAT_S16_NE))
|
|
|
|
{
|
2005-01-06 14:32:08 +00:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
|
2005-02-17 15:35:44 +00:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 14:32:08 +00:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2004-12-29 19:05:29 +00:00
|
|
|
af->play = play_float_s16;
|
|
|
|
}
|
|
|
|
if ((data->format == AF_FORMAT_S16_NE) &&
|
|
|
|
(af->data->format == AF_FORMAT_FLOAT_NE))
|
|
|
|
{
|
2005-01-06 14:32:08 +00:00
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
|
2005-02-17 15:35:44 +00:00
|
|
|
af_fmt2str(data->format,buf1,256),
|
2005-01-06 14:32:08 +00:00
|
|
|
af_fmt2str(af->data->format,buf2,256));
|
2004-12-29 19:05:29 +00:00
|
|
|
af->play = play_s16_float;
|
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_OK;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2002-10-31 11:06:19 +00:00
|
|
|
case AF_CONTROL_COMMAND_LINE:{
|
2005-01-03 18:59:16 +00:00
|
|
|
int format = af_str2fmt_short(arg);
|
2005-05-01 09:02:25 +00: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 18:59:16 +00:00
|
|
|
if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
|
2002-12-28 13:59:53 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
return AF_OK;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2005-01-03 18:59:16 +00:00
|
|
|
case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
|
2007-09-19 15:44:09 +00:00
|
|
|
// Check for errors in configuration
|
2002-12-28 13:59:53 +00:00
|
|
|
if(AF_OK != check_format(*(int*)arg))
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
af->data->format = *(int*)arg;
|
2005-01-03 18:59:16 +00:00
|
|
|
af->data->bps = af_fmt2bits(af->data->format)/8;
|
|
|
|
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
2005-01-03 18:59:16 +00:00
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deallocate memory
|
|
|
|
static void uninit(struct af_instance_s* af)
|
|
|
|
{
|
2007-02-10 18:12:03 +00:00
|
|
|
if (af->data)
|
|
|
|
free(af->data->audio);
|
|
|
|
free(af->data);
|
2004-05-01 20:16:54 +00:00
|
|
|
af->setup = 0;
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-29 19:05:29 +00: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
|
2007-09-19 15:44:09 +00:00
|
|
|
int len = c->len/c->bps; // Length in samples of current audio block
|
2004-12-29 19:05:29 +00:00
|
|
|
|
|
|
|
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
|
2007-09-19 15:44:09 +00:00
|
|
|
int len = c->len/4; // Length in samples of current audio block
|
2004-12-29 19:05:29 +00:00
|
|
|
|
|
|
|
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
|
2007-09-19 15:44:09 +00:00
|
|
|
int len = c->len/2; // Length in samples of current audio block
|
2004-12-29 19:05:29 +00:00
|
|
|
|
|
|
|
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 06:45:08 +00:00
|
|
|
// Filter data through filter
|
|
|
|
static af_data_t* play(struct af_instance_s* af, af_data_t* data)
|
|
|
|
{
|
2002-11-12 12:33:56 +00:00
|
|
|
af_data_t* l = af->data; // Local data
|
|
|
|
af_data_t* c = data; // Current working data
|
2007-09-19 15:44:09 +00:00
|
|
|
int len = c->len/c->bps; // Length in samples of current audio block
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
|
|
|
|
return NULL;
|
|
|
|
|
2002-11-12 12:33:56 +00: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 06:45:08 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
// Conversion table
|
2004-12-28 02:00:23 +00:00
|
|
|
if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) {
|
2002-11-12 12:33:56 +00: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 21:49:56 +00:00
|
|
|
si2us(l->audio,len,l->bps);
|
2004-12-28 02:00:23 +00:00
|
|
|
} else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) {
|
2002-11-12 12:33:56 +00: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 21:49:56 +00:00
|
|
|
si2us(l->audio,len,l->bps);
|
2004-12-28 02:00:23 +00:00
|
|
|
} else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
|
2002-11-12 12:33:56 +00: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 06:45:08 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
2002-11-13 09:09:50 +00:00
|
|
|
default:
|
|
|
|
float2int(c->audio, l->audio, len, l->bps);
|
|
|
|
if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
2005-10-04 21:49:56 +00:00
|
|
|
si2us(l->audio,len,l->bps);
|
2002-11-13 09:09:50 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2004-12-28 02:00:23 +00:00
|
|
|
} else {
|
2002-11-12 12:33:56 +00:00
|
|
|
// Input must be int
|
|
|
|
|
|
|
|
// Change signed/unsigned
|
|
|
|
if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
|
2005-10-04 21:49:56 +00:00
|
|
|
si2us(c->audio,len,c->bps);
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
|
|
|
// Convert to special formats
|
2002-11-13 09:09:50 +00:00
|
|
|
switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_MU_LAW):
|
|
|
|
to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
2002-11-13 09:09:50 +00:00
|
|
|
case(AF_FORMAT_F):
|
|
|
|
int2float(c->audio, l->audio, len, c->bps);
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
default:
|
2002-11-13 09:09:50 +00:00
|
|
|
// Change the number of bits
|
|
|
|
if(c->bps != l->bps)
|
|
|
|
change_bps(c->audio,l->audio,len,c->bps,l->bps);
|
|
|
|
else
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(l->audio,c->audio,len*c->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 20:02:01 +00:00
|
|
|
|
2007-09-19 15:44:09 +00:00
|
|
|
// Switch from cpu native endian to the correct endianness
|
2002-11-12 12:33:56 +00:00
|
|
|
if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
|
|
|
|
endian(l->audio,l->audio,len,l->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
// Set output data
|
|
|
|
c->audio = l->audio;
|
2002-11-12 12:33:56 +00:00
|
|
|
c->len = len*l->bps;
|
2002-10-01 06:45:08 +00:00
|
|
|
c->bps = l->bps;
|
|
|
|
c->format = l->format;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate memory and set function pointers
|
2007-03-20 09:46:00 +00:00
|
|
|
static int af_open(af_instance_t* af){
|
2002-10-01 06:45:08 +00:00
|
|
|
af->control=control;
|
|
|
|
af->uninit=uninit;
|
|
|
|
af->play=play;
|
2007-11-01 06:52:01 +00:00
|
|
|
af->mul=1;
|
2002-10-01 06:45:08 +00:00
|
|
|
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 11:26:14 +00:00
|
|
|
AF_FLAGS_REENTRANT,
|
2007-03-20 09:46:00 +00:00
|
|
|
af_open
|
2002-10-01 06:45:08 +00:00
|
|
|
};
|
2002-11-12 12:33:56 +00:00
|
|
|
|
2004-05-16 10:48:59 +00: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 12:33:56 +00: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 19:13:15 +00:00
|
|
|
((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-05-16 10:48:59 +00: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 16:21:33 +00:00
|
|
|
if (in != out)
|
|
|
|
((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1];
|
2004-05-16 10:48:59 +00:00
|
|
|
((uint8_t*)out)[3*i+2]=s;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):{
|
|
|
|
for(i=0;i<len;i++){
|
2004-05-18 19:13:15 +00:00
|
|
|
((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-04 21:49:56 +00:00
|
|
|
static void si2us(void* data, int len, int bps)
|
2002-11-12 12:33:56 +00:00
|
|
|
{
|
2005-10-04 21:49:56 +00: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 12:33:56 +00: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 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24);
|
|
|
|
break;
|
2002-11-12 12:33:56 +00: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 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16);
|
|
|
|
break;
|
2002-11-12 12:33:56 +00: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 10:48:59 +00: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 12:33:56 +00: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 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, ((uint32_t*)in)[i]);
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 16:48:18 +00:00
|
|
|
static void float2int(float* in, void* out, int len, int bps)
|
2002-11-12 12:33:56 +00:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
((int8_t*)out)[i] = lrintf(127.0 * in[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
((int16_t*)out)[i] = lrintf(32767.0 * in[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
2004-05-16 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
store24bit(out, i, lrintf(2147483647.0 * in[i]));
|
2004-05-16 10:48:59 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
((int32_t*)out)[i] = lrintf(2147483647.0 * in[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 16:48:18 +00:00
|
|
|
static void int2float(void* in, float* out, int len, int bps)
|
2002-11-12 12:33:56 +00:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
out[i]=(1.0/128.0)*((int8_t*)in)[i];
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
out[i]=(1.0/32768.0)*((int16_t*)in)[i];
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
2004-05-16 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
out[i]=(1.0/2147483648.0)*((int32_t)load24bit(in, i));
|
2004-05-16 10:48:59 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
2005-02-24 16:48:18 +00:00
|
|
|
out[i]=(1.0/2147483648.0)*((int32_t*)in)[i];
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|