Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial VBAP work, Float32 work, capture work, bug fixes, etc...lots of
changes.
  • Loading branch information
icculus committed Jan 27, 2004
1 parent 1899300 commit 4b078ab
Show file tree
Hide file tree
Showing 24 changed files with 2,548 additions and 586 deletions.
60 changes: 39 additions & 21 deletions osx/AL_EXT_vorbis/al_ext_vorbis.c
Expand Up @@ -94,13 +94,22 @@ static inline ALvoid __alMixVorbisMono(ALcontext *ctx, ALsource *src,
Float32 *dst, Float32 *in, long samples,
UInt32 devchannels)
{
register Float32 gainLeft;
register Float32 gainRight;
register Float32 sample;
register Float32 gain0;
register Float32 gain1;
register Float32 gain2;
register ALsizei channel0;
register ALsizei channel1;
register ALsizei channel2;

__alRecalcMonoSource(ctx, src);
gainLeft = src->channelGains[0];
gainRight = src->channelGains[1];

gain0 = src->channelGain0;
gain1 = src->channelGain1;
gain2 = src->channelGain2;
channel0 = src->channel0;
channel1 = src->channel1;
channel2 = src->channel2;

/* !!! FIXME: write altivec version and precalc whether we should use it.
if ( (__alHasEnabledVectorUnit) && (channels == 2)
Expand All @@ -114,8 +123,9 @@ static inline ALvoid __alMixVorbisMono(ALcontext *ctx, ALsource *src,
{
sample = *in;
in++;
dst[0] += sample * gainLeft;
dst[1] += sample * gainRight;
dst[channel0] += sample * gain0;
dst[channel1] += sample * gain1;
dst[channel2] += sample * gain2;
dst += devchannels;
} // while
} // __alMixVorbisMono
Expand All @@ -125,7 +135,8 @@ static inline ALvoid __alMixVorbisStereo_altivec(ALcontext *ctx, ALsource *src,
Float32 *_dst, Float32 *_left,
Float32 *_right, long _samples)
{
register Float32 gain = src->gain * ctx->listener.Gain;
register Float32 gainLeft;
register Float32 gainRight;
register long samples = _samples;
register Float32 *dst = _dst;
register Float32 *left = _left;
Expand All @@ -141,8 +152,13 @@ static inline ALvoid __alMixVorbisStereo_altivec(ALcontext *ctx, ALsource *src,
register vector unsigned char permute2 = vec_splat_u8(8);
permute2 = vec_add(permute1, permute2);

if (EPSILON_EQUAL(gain, 1.0f)) // No attenuation, just interleave the samples and mix.
gainLeft = gainRight = src->gain * ctx->listener.Gain;
gainLeft *= ctx->device->speakergains[0];
gainRight *= ctx->device->speakergains[1];

if ( (EPSILON_EQUAL(gainLeft, 1.0f)) && (EPSILON_EQUAL(gainRight, 1.0f)) )
{
// No attenuation, just interleave the samples and mix.
while (samples >= 4)
{
vLeft = vec_ld(0, left);
Expand Down Expand Up @@ -179,7 +195,8 @@ static inline ALvoid __alMixVorbisStereo_altivec(ALcontext *ctx, ALsource *src,
vector float v;
float f[4];
} conv;
conv.f[0] = conv.f[1] = conv.f[2] = conv.f[3] = gain;
conv.f[0] = conv.f[2] = gainLeft;
conv.f[1] = conv.f[3] = gainRight;
vGain = vec_ld(0, &conv.v);

while (samples >= 4)
Expand All @@ -202,8 +219,8 @@ static inline ALvoid __alMixVorbisStereo_altivec(ALcontext *ctx, ALsource *src,

while (samples--) // catch overflow.
{
dst[0] += (*left) * gain;
dst[1] += (*right) * gain;
dst[0] += (*left) * gainLeft;
dst[1] += (*right) * gainRight;
dst += 2;
left++;
right++;
Expand All @@ -224,10 +241,16 @@ static inline ALvoid __alMixVorbisStereo(ALcontext *ctx, ALsource *src,
} // if
else
{
register Float32 gain = src->gain * ctx->listener.Gain;
register Float32 gainLeft;
register Float32 gainRight;

gainLeft = gainRight = src->gain * ctx->listener.Gain;
gainLeft *= ctx->device->speakergains[0];
gainRight *= ctx->device->speakergains[1];

if (EPSILON_EQUAL(gain, 1.0f)) // No attenuation, just interleave the samples and mix.
if ( (EPSILON_EQUAL(gainLeft, 1.0f)) && (EPSILON_EQUAL(gainRight, 1.0f)) )
{
// No attenuation, just interleave the samples and mix.
while (samples--)
{
dst[0] += *left;
Expand All @@ -241,8 +264,8 @@ static inline ALvoid __alMixVorbisStereo(ALcontext *ctx, ALsource *src,
{
while (samples--)
{
dst[0] += (*left) * gain;
dst[1] += (*right) * gain;
dst[0] += (*left) * gainLeft;
dst[1] += (*right) * gainRight;
dst += devchans;
left++;
right++;
Expand Down Expand Up @@ -358,18 +381,13 @@ static ALvoid __alDeleteBufferVorbis(ALbuffer *buf)
} // __alDeleteBufferVorbis


ALboolean __alBufferDataFromVorbis(ALcontext *ctx, ALbuffer *buf,
ALvoid *_src, ALsizei size, ALsizei freq)
ALvoid __alBufferDataFromVorbis(ALbuffer *buf)
{
buf->prepareBuffer = __alPrepareBufferVorbis;
buf->processedBuffer = __alProcessedBufferVorbis;
buf->rewindBuffer = __alRewindBufferVorbis;
buf->deleteBuffer = __alDeleteBufferVorbis;
buf->mixFunc = __alMixVorbis;

// !!! FIXME: Use vm_copy?
memcpy(buf->mixData, _src, buf->allocatedSpace);
return(AL_TRUE);
} // __alBufferDataFromVorbis

// end of al_ext_vorbis.c ...
Expand Down
4 changes: 2 additions & 2 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/block.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: PCM data vector blocking, windowing and dis/reassembly
last mod: $Id: block.c,v 1.2 2003/10/20 03:26:15 icculus Exp $
last mod: $Id: block.c,v 1.3 2004/01/27 18:39:13 icculus Exp $
Handle windowing, overlap-add, etc of the PCM vectors. This is made
more amusing by Vorbis' current two allowed block sizes.
Expand Down Expand Up @@ -483,7 +483,7 @@ int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
codec_setup_info *ci=vi->codec_setup;
backend_lookup_state *b=v->backend_state;
vorbis_look_psy_global *g=b->psy_g_look;
vorbis_info_psy_global *gi=&ci->psy_g_param;
/*vorbis_info_psy_global *gi=&ci->psy_g_param;*/
long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;

Expand Down
4 changes: 2 additions & 2 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/envelope.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: PCM data envelope analysis
last mod: $Id: envelope.c,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: envelope.c,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -358,7 +358,7 @@ void _ve_envelope_shift(envelope_lookup *e,long shift){
int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
ahead of ve->current */
int smallshift=shift/e->searchstep;
int i;
/*int i;*/

memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));

