ref: 3d374bbcb1681e2334e7dd603aca7a695353a30e
parent: 275b9fd61b90f961806ba3816b0442662658eb7f
author: qwx <[email protected]>
date: Sat Oct 23 21:27:28 EDT 2021
opus: update and fix build (thanks umbraticus)
--- a/libopusenc
+++ b/libopusenc
@@ -1,5 +1,6 @@
---- /dev/null Wed Jan 8 06:24:14 2020
-+++ mkfile Sat Feb 1 20:37:33 2020
+diff 43779464dc7717b9211057df70d3caf5c904592c uncommitted
+--- /tmp/diff100000206984
++++ b/mkfile
@@ -0,0 +1,39 @@
+APE=/sys/src/ape
+<$APE/config
--- a/opus
+++ b/opus
@@ -1,6 +1,7 @@
---- /mnt/git/branch/heads/master/tree/celt/stack_alloc.h Wed Dec 4 11:00:56 2019
-+++ celt/stack_alloc.h Sat Feb 1 15:27:54 2020
-@@ -140,7 +140,7 @@ extern char *global_stack_top;
+diff a8e6a77c5fe0c37aa6788f939f24f8cd22ae2652 uncommitted
+--- a/celt/stack_alloc.h
++++ b/celt/stack_alloc.h
+@@ -140,7 +140,7 @@
#else
@@ -9,8 +10,8 @@
#define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)/sizeof(char)),(stack)+=(size)*(sizeof(type)/sizeof(char)),(type*)((stack)-(size)*(sizeof(type)/sizeof(char))))
#if 0 /* Set this to 1 to instrument pseudostack usage */
#define RESTORE_STACK (printf("%ld %s:%d\n", global_stack-scratch_ptr, __FILE__, __LINE__),global_stack = _saved_stack)
---- /dev/null Wed Jan 8 06:24:14 2020
-+++ mkfile Sat Feb 1 20:40:04 2020
+--- /tmp/fuckyoutoo
++++ mkfile
@@ -0,0 +1,187 @@
+APE=/sys/src/ape
+<$APE/config
@@ -199,9 +200,9 @@
+$HFILES:
+ mkdir -p /sys/include/ape/opus
+ dircp include /sys/include/ape/opus
---- /mnt/git/branch/heads/master/tree/silk/LPC_inv_pred_gain.c Wed Dec 4 11:00:56 2019
-+++ silk/LPC_inv_pred_gain.c Sat Feb 1 19:26:10 2020
-@@ -45,7 +45,7 @@ static opus_int32 LPC_inverse_pred_gain_
+--- a/silk/LPC_inv_pred_gain.c
++++ b/silk/LPC_inv_pred_gain.c
+@@ -45,7 +45,7 @@
)
{
opus_int k, n, mult2Q;
@@ -210,7 +211,7 @@
invGain_Q30 = SILK_FIX_CONST( 1, 30 );
for( k = order - 1; k > 0; k-- ) {
-@@ -80,14 +80,14 @@ static opus_int32 LPC_inverse_pred_gain_
+@@ -80,14 +80,14 @@
opus_int64 tmp64;
tmp1 = A_QA[ n ];
tmp2 = A_QA[ k - n - 1 ];
--- a/opus-tools
+++ b/opus-tools
@@ -1,6 +1,7 @@
---- /dev/null Wed Jan 8 06:24:14 2020
-+++ mkfile Sat Feb 1 21:20:19 2020
-@@ -0,0 +1,39 @@
+diff b982c4c784095dccb77f57169416e02a0cd9c81d uncommitted
+--- /tmp/diff100000244624
++++ b/mkfile
+@@ -0,0 +1,51 @@
+APE=/sys/src/ape
+<$APE/config
+
@@ -26,6 +27,7 @@
+ /$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
+
@@ -35,14 +37,25 @@
+%.$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.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 $COMMON
---- /mnt/git/object/ae5d6d59e82ef40300a4dece7897499685f87184/tree/src/audio-in.c
-+++ src/audio-in.c
-@@ -718,7 +718,11 @@
++$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
+@@ -721,7 +721,11 @@
int sampbyte = f->samplesize / 8;
int realsamples = f->totalsamples > 0 && samples > (f->totalsamples - f->samplesread)
? (int)(f->totalsamples - f->samplesread) : samples;
@@ -55,7 +68,7 @@
int i,j;
int *ch_permute = f->channel_permute;
-@@ -806,9 +810,11 @@
+@@ -809,9 +813,11 @@
else {
fprintf(stderr, _("Internal error: attempt to read unsupported "
"bitdepth %d\n"), f->samplesize);
@@ -67,7 +80,7 @@
return realsamples;
}
-@@ -817,9 +823,14 @@
+@@ -820,9 +826,14 @@
wavfile *f = (wavfile *)in;
int realsamples = f->totalsamples > 0 && samples > (f->totalsamples - f->samplesread)
? (int)(f->totalsamples - f->samplesread) : samples;
@@ -83,7 +96,7 @@
realsamples = (int)fread(buf, 4*f->channels, realsamples, f->f);
f->samplesread += realsamples;
-@@ -836,6 +847,7 @@
+@@ -839,6 +850,7 @@
get_be_float(buf + i*f->channels + f->channel_permute[j]);
}
@@ -91,9 +104,9 @@
return realsamples;
}
---- /mnt/git/object/ae5d6d59e82ef40300a4dece7897499685f87184/tree/src/opusdec.c
-+++ src/opusdec.c
-@@ -494,8 +494,12 @@
+--- a/src/opusdec.c
++++ b/src/opusdec.c
+@@ -503,8 +503,12 @@
short *out;
float *buf;
float *output;
@@ -108,7 +121,7 @@
maxout=((link_read/48000)*rate + (link_read%48000)*rate/48000) - link_out;
maxout=maxout<0?0:maxout;
do {
-@@ -561,6 +565,8 @@
+@@ -570,6 +574,8 @@
maxout-=ret;
}
} while (frame_size>0 && maxout>0);
@@ -117,7 +130,7 @@
return sampout;
}
-@@ -848,8 +854,8 @@
+@@ -857,8 +863,8 @@
}
else
{
@@ -128,7 +141,7 @@
{
st=op_open_file(inFile,NULL);
}
-@@ -1057,7 +1063,8 @@
+@@ -1066,7 +1072,8 @@
resampler=NULL;
}
/*We've encountered a new link.*/
--- a/opus-tools-defaults
+++ b/opus-tools-defaults
@@ -1,6 +1,7 @@
---- /mnt/git/object/9e6bc60eca7b34de0173ae12a5de7d6699bffe86/tree/src/audio-in.c
-+++ src/audio-in.c
-@@ -668,8 +668,8 @@
+diff 1d5e00558c79cf9a4266124d393cfbc879df7475 uncommitted
+--- a/src/audio-in.c
++++ b/src/audio-in.c
+@@ -671,8 +671,8 @@
this length so that we do not misinterpret any additional
chunks after this as audio. Also use this length to report
percent progress. */
@@ -11,9 +12,9 @@
}
else
{
---- /mnt/git/object/9e6bc60eca7b34de0173ae12a5de7d6699bffe86/tree/src/opusdec.c
-+++ src/opusdec.c
-@@ -436,27 +436,13 @@
+--- a/src/opusdec.c
++++ b/src/opusdec.c
+@@ -445,27 +445,13 @@
defined HAVE_SYS_AUDIOIO_H || defined WIN32 || defined _WIN32
printf("Usage: opusdec [options] input [output]\n");
#else
@@ -42,7 +43,7 @@
printf(" -h, --help Show this help\n");
printf(" -V, --version Show version information\n");
printf(" --quiet Suppress program output\n");
-@@ -468,7 +454,6 @@
+@@ -477,7 +463,6 @@
printf(" --force-wav Force Wave header on output\n");
printf(" --packet-loss n Simulate n %% random packet loss\n");
printf(" --save-range file Save check values for every frame to a file\n");
@@ -50,7 +51,7 @@
}
void version(void)
-@@ -683,7 +668,7 @@
+@@ -692,7 +677,7 @@
int file_output;
int old_li=-1;
int li;
@@ -59,7 +60,7 @@
int forcewav = 0;
ogg_int64_t nb_read_total=0;
ogg_int64_t link_read=0;
-@@ -709,10 +694,10 @@
+@@ -718,10 +703,10 @@
float loss_percent=-1;
float manual_gain=0;
int force_rate=0;
@@ -72,7 +73,7 @@
int wav_format=0;
int dither=1;
int fp=0;
-@@ -801,13 +786,7 @@
+@@ -810,13 +795,7 @@
goto done;
}
}
@@ -87,7 +88,7 @@
/*Output to a file or playback?*/
file_output=argc_utf8-optind==2;
-@@ -824,7 +803,7 @@
+@@ -833,7 +812,7 @@
}
wav_format|=forcewav;
} else {
@@ -96,8 +97,8 @@
wav_format=0;
/*If playing to audio out, default the rate to 48000
instead of the original rate. The original rate is
---- /mnt/git/object/9e6bc60eca7b34de0173ae12a5de7d6699bffe86/tree/src/opusenc.c
-+++ src/opusenc.c
+--- a/src/opusenc.c
++++ b/src/opusenc.c
@@ -117,20 +117,12 @@
static void usage(void)
@@ -120,7 +121,7 @@
printf("\nGeneral options:\n");
printf(" -h, --help Show this help\n");
printf(" -V, --version Show version information\n");
-@@ -419,7 +411,7 @@
+@@ -431,7 +423,7 @@
time_t last_spin=0;
int last_spin_len=0;
/*Settings*/
@@ -129,10 +130,10 @@
opus_int32 bitrate=-1;
opus_int32 rate=48000;
opus_int32 frame_size=960;
-@@ -460,12 +452,12 @@
- range_file=NULL;
+@@ -474,12 +466,12 @@
in_format=NULL;
inopt.channels=chan;
+ inopt.channels_format=CHANNELS_FORMAT_DEFAULT;
- inopt.rate=rate;
+ inopt.rate=44100;
/* 0 dB gain is recommended unless you know what you're doing */
@@ -144,7 +145,7 @@
inopt.rawmode_f=0;
inopt.ignorelength=0;
inopt.copy_comments=1;
-@@ -805,12 +797,8 @@
+@@ -827,12 +819,8 @@
fatal("Invalid bit-depth:\n"
"--raw-bits must be 32 for float sample format\n");
}
--- a/opus-tools-seek
+++ b/opus-tools-seek
@@ -1,6 +1,7 @@
---- /mnt/git/branch/heads/test3-appveyor/tree/src/opusdec.c Fri Aug 21 01:36:31 2020
-+++ src/opusdec.c Fri Aug 21 01:32:19 2020
-@@ -469,7 +469,7 @@
+diff 1d5e00558c79cf9a4266124d393cfbc879df7475 uncommitted
+--- a/src/opusdec.c
++++ b/src/opusdec.c
+@@ -493,7 +493,7 @@
opus_int64 audio_write(float *pcm, int channels, int frame_size, FILE *fout,
SpeexResamplerState *resampler, float *clipmem, shapestate *shapemem,
@@ -9,7 +10,7 @@
{
opus_int64 sampout=0;
opus_int64 maxout;
-@@ -497,10 +497,18 @@
+@@ -521,12 +521,20 @@
pcm, &in_len, buf, &out_len);
pcm += channels*(in_len);
frame_size -= in_len;
@@ -19,16 +20,18 @@
out_len=frame_size<maxout?(unsigned)frame_size:(unsigned)maxout;
frame_size=0;
+ ret = *seek<out_len?*seek:out_len;
-+ }
-+
+ }
+
+ if (*seek > 0)
+ {
+ *seek -= ret;
+ goto next;
- }
-
++ }
++
if (!file||!fp)
-@@ -546,6 +554,7 @@
+ {
+ /*Convert to short and save to output file*/
+@@ -570,6 +578,7 @@
#endif
ret=fwrite(fp?(char *)output:(char *)out,
(fp?sizeof(float):sizeof(short))*channels, out_len, fout);
@@ -36,7 +39,7 @@
sampout+=ret;
maxout-=ret;
}
-@@ -632,7 +641,7 @@
+@@ -656,7 +665,7 @@
static void drain_resampler(FILE *fout, int file_output,
SpeexResamplerState *resampler, int channels, int rate,
opus_int64 link_read, opus_int64 link_out, float *clipmem,
@@ -45,7 +48,7 @@
{
float *zeros;
int drain;
-@@ -643,7 +652,7 @@
+@@ -667,7 +676,7 @@
opus_int64 outsamp;
int tmp=MINI(drain, 100);
outsamp=audio_write(zeros, channels, tmp, fout, resampler, clipmem,
@@ -54,15 +57,15 @@
link_out+=outsamp;
(*audio_size)+=(fp?sizeof(float):sizeof(short))*outsamp*channels;
drain-=tmp;
-@@ -690,6 +699,7 @@
+@@ -714,6 +723,7 @@
{0, 0, 0, 0}
};
opus_int64 audio_size=0;
+ opus_int64 seek=-1;
- double last_coded_seconds=0;
+ opus_int64 last_coded_seconds=-1;
float loss_percent=-1;
float manual_gain=0;
-@@ -725,7 +735,7 @@
+@@ -749,7 +759,7 @@
/*Process options*/
while (1)
{
@@ -71,7 +74,7 @@
long_options, &option_index);
if (c==-1)
break;
-@@ -777,6 +787,9 @@
+@@ -801,6 +811,9 @@
case 'h':
usage();
goto done;
@@ -81,7 +84,7 @@
case 'V':
version();
goto done;
-@@ -990,6 +1003,11 @@
+@@ -1020,6 +1033,11 @@
op_set_decode_callback(st, (op_decode_cb_func)decode_cb, &cb_ctx);
}
@@ -93,7 +96,7 @@
/*Main decoding loop*/
while (1)
{
-@@ -1033,7 +1051,7 @@
+@@ -1063,7 +1081,7 @@
{
drain_resampler(fout, file_output, resampler, channels, rate,
link_read, link_out, clipmem, dither?&shapemem:NULL, &audio_size,
@@ -102,7 +105,7 @@
/*Neither speex_resampler_reset_mem() nor
speex_resampler_skip_zeros() clear the number of fractional
samples properly, so we just destroy it. It will get re-created
-@@ -1141,7 +1159,7 @@
+@@ -1171,7 +1189,7 @@
}
outsamp=audio_write(permuted_output?permuted_output:output, channels,
nb_read, fout, resampler, clipmem, dither?&shapemem:0, file_output,
@@ -111,7 +114,7 @@
link_out+=outsamp;
audio_size+=(fp?sizeof(float):sizeof(short))*outsamp*channels;
}
-@@ -1149,7 +1167,7 @@
+@@ -1179,7 +1197,7 @@
if (resampler!=NULL)
{
drain_resampler(fout, file_output, resampler, channels, rate,
--- a/opusfile
+++ b/opusfile
@@ -1,5 +1,6 @@
---- /dev/null Wed Jan 8 06:24:14 2020
-+++ mkfile Sat Feb 1 20:41:39 2020
+diff 705fefe3be63402de65d74d8a3ff499a2e8b8cc5 uncommitted
+--- /tmp/diff100000210759
++++ b/mkfile
@@ -0,0 +1,34 @@
+APE=/sys/src/ape
+<$APE/config
@@ -35,9 +36,9 @@
+$HFILES:
+ mkdir -p /sys/include/ape/opus
+ dircp include /sys/include/ape/opus
---- /mnt/git/branch/heads/master/tree/src/opusfile.c Wed Oct 3 05:33:45 2018
-+++ src/opusfile.c Sat Feb 1 20:59:18 2020
-@@ -327,7 +327,9 @@ static int op_get_prev_page_serial(OggOp
+--- a/src/opusfile.c
++++ b/src/opusfile.c
+@@ -327,7 +327,9 @@
opus_int64 original_end;
opus_int32 chunk_size;
int preferred_found;
@@ -48,7 +49,7 @@
preferred_found=0;
_offset=-1;
chunk_size=OP_CHUNK_SIZE;
-@@ -350,7 +352,8 @@ static int op_get_prev_page_serial(OggOp
+@@ -350,7 +352,8 @@
We're not interested in the page itself... just the serial number, byte
offset, page size, and granule position.*/
_sr->search_start=search_start;
@@ -58,7 +59,7 @@
_sr->serialno=serialno;
OP_ASSERT(_of->offset-_offset>=0);
OP_ASSERT(_of->offset-_offset<=OP_PAGE_SIZE_MAX);
-@@ -416,7 +419,9 @@ static opus_int64 op_get_last_page(OggOp
+@@ -416,7 +419,9 @@
opus_int32 chunk_size;
/*The target serial number must belong to the current link.*/
OP_ASSERT(op_lookup_serialno(_serialno,_serialnos,_nserialnos));
@@ -69,7 +70,7 @@
_offset=-1;
/*We shouldn't have to initialize gp, but gcc is too dumb to figure out that
ret>=0 implies we entered the if(page_gp!=-1) block at least once.*/
-@@ -859,7 +864,8 @@ static int op_find_initial_pcm_offset(Og
+@@ -859,7 +864,8 @@
_link->pcm_file_offset=0;
/*Set pcm_end and end_offset so we can skip the call to
op_find_final_pcm_offset().*/
@@ -79,7 +80,7 @@
_link->end_offset=_link->data_offset;
return 0;
}
-@@ -869,7 +875,8 @@ static int op_find_initial_pcm_offset(Og
+@@ -869,7 +875,8 @@
/*Set pcm_end and end_offset so we can skip the call to
op_find_final_pcm_offset().*/
_link->pcm_file_offset=0;
@@ -89,7 +90,7 @@
_link->end_offset=_link->data_offset;
/*Tell the caller we've got a buffered page for them.*/
return 1;
-@@ -939,7 +946,8 @@ static int op_find_initial_pcm_offset(Og
+@@ -939,7 +946,8 @@
/*If we trimmed the entire packet, stop (the spec says encoders
shouldn't do this, but we support it anyway).*/
if(OP_UNLIKELY(diff>durations[pi]))break;
@@ -99,7 +100,7 @@
/*Move the EOS flag to this packet, if necessary, so we'll trim the
samples.*/
_of->op[pi].e_o_s=1;
-@@ -955,7 +963,8 @@ static int op_find_initial_pcm_offset(Og
+@@ -955,7 +963,8 @@
_of->op_count=pi;
_of->cur_discard_count=_link->head.pre_skip;
_link->pcm_file_offset=0;
@@ -109,7 +110,7 @@
_of->prev_page_offset=page_offset;
return 0;
}
-@@ -1396,7 +1405,8 @@ static int op_open_seekable2_impl(OggOpu
+@@ -1396,7 +1405,8 @@
int ret;
/*We can seek, so set out learning all about this file.*/
(*_of->callbacks.seek)(_of->stream,0,SEEK_END);
@@ -119,7 +120,7 @@
if(OP_UNLIKELY(_of->end<0))return OP_EREAD;
data_offset=_of->links[0].data_offset;
if(OP_UNLIKELY(_of->end<data_offset))return OP_EBADLINK;
-@@ -2280,10 +2290,13 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2285,10 +2295,13 @@
_of->bytes_tracked=0;
_of->samples_tracked=0;
link=_of->links+_li;
@@ -135,7 +136,7 @@
page_offset=-1;
buffering=0;
/*We discard the first 80 ms of data after a seek, so seek back that much
-@@ -2296,9 +2309,12 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2301,9 +2314,12 @@
/*Special case seeking to the start of the link.*/
pre_skip=link->head.pre_skip;
OP_ALWAYS_TRUE(!op_granpos_add(&pcm_pre_skip,pcm_start,pre_skip));
@@ -151,9 +152,9 @@
#if !defined(OP_SMALL_FOOTPRINT)
/*If we were decoding from this link, we can narrow the range a bit.*/
if(_li==_of->cur_link&&_of->ready_state>=OP_INITSET){
-@@ -2329,8 +2345,10 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2338,8 +2354,10 @@
+ first seek location gives better results, on average.*/
if(diff<0){
- OP_ASSERT(offset>=begin);
if(offset-begin>=end-begin>>1||diff>-OP_CUR_TIME_THRESH){
- best=begin=offset;
- best_gp=pcm_start=gp;
@@ -164,7 +165,7 @@
/*If we have buffered data from a continued packet, remember the
offset of the previous page's start, so that if we do wind up
having to seek back here later, we can prime the stream with
-@@ -2369,7 +2387,8 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2389,7 +2407,8 @@
Check if we can cut off at least half the range, though.*/
if(offset-begin<=end-begin>>1||diff<OP_CUR_TIME_THRESH){
/*We really want the page start here, but this will do.*/
@@ -174,7 +175,7 @@
pcm_end=gp;
}
}
-@@ -2386,7 +2405,9 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2406,7 +2425,9 @@
_of->cur_link=_li;
_of->ready_state=OP_STREAMSET;
/*Initialize the interval size history.*/
@@ -185,7 +186,7 @@
force_bisect=0;
while(begin<end){
opus_int64 bisect;
-@@ -2490,7 +2511,8 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2510,7 +2531,8 @@
}
/*Save the byte offset of the end of the page with this granule
position.*/
@@ -195,7 +196,7 @@
/*Buffer any data from a continued packet, if necessary.
This avoids the need to seek back here if the next timestamp we
encounter while scanning forward lies after our target.*/
-@@ -2506,7 +2528,8 @@ static int op_pcm_seek_page(OggOpusFile
+@@ -2526,7 +2548,8 @@
/*Then force buffering on, so that if a packet starts (but does not
end) on the next page, we still avoid the extra seek back.*/
buffering=1;