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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
#include "af.h"
|
2004-05-18 19:13:15 +00:00
|
|
|
#include "../bswap.h"
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-11-13 09:09:50 +00:00
|
|
|
// Integer to float conversion through lrintf()
|
|
|
|
#ifdef HAVE_LRINTF
|
|
|
|
#define __USE_ISOC99 1
|
|
|
|
#include <math.h>
|
|
|
|
#else
|
|
|
|
#define lrintf(x) ((int)(x))
|
|
|
|
#endif
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-11-12 12:33:56 +00: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);
|
|
|
|
// From singed to unsigned
|
|
|
|
static void si2us(void* in, void* out, int len, int bps);
|
|
|
|
// From unsinged to signed
|
|
|
|
static void us2si(void* in, void* out, int len, int bps);
|
|
|
|
// 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
|
|
|
|
static void float2int(void* in, void* out, int len, int bps);
|
|
|
|
// From signed int to float
|
|
|
|
static void int2float(void* in, void* out, int len, int bps);
|
|
|
|
|
|
|
|
// Convert from string to format
|
|
|
|
static int str2fmt(char* str)
|
|
|
|
{
|
|
|
|
int format=0;
|
|
|
|
// Scan for endianess
|
|
|
|
if(strstr(str,"be") || strstr(str,"BE"))
|
|
|
|
format |= AF_FORMAT_BE;
|
|
|
|
else if(strstr(str,"le") || strstr(str,"LE"))
|
|
|
|
format |= AF_FORMAT_LE;
|
|
|
|
else
|
|
|
|
format |= AF_FORMAT_NE;
|
|
|
|
|
|
|
|
// Scan for special formats
|
|
|
|
if(strstr(str,"mulaw") || strstr(str,"MULAW")){
|
|
|
|
format |= AF_FORMAT_MU_LAW; return format;
|
|
|
|
}
|
|
|
|
if(strstr(str,"alaw") || strstr(str,"ALAW")){
|
|
|
|
format |= AF_FORMAT_A_LAW; return format;
|
|
|
|
}
|
|
|
|
if(strstr(str,"ac3") || strstr(str,"AC3")){
|
|
|
|
format |= AF_FORMAT_AC3; return format;
|
|
|
|
}
|
|
|
|
if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){
|
|
|
|
format |= AF_FORMAT_MPEG2; return format;
|
|
|
|
}
|
|
|
|
if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){
|
|
|
|
format |= AF_FORMAT_IMA_ADPCM; return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan for int/float
|
|
|
|
if(strstr(str,"float") || strstr(str,"FLOAT")){
|
|
|
|
format |= AF_FORMAT_F; return format;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
format |= AF_FORMAT_I;
|
|
|
|
|
|
|
|
// Scan for signed/unsigned
|
|
|
|
if(strstr(str,"unsigned") || strstr(str,"UNSIGNED"))
|
|
|
|
format |= AF_FORMAT_US;
|
|
|
|
else
|
|
|
|
format |= AF_FORMAT_SI;
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
/* Convert format to str input str is a buffer for the
|
|
|
|
converted string, size is the size of the buffer */
|
2003-01-18 17:31:58 +00:00
|
|
|
char* fmt2str(int format, char* str, size_t size)
|
2002-10-01 06:45:08 +00:00
|
|
|
{
|
2002-11-12 12:33:56 +00:00
|
|
|
int i=0;
|
|
|
|
// Print endinaness
|
|
|
|
if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK))
|
|
|
|
i+=snprintf(str,size,"little endian ");
|
|
|
|
else
|
|
|
|
i+=snprintf(str,size,"big endian ");
|
|
|
|
|
|
|
|
if(format & AF_FORMAT_SPECIAL_MASK){
|
|
|
|
switch(format & AF_FORMAT_SPECIAL_MASK){
|
|
|
|
case(AF_FORMAT_MU_LAW):
|
|
|
|
i+=snprintf(&str[i],size-i,"mu law "); break;
|
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
i+=snprintf(&str[i],size-i,"A law "); break;
|
|
|
|
case(AF_FORMAT_MPEG2):
|
|
|
|
i+=snprintf(&str[i],size-i,"MPEG 2 "); break;
|
|
|
|
case(AF_FORMAT_AC3):
|
|
|
|
i+=snprintf(&str[i],size-i,"AC3 "); break;
|
|
|
|
}
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
2002-11-12 12:33:56 +00:00
|
|
|
else{
|
|
|
|
// Point
|
|
|
|
if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
|
|
|
|
i+=snprintf(&str[i],size,"float ");
|
|
|
|
else{
|
|
|
|
// Sign
|
|
|
|
if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK))
|
|
|
|
i+=snprintf(&str[i],size-i,"unsigned ");
|
|
|
|
else
|
|
|
|
i+=snprintf(&str[i],size-i,"signed ");
|
2002-10-01 06:45:08 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
i+=snprintf(&str[i],size,"int ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
|
|
|
|
2002-12-28 13:59:53 +00:00
|
|
|
// Helper functions to check sanity for input arguments
|
|
|
|
|
|
|
|
// Sanity check for bytes per sample
|
|
|
|
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
|
|
|
|
int check_format(int format)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
switch(format & AF_FORMAT_SPECIAL_MASK){
|
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",
|
2002-12-28 13:59:53 +00:00
|
|
|
fmt2str(format,buf,255));
|
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];
|
2002-10-01 06:45:08 +00:00
|
|
|
// Make sure this filter isn't redundant
|
2002-11-12 12:33:56 +00:00
|
|
|
if(af->data->format == ((af_data_t*)arg)->format &&
|
|
|
|
af->data->bps == ((af_data_t*)arg)->bps)
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_DETACH;
|
2002-12-28 13:59:53 +00:00
|
|
|
|
2002-11-13 09:09:50 +00:00
|
|
|
// Check for errors in configuraton
|
2002-12-28 13:59:53 +00:00
|
|
|
if((AF_OK != check_bps(((af_data_t*)arg)->bps)) ||
|
|
|
|
(AF_OK != check_format(((af_data_t*)arg)->format)) ||
|
|
|
|
(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;
|
|
|
|
|
|
|
|
af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %ibit %sto %ibit %s \n",
|
2002-11-13 09:09:50 +00:00
|
|
|
((af_data_t*)arg)->bps*8,fmt2str(((af_data_t*)arg)->format,buf1,255),
|
|
|
|
af->data->bps*8,fmt2str(af->data->format,buf2,255));
|
2002-10-01 06:45:08 +00:00
|
|
|
|
|
|
|
af->data->rate = ((af_data_t*)arg)->rate;
|
|
|
|
af->data->nch = ((af_data_t*)arg)->nch;
|
|
|
|
af->mul.n = af->data->bps;
|
|
|
|
af->mul.d = ((af_data_t*)arg)->bps;
|
|
|
|
return AF_OK;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2002-10-31 11:06:19 +00:00
|
|
|
case AF_CONTROL_COMMAND_LINE:{
|
2002-12-28 13:59:53 +00:00
|
|
|
int bps = 2;
|
|
|
|
int format = AF_FORMAT_NE;
|
2002-11-12 12:33:56 +00:00
|
|
|
char str[256];
|
2002-11-13 09:09:50 +00:00
|
|
|
str[0] = '\0';
|
2002-12-28 13:59:53 +00:00
|
|
|
sscanf((char*)arg,"%i:%s",&bps,str);
|
2002-11-12 12:33:56 +00:00
|
|
|
// Convert string to format
|
2002-12-28 13:59:53 +00:00
|
|
|
format = str2fmt(str);
|
2002-11-13 09:09:50 +00:00
|
|
|
|
2002-11-12 12:33:56 +00:00
|
|
|
// Automatic correction of errors
|
2002-12-28 13:59:53 +00:00
|
|
|
switch(format & AF_FORMAT_SPECIAL_MASK){
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
case(AF_FORMAT_MU_LAW):
|
2002-12-28 13:59:53 +00:00
|
|
|
bps=1; break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_AC3):
|
2002-12-28 13:59:53 +00:00
|
|
|
bps=4; break; // I think
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2002-12-28 13:59:53 +00:00
|
|
|
if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
|
|
|
|
bps=4;
|
|
|
|
|
|
|
|
if((AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET,&bps)) ||
|
|
|
|
(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)))
|
|
|
|
return AF_ERROR;
|
|
|
|
return AF_OK;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
2002-12-28 13:59:53 +00:00
|
|
|
case AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET:
|
2002-10-01 06:45:08 +00:00
|
|
|
// Reinit must be called after this function has been called
|
|
|
|
|
2002-11-13 09:09:50 +00:00
|
|
|
// Check for errors in configuraton
|
2002-12-28 13:59:53 +00:00
|
|
|
if(AF_OK != check_bps(*(int*)arg))
|
|
|
|
return AF_ERROR;
|
|
|
|
|
|
|
|
af->data->bps = *(int*)arg;
|
|
|
|
return AF_OK;
|
|
|
|
case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:
|
|
|
|
// Reinit must be called after this function has been called
|
|
|
|
|
|
|
|
// Check for errors in configuraton
|
|
|
|
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;
|
2002-10-01 06:45:08 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deallocate memory
|
|
|
|
static void uninit(struct af_instance_s* af)
|
|
|
|
{
|
|
|
|
if(af->data)
|
|
|
|
free(af->data);
|
2004-05-01 20:16:54 +00:00
|
|
|
af->setup = 0;
|
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
|
|
|
|
int len = c->len/c->bps; // Lenght 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
|
|
|
|
switch(c->format & ~AF_FORMAT_END_MASK){
|
|
|
|
case(AF_FORMAT_MU_LAW):
|
|
|
|
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)
|
|
|
|
si2us(l->audio,l->audio,len,l->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_A_LAW):
|
|
|
|
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)
|
|
|
|
si2us(l->audio,l->audio,len,l->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(AF_FORMAT_F):
|
|
|
|
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)
|
|
|
|
si2us(l->audio,l->audio,len,l->bps);
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Input must be int
|
|
|
|
|
|
|
|
// Change signed/unsigned
|
|
|
|
if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
|
|
|
|
if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
|
|
|
|
us2si(c->audio,c->audio,len,c->bps);
|
|
|
|
else
|
|
|
|
si2us(c->audio,c->audio,len,c->bps);
|
|
|
|
}
|
|
|
|
// 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
|
2002-11-14 09:47:46 +00:00
|
|
|
memcpy(l->audio,c->audio,len*c->bps);
|
2002-10-01 06:45:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-11-13 09:09:50 +00:00
|
|
|
break;
|
2002-10-01 06:45:08 +00:00
|
|
|
}
|
2002-10-12 20:02:01 +00:00
|
|
|
|
|
|
|
// Switch from cpu native endian to the correct endianess
|
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
|
|
|
|
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 11:26:14 +00:00
|
|
|
AF_FLAGS_REENTRANT,
|
2002-10-01 06:45:08 +00:00
|
|
|
open
|
|
|
|
};
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void si2us(void* in, void* out, int len, int bps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i]));
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i]));
|
|
|
|
break;
|
2004-05-16 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i)));
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void us2si(void* in, void* out, int len, int bps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i]));
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i]));
|
|
|
|
break;
|
2004-05-16 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
store24bit(out, i, (int32_t)(INT_MIN+(uint32_t)load24bit(in, i)));
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void float2int(void* in, void* out, int len, int bps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
2002-11-13 09:09:50 +00:00
|
|
|
((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
2002-11-13 09:09:50 +00:00
|
|
|
((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)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++)
|
|
|
|
store24bit(out, i, (int32_t)lrintf(INT_MAX*((float*)in)[i]));
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
2002-11-13 09:09:50 +00:00
|
|
|
((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]);
|
2002-11-12 12:33:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void int2float(void* in, void* out, int len, int bps)
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
switch(bps){
|
|
|
|
case(1):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]);
|
|
|
|
break;
|
|
|
|
case(2):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]);
|
|
|
|
break;
|
2004-05-16 10:48:59 +00:00
|
|
|
case(3):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t)load24bit(in, i)));
|
|
|
|
break;
|
2002-11-12 12:33:56 +00:00
|
|
|
case(4):
|
|
|
|
for(i=0;i<len;i++)
|
|
|
|
((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|