Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.20)
project(vorbis)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand All @@ -10,7 +10,6 @@ include(CheckIncludeFiles)
include(CheckLibraryExists)

# Build options
option(BUILD_SHARED_LIBS "Build shared library" OFF)
if(APPLE)
option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
endif()
Expand Down
10 changes: 7 additions & 3 deletions lib/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <ogg/ogg.h>
#include "stack_alloc.h"
#include "vorbis/codec.h"
#include "codec_internal.h"

Expand Down Expand Up @@ -425,8 +426,8 @@ float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
static void _preextrapolate_helper(vorbis_dsp_state *v){
int i;
int order=16;
float *lpc=alloca(order*sizeof(*lpc));
float *work=alloca(v->pcm_current*sizeof(*work));
float *lpc=VORBIS_STACK_ALLOC(order*sizeof(*lpc));
float *work=VORBIS_STACK_ALLOC(v->pcm_current*sizeof(*work));
long j;
v->preextrapolate=1;

Expand Down Expand Up @@ -461,6 +462,8 @@ static void _preextrapolate_helper(vorbis_dsp_state *v){

}
}
VORBIS_STACK_FREE(work);
VORBIS_STACK_FREE(lpc);
}


Expand All @@ -473,7 +476,7 @@ int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
if(vals<=0){
int order=32;
int i;
float *lpc=alloca(order*sizeof(*lpc));
float *lpc=VORBIS_STACK_ALLOC(order*sizeof(*lpc));

/* if it wasn't done earlier (very short sample) */
if(!v->preextrapolate)
Expand Down Expand Up @@ -511,6 +514,7 @@ int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){

}
}
VORBIS_STACK_FREE(lpc);
}else{

if(v->pcm_current+vals>v->pcm_storage)
Expand Down
14 changes: 11 additions & 3 deletions lib/codebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string.h>
#include <math.h>
#include <ogg/ogg.h>
#include "stack_alloc.h"
#include "vorbis/codec.h"
#include "codebook.h"
#include "scales.h"
Expand Down Expand Up @@ -376,18 +377,25 @@ long vorbis_book_decode(codebook *book, oggpack_buffer *b){
long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
if(book->used_entries>0){
int step=n/book->dim;
long *entry = alloca(sizeof(*entry)*step);
float **t = alloca(sizeof(*t)*step);
long *entry = VORBIS_STACK_ALLOC(sizeof(*entry)*step);
float **t = VORBIS_STACK_ALLOC(sizeof(*t)*step);
int i,j,o;

for (i = 0; i < step; i++) {
entry[i]=decode_packed_entry_number(book,b);
if(entry[i]==-1)return(-1);
if(entry[i]==-1) {
VORBIS_STACK_FREE(t);
VORBIS_STACK_FREE(entry);
return(-1);
}
t[i] = book->valuelist+entry[i]*book->dim;
}
for(i=0,o=0;i<book->dim;i++,o+=step)
for (j=0;o+j<n && j<step;j++)
a[o+j]+=t[j][i];

VORBIS_STACK_FREE(t);
VORBIS_STACK_FREE(entry);
}
return(0);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdio.h>
#include <math.h>
#include <ogg/ogg.h>
#include "stack_alloc.h"
#include "vorbis/codec.h"
#include "codec_internal.h"

Expand Down Expand Up @@ -101,7 +102,7 @@ static int _ve_amp(envelope_lookup *ve,
itself (for low power signals) */

float minV=ve->minenergy;
float *vec=alloca(n*sizeof(*vec));
float *vec=VORBIS_STACK_ALLOC(n*sizeof(*vec));

/* stretch is used to gradually lengthen the number of windows
considered prevoius-to-potential-trigger */
Expand Down Expand Up @@ -204,6 +205,8 @@ static int _ve_amp(envelope_lookup *ve,
if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
}

VORBIS_STACK_FREE(vec);

return(ret);
}

Expand Down Expand Up @@ -278,7 +281,7 @@ long _ve_envelope_search(vorbis_dsp_state *v){

#if 0
if(j>ve->curmark){
float *marker=alloca(v->pcm_current*sizeof(*marker));
float *marker=VORBIS_STACK_ALLOC(v->pcm_current*sizeof(*marker));
int l,m;
memset(marker,0,sizeof(*marker)*v->pcm_current);
fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
Expand Down
12 changes: 9 additions & 3 deletions lib/lpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Carsten Bormann
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "stack_alloc.h"
#include "os.h"
#include "smallft.h"
#include "lpc.h"
Expand All @@ -58,8 +59,8 @@ Carsten Bormann
Output: m lpc coefficients, excitation energy */

float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
double *aut=alloca(sizeof(*aut)*(m+1));
double *lpc=alloca(sizeof(*lpc)*(m));
double *aut=VORBIS_STACK_ALLOC(sizeof(*aut)*(m+1));
double *lpc=VORBIS_STACK_ALLOC(sizeof(*lpc)*(m));
double error;
double epsilon;
int i,j;
Expand Down Expand Up @@ -126,6 +127,9 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
/* we need the error value to know how big an impulse to hit the
filter with later */

VORBIS_STACK_FREE(aut);
VORBIS_STACK_FREE(lpc);

return error;
}

Expand All @@ -138,7 +142,7 @@ void vorbis_lpc_predict(float *coeff,float *prime,int m,

long i,j,o,p;
float y;
float *work=alloca(sizeof(*work)*(m+n));
float *work=VORBIS_STACK_ALLOC(sizeof(*work)*(m+n));

if(!prime)
for(i=0;i<m;i++)
Expand All @@ -156,4 +160,6 @@ void vorbis_lpc_predict(float *coeff,float *prime,int m,

data[i]=work[o]=y;
}

VORBIS_STACK_FREE(work);
}
41 changes: 30 additions & 11 deletions lib/lsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "stack_alloc.h"
#include "lsp.h"
#include "os.h"
#include "misc.h"
Expand Down Expand Up @@ -146,7 +147,7 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
int i;
int ampoffseti=rint(ampoffset*4096.f);
int ampi=rint(amp*16.f);
long *ilsp=alloca(m*sizeof(*ilsp));
long *ilsp=VORBIS_STACK_ALLOC(m*sizeof(*ilsp));
for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);

i=0;
Expand Down Expand Up @@ -236,6 +237,7 @@ void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
curve[i]*=amp;
while(map[++i]==k)curve[i]*=amp;
}
VORBIS_STACK_FREE(ilsp);
}