Expand Down
8 changes: 4 additions & 4 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/floor1.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: floor backend 1 implementation
last mod: $Id: floor1.c,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: floor1.c,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -414,7 +414,7 @@ static int accumulate_fit(const float *flr,const float *mdct,
int x0, int x1,lsfit_acc *a,
int n,vorbis_info_floor1 *info){
long i;
int quantized=vorbis_dBquant(flr+x0);
/*int quantized=vorbis_dBquant(flr+x0);*/

long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;

Expand Down Expand Up @@ -593,7 +593,7 @@ static int post_Y(int *A,int *B,int pos){
return (A[pos]+B[pos])>>1;
}

static int seq=0;
/*static int seq=0;*/

int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look,
const float *logmdct, /* in */
Expand Down Expand Up @@ -760,7 +760,7 @@ int floor1_encode(vorbis_block *vb,vorbis_look_floor1 *look,

long i,j;
vorbis_info_floor1 *info=look->vi;
long n=look->n;
/*long n=look->n;*/
long posts=look->posts;
codec_setup_info *ci=vb->vd->vi->codec_setup;
int out[VIF_POSIT+2];
Expand Down
4 changes: 3 additions & 1 deletion osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/lookup_data.h
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: lookup data; generated by lookups.pl; edit there
last mod: $Id: lookup_data.h,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: lookup_data.h,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -55,6 +55,7 @@ static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
-1.0000000000000f,
};

#if !MACOSX
#define INVSQ_LOOKUP_SZ 32
static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
Expand All @@ -67,6 +68,7 @@ static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
1.000000000000f,
};
#endif

