ref: b2a6823ecd5f13fb9f5a959536536adc1e253daa
parent: ecd50e531fbf378499a3f71cdca05ad969c2e29f
author: qwx <qwx@sciops.net>
date: Mon Mar 6 17:13:56 EST 2023
initial port
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,51 @@
+APE=/sys/src/ape
+<$APE/config
+
+TARG=opusdec opusenc opusinfo
+BIN=/$objtype/bin/audio
+
+CFLAGS=$CFLAGS -c \
+ -Iinclude \
+ -I/sys/src/cmd/audio/libogg \
+ -I/sys/include/ape/opus \
+ -D_POSIX_SOURCE \
+ -D__GNU_LIBRARY__ \
+ -D_C99_SNPRINTF_EXTENSION \
+ -DSPX_RESAMPLE_EXPORT= \
+ -DRANDOM_PREFIX=opustools \
+ -DOUTSIDE_SPEEX \
+ -DRESAMPLE_FULL_SINC_TABLE \
+ -DOPUSTOOLS \
+ -DPACKAGE_NAME="opus-tools" \
+ -DPACKAGE_VERSION="fuckoff"
+
+LIB=\
+ /$objtype/lib/ape/libopusfile.a \
+ /$objtype/lib/ape/libopusenc.a \
+ /$objtype/lib/ape/libopus.a \
+ /sys/src/cmd/audio/libogg/libogg.a$O \
+
+</sys/src/cmd/mkmany
+
+%.$O: src/%.c
+ $CC $CFLAGS $prereq
+
+%.$O: share/%.c
+ $CC $CFLAGS $prereq
+
+%.$O: /sys/src/cmd/audio/libogg/%.c
+ $CC $CFLAGS $prereq
+
+OGG=`{cd /sys/src/cmd/audio/libogg; echo *.c}
+OGG=${OGG:%.c=%.$O}
+
+/sys/src/cmd/audio/libogg/libogg.a$O: $OGG
+ ar vu $target $OGG
+
+COMMON=opus_header.$O resample.$O getopt.$O getopt1.$O
+
+$O.opusdec: opusdec.$O wav_io.$O wave_out.$O diag_range.$O $COMMON
+$O.opusenc: opusenc.$O audio-in.$O diag_range.$O flac.$O picture.$O $COMMON
+$O.opusinfo: opusinfo.$O info_opus.$O picture.$O tagcompare.$O $COMMON
+
+CLEANFILES=`{$CLEANFILES echo /sys/src/cmd/audio/libogg/libogg.a[$OS]}
--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -719,7 +719,11 @@
int sampbyte = f->samplesize / 8;
int realsamples = f->totalsamples > 0 && samples > (f->totalsamples - f->samplesread)
? (int)(f->totalsamples - f->samplesread) : samples;
- signed char *buf = alloca(realsamples*sampbyte*f->channels);
+ signed char *buf = malloc(realsamples*sampbyte*f->channels);
+ if(buf == NULL){
+ fprintf(stderr, "allocation failure\n");
+ return 0;
+ }
int i,j;
int *ch_permute = f->channel_permute;
@@ -807,9 +811,11 @@
else {
fprintf(stderr, _("Internal error: attempt to read unsupported "
"bitdepth %d\n"), f->samplesize);
+ free(buf);
return 0;
}
+ free(buf);
return realsamples;
}
@@ -818,9 +824,14 @@
wavfile *f = (wavfile *)in;
int realsamples = f->totalsamples > 0 && samples > (f->totalsamples - f->samplesread)
? (int)(f->totalsamples - f->samplesread) : samples;
- float *buf = alloca(realsamples*4*f->channels); /* de-interleave buffer */
+ float *buf = malloc(realsamples*4*f->channels); /* de-interleave buffer */
int i,j;
+ if(buf == NULL){
+ fprintf(stderr, "allocation failure\n");
+ return 0;
+ }
+
realsamples = (int)fread(buf, 4*f->channels, realsamples, f->f);
f->samplesread += realsamples;
@@ -837,6 +848,7 @@
get_be_float(buf + i*f->channels + f->channel_permute[j]);
}
+ free(buf);
return realsamples;
}
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -503,8 +503,12 @@
short *out;
float *buf;
float *output;
- out=alloca(sizeof(short)*MAX_FRAME_SIZE*channels);
- buf=alloca(sizeof(float)*MAX_FRAME_SIZE*channels);
+ out=malloc(sizeof(short)*MAX_FRAME_SIZE*channels);
+ buf=malloc(sizeof(float)*MAX_FRAME_SIZE*channels);
+ if(out == NULL || buf == NULL){
+ fprintf(stderr, "allocation failure\n");
+ return 0;
+ }
maxout=((link_read/48000)*rate + (link_read%48000)*rate/48000) - link_out;
maxout=maxout<0?0:maxout;
do {
@@ -570,6 +574,8 @@
maxout-=ret;
}
} while (frame_size>0 && maxout>0);
+ free(buf);
+ free(out);
return sampout;
}
@@ -857,8 +863,8 @@
}
else
{
- st=op_open_url(inFile,NULL,NULL);
- if (st==NULL)
+ //st=op_open_url(inFile,NULL,NULL);
+ //if (st==NULL)
{
st=op_open_file(inFile,NULL);
}
@@ -1066,7 +1072,8 @@
resampler=NULL;
}
/*We've encountered a new link.*/
- link_read=link_out=0;
+ link_read=0;
+ link_out=0;
head=op_head(st, li);
if (!force_stereo && channels!=head->channel_count)
{