#else
Expand Down Expand Up @@ -309,7 +311,7 @@ static int comp(const void *a,const void *b){
#define EPSILON 10e-7
static int Laguerre_With_Deflation(float *a,int ord,float *r){
int i,m;
double *defl=alloca(sizeof(*defl)*(ord+1));
double *defl=VORBIS_STACK_ALLOC(sizeof(*defl)*(ord+1));
for(i=0;i<=ord;i++)defl[i]=a[i];

for(m=ord;m>0;m--){
Expand All @@ -328,8 +330,10 @@ static int Laguerre_With_Deflation(float *a,int ord,float *r){

/* Laguerre's method */
denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
if(denom<0)
return(-1); /* complex root! The LPC generator handed us a bad filter */
if(denom<0){ /* complex root! The LPC generator handed us a bad filter */
VORBIS_STACK_FREE(defl);
return(-1);
}

if(pp>0){
denom = pp + sqrt(denom);
Expand All @@ -356,6 +360,7 @@ static int Laguerre_With_Deflation(float *a,int ord,float *r){
defl++;

}
VORBIS_STACK_FREE(defl);
return(0);
}

Expand All @@ -364,7 +369,7 @@ static int Laguerre_With_Deflation(float *a,int ord,float *r){
static int Newton_Raphson(float *a,int ord,float *r){
int i, k, count=0;
double error=1.f;
double *root=alloca(ord*sizeof(*root));
double *root=VORBIS_STACK_ALLOC(ord*sizeof(*root));

for(i=0; i<ord;i++) root[i] = r[i];

Expand All @@ -386,7 +391,10 @@ static int Newton_Raphson(float *a,int ord,float *r){
error+= delta*delta;
}

if(count>40)return(-1);
if(count>40){
VORBIS_STACK_FREE(root);
return(-1);
}

count++;
}
Expand All @@ -395,6 +403,7 @@ static int Newton_Raphson(float *a,int ord,float *r){
help, we can eliminate the bubble sort in our lifetime. --Monty */

for(i=0; i<ord;i++) r[i] = root[i];
VORBIS_STACK_FREE(root);
return(0);
}

Expand All @@ -403,10 +412,10 @@ static int Newton_Raphson(float *a,int ord,float *r){
int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
int order2=(m+1)>>1;
int g1_order,g2_order;
float *g1=alloca(sizeof(*g1)*(order2+1));
float *g2=alloca(sizeof(*g2)*(order2+1));
float *g1r=alloca(sizeof(*g1r)*(order2+1));
float *g2r=alloca(sizeof(*g2r)*(order2+1));
float *g1=VORBIS_STACK_ALLOC(sizeof(*g1)*(order2+1));
float *g2=VORBIS_STACK_ALLOC(sizeof(*g2)*(order2+1));
float *g1r=VORBIS_STACK_ALLOC(sizeof(*g1r)*(order2+1));
float *g2r=VORBIS_STACK_ALLOC(sizeof(*g2r)*(order2+1));
int i;

/* even and odd are slightly different base cases */
Expand Down Expand Up @@ -436,8 +445,13 @@ int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){

/* Find the roots of the 2 even polynomials.*/
if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
Laguerre_With_Deflation(g2,g2_order,g2r))
Laguerre_With_Deflation(g2,g2_order,g2r)) {
VORBIS_STACK_FREE(g2r);
VORBIS_STACK_FREE(g1r);
VORBIS_STACK_FREE(g2);
VORBIS_STACK_FREE(g1);
return(-1);
}

Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
Expand All @@ -450,5 +464,10 @@ int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){

for(i=0;i<g2_order;i++)
lsp[i*2+1] = acos(g2r[i]);

VORBIS_STACK_FREE(g2r);
VORBIS_STACK_FREE(g1r);
VORBIS_STACK_FREE(g2);
VORBIS_STACK_FREE(g1);
return(0);
}
32 changes: 23 additions & 9 deletions lib/mapping0.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string.h>
#include <math.h>
#include <ogg/ogg.h>
#include "stack_alloc.h"
#include "vorbis/codec.h"
#include "codec_internal.h"
#include "codebook.h"
Expand Down Expand Up @@ -236,13 +237,13 @@ static int mapping0_forward(vorbis_block *vb){
int n=vb->pcmend;
int i,j,k;

int *nonzero = alloca(sizeof(*nonzero)*vi->channels);
int *nonzero = VORBIS_STACK_ALLOC(sizeof(*nonzero)*vi->channels);
float **gmdct = _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
int **iwork = _vorbis_block_alloc(vb,vi->channels*sizeof(*iwork));
int ***floor_posts = _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));

float global_ampmax=vbi->ampmax;
float *local_ampmax=alloca(sizeof(*local_ampmax)*vi->channels);
float *local_ampmax=VORBIS_STACK_ALLOC(sizeof(*local_ampmax)*vi->channels);
int blocktype=vbi->blocktype;

int modenumber=vb->W;
Expand Down Expand Up @@ -495,7 +496,11 @@ static int mapping0_forward(vorbis_block *vb){
/* this algorithm is hardwired to floor 1 for now; abort out if
we're *not* floor1. This won't happen unless someone has
broken the encode setup lib. Guard it anyway. */
if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
if(ci->floor_type[info->floorsubmap[submap]]!=1) {
VORBIS_STACK_FREE(local_ampmax);
VORBIS_STACK_FREE(nonzero);
return(-1);
}

floor_posts[i][PACKETBLOBS/2]=
floor1_fit(vb,b->flr[info->floorsubmap[submap]],
Expand Down Expand Up @@ -590,8 +595,8 @@ static int mapping0_forward(vorbis_block *vb){
/* iterate over the many masking curve fits we've created */

{
int **couple_bundle=alloca(sizeof(*couple_bundle)*vi->channels);
int *zerobundle=alloca(sizeof(*zerobundle)*vi->channels);
int **couple_bundle=VORBIS_STACK_ALLOC(sizeof(*couple_bundle)*vi->channels);
int *zerobundle=VORBIS_STACK_ALLOC(sizeof(*zerobundle)*vi->channels);

for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
Expand Down Expand Up @@ -686,12 +691,16 @@ static int mapping0_forward(vorbis_block *vb){
/* ok, done encoding. Next protopacket. */
}

VORBIS_STACK_FREE(zerobundle);
VORBIS_STACK_FREE(couple_bundle);
}

#if 0
seq++;
total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
#endif
VORBIS_STACK_FREE(local_ampmax);
VORBIS_STACK_FREE(nonzero);
return(0);
}

Expand All @@ -705,11 +714,11 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
int i,j;
long n=vb->pcmend=ci->blocksizes[vb->W];

float **pcmbundle=alloca(sizeof(*pcmbundle)*vi->channels);
int *zerobundle=alloca(sizeof(*zerobundle)*vi->channels);
float **pcmbundle=VORBIS_STACK_ALLOC(sizeof(*pcmbundle)*vi->channels);
int *zerobundle=VORBIS_STACK_ALLOC(sizeof(*zerobundle)*vi->channels);

int *nonzero =alloca(sizeof(*nonzero)*vi->channels);
void **floormemo=alloca(sizeof(*floormemo)*vi->channels);
int *nonzero =VORBIS_STACK_ALLOC(sizeof(*nonzero)*vi->channels);
void **floormemo=VORBIS_STACK_ALLOC(sizeof(*floormemo)*vi->channels);

/* recover the spectral envelope; store it in the PCM vector for now */
for(i=0;i<vi->channels;i++){
Expand Down Expand Up @@ -794,6 +803,11 @@ static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
mdct_backward(b->transform[vb->W][0],pcm,pcm);
}

VORBIS_STACK_FREE(floormemo);
VORBIS_STACK_FREE(nonzero);
VORBIS_STACK_FREE(zerobundle);
VORBIS_STACK_FREE(pcmbundle);

/* all done! */
return(0);
}
Expand Down
Loading