#define INVSQ2EXP_LOOKUP_MIN -32
#define INVSQ2EXP_LOOKUP_MAX 32
Expand Down
7 changes: 5 additions & 2 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/lsp.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: LSP (also called LSF) conversion routines
last mod: $Id: lsp.c,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: lsp.c,v 1.2 2004/01/27 18:39:13 icculus Exp $
The LSP generation code is taken (with minimal modification and a
few bugfixes) from "On the Computation of the LSP Frequencies" by
Expand Down Expand Up @@ -64,8 +64,11 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
float amp,float ampoffset){
register int i;
register float wdel=M_PI/ln;

#if !MACOSX
vorbis_fpu_control fpu;

#endif

vorbis_fpu_setround(&fpu);
for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);

Expand Down
6 changes: 3 additions & 3 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/os.h
Expand Up @@ -13,7 +13,7 @@
********************************************************************
function: #ifdef jail to whip a few platforms into the UNIX ideal.
last mod: $Id: os.h,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: os.h,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -130,8 +130,8 @@ static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){

typedef int vorbis_fpu_control;

static int vorbis_ftoi(double f){
return (int)(f+.5);
static inline int vorbis_ftoi(double f){
return (int)(f+0.5);
}

/* We don't have special code for this compiler/arch, so do it the slow way */
Expand Down
8 changes: 4 additions & 4 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/res0.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: residue backend 0, 1 and 2 implementation
last mod: $Id: res0.c,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: res0.c,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -368,8 +368,8 @@ static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
long i,j,k;
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
vorbis_info_residue0 *info=look->info;
vorbis_info *vi=vb->vd->vi;
codec_setup_info *ci=vi->codec_setup;
/*vorbis_info *vi=vb->vd->vi;*/
/*codec_setup_info *ci=vi->codec_setup;*/

/* move all this setup out later */
int samples_per_partition=info->grouping;
Expand Down Expand Up @@ -496,7 +496,7 @@ static int _01forward(vorbis_block *vb,vorbis_look_residue *vl,
vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
vorbis_info_residue0 *info=look->info;

vorbis_dsp_state *vd=vb->vd;
/*vorbis_dsp_state *vd=vb->vd;*/

/* move all this setup out later */
int samples_per_partition=info->grouping;
Expand Down
10 changes: 5 additions & 5 deletions osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/scales.h
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: linear scale -> dB, Bark and Mel scales
last mod: $Id: scales.h,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: scales.h,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand All @@ -25,19 +25,19 @@
#define VORBIS_IEEE_FLOAT32 1
#ifdef VORBIS_IEEE_FLOAT32

static float unitnorm(float x){
static inline float unitnorm(float x){
ogg_uint32_t *ix=(ogg_uint32_t *)&x;
*ix=(*ix&0x80000000UL)|(0x3f800000UL);
return(x);
}

static float FABS(float *x){
static inline float FABS(float *x){
ogg_uint32_t *ix=(ogg_uint32_t *)x;
*ix&=0x7fffffffUL;
return(*x);
}

static float todB(const float *x){
static inline float todB(const float *x){
float calc;
ogg_int32_t *i=(ogg_int32_t *)x;
calc = ((*i) & 0x7fffffff);
Expand All @@ -50,7 +50,7 @@ static float todB(const float *x){

#else

static float unitnorm(float x){
static inline float unitnorm(float x){
if(x<0)return(-1.f);
return(1.f);
}
Expand Down
6 changes: 5 additions & 1 deletion osx/AL_EXT_vorbis/libvorbis-1.0-optimized/lib/vorbisfile.c
Expand Up @@ -11,7 +11,7 @@
********************************************************************
function: stdio-based convenience library for opening/seeking/decoding
last mod: $Id: vorbisfile.c,v 1.1 2003/10/12 23:51:40 root Exp $
last mod: $Id: vorbisfile.c,v 1.2 2004/01/27 18:39:13 icculus Exp $
********************************************************************/

Expand Down Expand Up @@ -1476,7 +1476,11 @@ long ov_read(OggVorbis_File *vf,char *buffer,int length,

long channels=ov_info(vf,-1)->channels;
long bytespersample=word * channels;

#if !MACOSX
vorbis_fpu_control fpu;
#endif

if(samples>length/bytespersample)samples=length/bytespersample;

if(samples <= 0)
Expand Down

0 comments on commit 4b078ab

Please sign in to comment.