Skip to content
Snippets Groups Projects
Commit a5ff49ec authored by Gregory Maxwell's avatar Gregory Maxwell
Browse files

Renames test_opus to opus_demo and adds the test_opus_api, test_opus_encode,...

Renames test_opus to opus_demo and adds the test_opus_api, test_opus_encode, test_opus_decode test programs.
parent d481798a
No related branches found
No related tags found
No related merge requests found
......@@ -26,11 +26,13 @@ pkginclude_HEADERS = src/opus.h src/opus_multistream.h celt/opus_types.h celt/op
noinst_HEADERS = $(OPUS_HEAD) $(SILK_HEAD) $(CELT_HEAD)
noinst_PROGRAMS = test_opus test_repacketizer opus_compare
noinst_PROGRAMS = opus_demo test_repacketizer opus_compare test_opus_api test_opus_encode test_opus_decode
test_opus_SOURCES = src/test_opus.c
TESTS = test_opus_api test_opus_decode test_opus_encode
test_opus_LDADD = libopus.la -lm
opus_demo_SOURCES = src/opus_demo.c
opus_demo_LDADD = libopus.la -lm
test_repacketizer_SOURCES = src/test_repacketizer.c
......@@ -39,11 +41,20 @@ test_repacketizer_LDADD = libopus.la -lm
opus_compare_SOURCES = src/opus_compare.c
opus_compare_LDADD = -lm
test_opus_api_SOURCES = tests/test_opus_api.c
test_opus_api_LDADD = libopus.la -lm
test_opus_encode_SOURCES = tests/test_opus_encode.c
test_opus_encode_LDADD = libopus.la -lm
test_opus_decode_SOURCES = tests/test_opus_decode.c
test_opus_decode_LDADD = libopus.la -lm
if CUSTOM_MODES
pkginclude_HEADERS += celt/opus_custom.h
noinst_PROGRAMS += test_opus_custom
test_opus_custom_SOURCES = celt/test_opus_custom.c
test_opus_custom_LDADD = libopus.la -lm
noinst_PROGRAMS += opus_custom_demo
opus_custom_demo_SOURCES = celt/opus_custom_demo.c
opus_custom_demo_LDADD = libopus.la -lm
endif
EXTRA_DIST = opus.pc.in opus-uninstalled.pc.in
......
......@@ -101,8 +101,8 @@ SRCS_C = $(SILK_SOURCES) $(CELT_SOURCES) $(OPUS_SOURCES)
OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(SRCS_C))
TESTOPUS_SRCS_C = src/test_opus.c
TESTOPUS_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(TESTOPUS_SRCS_C))
OPUSDEMO_SRCS_C = src/opus_demo.c
OPUSDEMO_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSDEMO_SRCS_C))
OPUSCOMPARE_SRCS_C = src/opus_compare.c
OPUSCOMPARE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSCOMPARE_SRCS_C))
......@@ -110,18 +110,18 @@ OPUSCOMPARE_OBJS := $(patsubst %.c,%$(OBJSUFFIX),$(OPUSCOMPARE_SRCS_C))
# Rules
default: all
all: $(TARGET) lib test_opus opus_compare
all: $(TARGET) lib opus_demo opus_compare
lib: $(TARGET)
$(TARGET): $(OBJS)
$(ARCHIVE.cmdline)
test_opus$(EXESUFFIX): $(TESTOPUS_OBJS) $(TARGET)
opus_demo$(EXESUFFIX): $(OPUSDEMO_OBJS) $(TARGET)
$(LINK.o.cmdline)
opus_compare$(EXESUFFIX): $(OPUSCOMPARE_OBJS)
$(LINK.o.cmdline)
clean:
rm -f test_opus$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) $(OBJS) $(TESTOPUS_OBJS)
rm -f opus_demo$(EXESUFFIX) opus_compare$(EXESUFFIX) $(TARGET) $(OBJS) $(OPUSDEMO_OBJS)
......@@ -19,12 +19,12 @@ To build from the git repository, the following steps are necessary:
% make
Once you have compiled the codec, there will be a test_opus executable in
Once you have compiled the codec, there will be a opus_demo executable in
the top directory.
Usage: test_opus [-e] <application> <sampling rate (Hz)> <channels (1/2)>
Usage: opus_demo [-e] <application> <sampling rate (Hz)> <channels (1/2)>
<bits per second> [options] <input> <output>
test_opus -d <sampling rate (Hz)> <channels (1/2)> [options]
opus_demo -d <sampling rate (Hz)> <channels (1/2)> [options]
<input> <output>
mode: voip | audio | restricted-lowdelay
......@@ -32,8 +32,7 @@ options:
-e : only runs the encoder (output the bit-stream)
-d : only runs the decoder (reads the bit-stream as input)
-cbr : enable constant bitrate; default: variable bitrate
-cvbr : enable constrained variable bitrate; default:
-unconstrained
-cvbr : enable constrained variable bitrate; default: unconstrained
-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband);
default: sampling rate
-framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20
......@@ -45,4 +44,4 @@ options:
-loss <perc> : simulate packet loss, in percent (0-100); default: 0
input and output are 16-bit PCM files (machine endian) or opus bitstreams
with simple test_opus propritary framing.
with simple opus_demo propritary framing.
......@@ -20,19 +20,20 @@ steps:
% ./configure
% make
Once you have compiled the codec, there will be a test_opus executable in
the src/ directory.
Once you have compiled the codec, there will be a opus_demo executable in
the top directory.
Usage: ./test_opus [-e | -d] <application (0/1)> <sampling rate (Hz)> <channels
(1/2)> <bits per second> [options] <input> <output>
Usage: opus_demo [-e] <application> <sampling rate (Hz)> <channels (1/2)>
<bits per second> [options] <input> <output>
opus_demo -d <sampling rate (Hz)> <channels (1/2)> [options]
<input> <output>
mode: 0 for VoIP, 1 for audio:
mode: voip | audio | restricted-lowdelay
options:
-e : only runs the encoder (output the bit-stream)
-d : only runs the decoder (reads the bit-stream as input)
-cbr : enable constant bitrate; default: variable bitrate
-cvbr : enable constrained variable bitrate;
default: unconstrained
-cvbr : enable constrained variable bitrate; default: unconstrained
-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband);
default: sampling rate
-framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20
......@@ -43,4 +44,5 @@ options:
-dtx : enable SILK DTX
-loss <perc> : simulate packet loss, in percent (0-100); default: 0
input and output are 16-bit PCM files (machine endian)
input and output are 16-bit PCM files (machine endian) or opus bitstreams
with simple opus_demo propritary framing.
File moved
......@@ -22,9 +22,9 @@ for f in `cat "${toplevel}"/opus_sources.mk "${toplevel}"/celt_sources.mk \
| grep '\.[ch]' | sed -e 's/^.*=//' -e 's/\\\\//'` ; do
cp -a "${toplevel}/${f}" "${destdir}/${f}"
done
cp -a "${toplevel}"/src/test_opus.c "${destdir}"/src/
cp -a "${toplevel}"/src/opus_demo.c "${destdir}"/src/
cp -a "${toplevel}"/src/opus_compare.c "${destdir}"/src/
cp -a "${toplevel}"/celt/test_opus_custom.c "${destdir}"/celt/
cp -a "${toplevel}"/celt/opus_custom_demo.c "${destdir}"/celt/
cp -a "${toplevel}"/celt/opus_custom.h "${destdir}"/celt/
cp -a "${toplevel}"/Makefile.draft "${destdir}"/Makefile
cp -a "${toplevel}"/opus_sources.mk "${destdir}"/
......
File moved
This diff is collapsed.
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Gregory Maxwell */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
static inline void deb2_impl(unsigned char *_t,unsigned char **_p,int _k,int _x,int _y)
{
int i;
if(_x>2){
if(_y<3)for(i=0;i<_y;i++)*(--*_p)=_t[i+1];
}else{
_t[_x]=_t[_x-_y];
deb2_impl(_t,_p,_k,_x+1,_y);
for(i=_t[_x-_y]+1;i<_k;i++){
_t[_x]=i;
deb2_impl(_t,_p,_k,_x+1,_x);
}
}
}
/*Generates a De Bruijn sequence (k,2) with length k^2*/
static inline void debruijn2(int _k, unsigned char *_res)
{
unsigned char *p;
unsigned char *t;
t=malloc(sizeof(unsigned char)*_k*2);
memset(t,0,sizeof(unsigned char)*_k*2);
p=&_res[_k*_k];
deb2_impl(t,&p,_k,1,1);
free(t);
}
/*MWC RNG of George Marsaglia*/
static opus_uint32 Rz, Rw;
static inline opus_uint32 fast_rand(void)
{
Rz=36969*(Rz&65535)+(Rz>>16);
Rw=18000*(Rw&65535)+(Rw>>16);
return (Rz<<16)+Rw;
}
static opus_uint32 iseed;
#ifdef __GNUC__
__attribute__((noreturn))
#endif
static inline void _test_failed(const char *file, int line)
{
fprintf(stderr,"\n ***************************************************\n");
fprintf(stderr," *** A fatal error was detected. ***\n");
fprintf(stderr," ***************************************************\n");
fprintf(stderr,"Please report this failure and include\n");
fprintf(stderr,"'make check SEED=%u fails %s at line %d for %s'\n",iseed,file,line,opus_get_version_string());
fprintf(stderr,"and any relevant details about your system.\n\n");
abort();
}
#define test_failed() _test_failed(__FILE__, __LINE__);
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Gregory Maxwell */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "../src/opus.h"
#include "test_opus_common.h"
#define MAX_PACKET (1500)
#define MAX_FRAME_SAMP (288000)
extern int jackpot;
int test_decoder_code0(void)
{
static const opus_int32 fsv[5]={48000,24000,16000,12000,8000};
int err,skip,plen;
int out_samples,fec;
int t;
opus_int32 i;
OpusDecoder *dec[5*2];
opus_uint32 dec_final_range1,dec_final_range2,dec_final_acc;
unsigned char *packet;
unsigned char modes[4096];
short *outbuf_int;
short *outbuf;
dec_final_range1=dec_final_range2=2;
packet=malloc(sizeof(unsigned char)*MAX_PACKET);
if(packet==NULL)test_failed();
outbuf_int=malloc(sizeof(short)*(MAX_FRAME_SAMP+16)*2);
for(i=0;i<(MAX_FRAME_SAMP+16)*2;i++)outbuf_int[i]=32749;
outbuf=&outbuf_int[8*2];
fprintf(stdout," Starting %d decoders...\n",5*2);
for(t=0;t<5*2;t++)
{
int fs=fsv[t>>1];
int c=(t&1)+1;
err=OPUS_INTERNAL_ERROR;
dec[t] = opus_decoder_create(fs, c, &err);
if(err!=OPUS_OK || dec[t]==NULL)test_failed();
fprintf(stdout," opus_decoder_create(%5d,%d) OK. Copy ",fs,c);
{
OpusDecoder *dec2;
/*The opus state structures contain no pointers and can be freely copied*/
dec2=(OpusDecoder *)malloc(opus_decoder_get_size(c));
if(dec2==NULL)test_failed();
memcpy(dec2,dec[t],opus_decoder_get_size(c));
memset(dec[t],255,opus_decoder_get_size(c));
opus_decoder_destroy(dec[t]);
printf("OK.\n");
dec[t]=dec2;
}
}
for(t=0;t<5*2;t++)
{
int factor=48000/fsv[t>>1];
for(fec=0;fec<2;fec++)
{
/*Test PLC on a fresh decoder*/
out_samples = opus_decode(dec[t], 0, 0, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
/*Test null pointer input*/
out_samples = opus_decode(dec[t], 0, -1, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
out_samples = opus_decode(dec[t], 0, 1, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
out_samples = opus_decode(dec[t], 0, 10, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
out_samples = opus_decode(dec[t], 0, fast_rand(), outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
/*Zero lengths*/
out_samples = opus_decode(dec[t], packet, 0, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples!=120/factor)test_failed();
/*Zero buffer*/
outbuf[0]=32749;
out_samples = opus_decode(dec[t], packet, 0, outbuf, 0, fec);
if(out_samples>0)test_failed();
out_samples = opus_decode(dec[t], packet, 0, 0, 0, fec);
if(out_samples>0)test_failed();
if(outbuf[0]!=32749)test_failed();
/*Invalid lengths*/
out_samples = opus_decode(dec[t], packet, -1, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples>=0)test_failed();
out_samples = opus_decode(dec[t], packet, INT_MIN, outbuf, MAX_FRAME_SAMP, fec);
if(out_samples>=0)test_failed();
out_samples = opus_decode(dec[t], packet, -1, outbuf, -1, fec);
if(out_samples>=0)test_failed();
/*Crazy FEC values*/
out_samples = opus_decode(dec[t], packet, 1, outbuf, MAX_FRAME_SAMP, fec?-1:2);
if(out_samples>=0)test_failed();
/*Reset the decoder*/
if(opus_decoder_ctl(dec[t], OPUS_RESET_STATE)!=OPUS_OK)test_failed();
}
}
fprintf(stdout," dec[all] initial frame PLC OK.\n");
/*Count code 0 tests*/
for(i=0;i<64;i++)
{
int j,expected[5*2];
packet[0]=i<<2;
packet[1]=255;
packet[2]=255;
err=opus_packet_get_nb_channels(packet);
if(err!=(i&1)+1)test_failed();
for(t=0;t<5*2;t++){
expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1);
if(expected[t]>2880)test_failed();
}
for(j=0;j<256;j++)
{
packet[1]=j;
for(t=0;t<5*2;t++)
{
out_samples = opus_decode(dec[t], packet, 3, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=expected[t])test_failed();
opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
if(t==0)dec_final_range2=dec_final_range1;
else if(dec_final_range1!=dec_final_range2)test_failed();
}
}
for(t=0;t<5*2;t++){
int factor=48000/fsv[t>>1];
/* The PLC is run for 6 frames in order to get better PLC coverage. */
for(j=0;j<6;j++)
{
out_samples = opus_decode(dec[t], 0, 0, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=expected[t])test_failed();
}
/* Run the PLC once at 2.5ms, as a simulation of someone trying to
do small drift corrections. */
if(expected[t]!=120/factor)
{
out_samples = opus_decode(dec[t], 0, 0, outbuf, 120/factor, 0);
if(out_samples!=120/factor)test_failed();
}
out_samples = opus_decode(dec[t], packet, 2, outbuf, expected[t]-1, 0);
if(out_samples>0)test_failed();
}
}
fprintf(stdout," dec[all] all 2-byte prefix for length 3 and PLC, all modes (64) OK.\n");
{
/*We only test a subset of the modes here simply because the longer
durations end up taking a long time.*/
static const int cmodes[4]={16,20,24,28};
static const opus_uint32 cres[4]={116290185,2172123586,2172123586,2172123586};
static const opus_uint32 lres[3]={3285687739,1481572662,694350475};
static const int lmodes[3]={0,4,8};
int mode=fast_rand()%4;
packet[0]=cmodes[mode]<<3;
dec_final_acc=0;
t=fast_rand()%10;
for(i=0;i<65536;i++)
{
int factor=48000/fsv[t>>1];
packet[1]=i>>8;
packet[2]=i&255;
packet[3]=255;
out_samples = opus_decode(dec[t], packet, 4, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=120/factor)test_failed();
opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
dec_final_acc+=dec_final_range1;
}
if(dec_final_acc!=cres[mode])test_failed();
fprintf(stdout," dec[%3d] all 3-byte prefix for length 4, mode %2d OK.\n",t,cmodes[mode]);
mode=fast_rand()%3;
packet[0]=lmodes[mode]<<3;
dec_final_acc=0;
t=fast_rand()%10;
for(i=0;i<65536;i++)
{
int factor=48000/fsv[t>>1];
packet[1]=i>>8;
packet[2]=i&255;
packet[3]=255;
out_samples = opus_decode(dec[t], packet, 4, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=480/factor)test_failed();
opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
dec_final_acc+=dec_final_range1;
}
if(dec_final_acc!=lres[mode])test_failed();
fprintf(stdout," dec[%3d] all 3-byte prefix for length 4, mode %2d OK.\n",t,lmodes[mode]);
}
skip=fast_rand()%7;
for(i=0;i<64;i++)
{
int j,expected[5*2];
packet[0]=i<<2;
for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,1);
for(j=2+skip;j<1275;j+=4)
{
int jj;
for(jj=0;jj<j;jj++)packet[jj+1]=fast_rand()&255;
for(t=0;t<5*2;t++)
{
out_samples = opus_decode(dec[t], packet, j+1, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=expected[t])test_failed();
opus_decoder_ctl(dec[t], OPUS_GET_FINAL_RANGE(&dec_final_range1));
if(t==0)dec_final_range2=dec_final_range1;
else if(dec_final_range1!=dec_final_range2)test_failed();
}
}
}
fprintf(stdout," dec[all] random packets, all modes (64), every 8th size from from %d bytes to maximum OK.\n",2+skip);
debruijn2(64,modes);
plen=(fast_rand()%18+3)*8+skip+3;
for(i=0;i<4096;i++)
{
int j,expected[5*2];
packet[0]=modes[i]<<2;
for(t=0;t<5*2;t++)expected[t]=opus_decoder_get_nb_samples(dec[t],packet,plen);
for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255;
for(t=0;t<5*2;t++)
{
out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=expected[t])test_failed();
if(t==0)dec_final_range2=dec_final_range1;
else if(dec_final_range1!=dec_final_range2)test_failed();
}
}
fprintf(stdout," dec[all] random packets, all mode pairs (4096), %d bytes/frame OK.\n",plen+1);
plen=(fast_rand()%18+3)*8+skip+3;
t=rand()&3;
for(i=0;i<4096;i++)
{
int count,j,expected;
packet[0]=modes[i]<<2;
expected=opus_decoder_get_nb_samples(dec[t],packet,plen);
for(count=0;count<10;count++)
{
for(j=0;j<plen;j++)packet[j+1]=(fast_rand()|fast_rand())&255;
out_samples = opus_decode(dec[t], packet, plen+1, outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=expected)test_failed();
}
}
fprintf(stdout," dec[%3d] random packets, all mode pairs (4096)*10, %d bytes/frame OK.\n",t,plen+1);
{
int tmodes[1]={25<<2};
opus_uint32 tseeds[1]={140441};
int tlen[1]={157};
opus_int32 tret[1]={480};
t=fast_rand()&1;
for(i=0;i<1;i++)
{
int j;
packet[0]=tmodes[i];
Rw=Rz=tseeds[i];
for(j=1;j<tlen[i];j++)packet[j]=fast_rand()&255;
out_samples=opus_decode(dec[t], packet, tlen[i], outbuf, MAX_FRAME_SAMP, 0);
if(out_samples!=tret[i])test_failed();
}
fprintf(stdout," dec[%3d] pre-selected random packets OK.\n",t);
}
for(t=0;t<5*2;t++)opus_decoder_destroy(dec[t]);
printf(" Decoders stopped.\n");
err=0;
for(i=0;i<8*2;i++)err|=outbuf_int[i]!=32749;
for(i=MAX_FRAME_SAMP*2;i<(MAX_FRAME_SAMP+8)*2;i++)err|=outbuf[i]!=32749;
if(err)test_failed();
free(outbuf_int);
free(packet);
return 0;
}
int main(int _argc, char **_argv)
{
const char * oversion;
if(_argc>2)
{
fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
return 1;
}
if(_argc>1)iseed=atoi(_argv[1]);
else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16);
Rw=Rz=iseed;
oversion=opus_get_version_string();
if(!oversion)test_failed();
fprintf(stderr,"Testing %s decoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535);
test_decoder_code0();
return 0;
}
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Gregory Maxwell */
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "../src/opus.h"
#include "../src/opus_private.h"
#include "test_opus_common.h"
#define MAX_PACKET (1500)
#define SAMPLES (48000*30)
#define SSAMPLES (SAMPLES/3)
#define MAX_FRAME_SAMP (288000)
#define PI (3.141592653589793238462643f)
void generate_music(short *buf, opus_int32 len)
{
opus_int32 a1,b1,a2,b2;
opus_int32 c1,c2,d1,d2;
opus_int32 i,j;
a1=b1=a2=b2=0;
c1=c2=d1=d2=0;
j=0;
/*60ms silence*/
for(i=0;i<2880;i++)buf[i*2]=buf[i*2+1]=0;
for(i=2880;i<len;i++)
{
opus_uint32 r;
opus_int32 v1,v2;
v1=v2=(((j*((j>>12)^((j>>10|j>>12)&26&j>>7)))&128)+128)<<15;
r=fast_rand();v1+=r&65535;v1-=r>>16;
r=fast_rand();v2+=r&65535;v2-=r>>16;
b1=v1-a1+((b1*61+32)>>6);a1=v1;
b2=v2-a2+((b2*61+32)>>6);a2=v2;
c1=(30*(c1+b1+d1)+32)>>6;d1=b1;
c2=(30*(c2+b2+d2)+32)>>6;d2=b2;
v1=(c1+128)>>8;
v2=(c2+128)>>8;
buf[i*2]=v1>32767?32767:(v1<-32768?-32768:v1);
buf[i*2+1]=v2>32767?32767:(v2<-32768?-32768:v2);
if(i%6==0)j++;
}
}
#if 0
static int save_ctr = 0;
static void int_to_char(opus_uint32 i, unsigned char ch[4])
{
ch[0] = i>>24;
ch[1] = (i>>16)&0xFF;
ch[2] = (i>>8)&0xFF;
ch[3] = i&0xFF;
}
static inline void save_packet(unsigned char* p, int len, opus_uint32 rng)
{
FILE *fout;
unsigned char int_field[4];
char name[256];
snprintf(name,255,"test_opus_encode.%llu.%d.bit",(unsigned long long)iseed,save_ctr);
fprintf(stdout,"writing %d byte packet to %s\n",len,name);
fout=fopen(name, "wb+");
if(fout==NULL)test_failed();
int_to_char(len, int_field);
fwrite(int_field, 1, 4, fout);
int_to_char(rng, int_field);
fwrite(int_field, 1, 4, fout);
fwrite(p, 1, len, fout);
fclose(fout);
save_ctr++;
}
#endif
int run_test1(void)
{
static const int fsizes[6]={960*3,960*2,120,240,480,960};
static const char *mstrings[3] = {" LP","Hybrid"," MDCT"};
unsigned char db62[36];
opus_int32 i;
int rc,j,err;
OpusEncoder *enc;
OpusEncoder *enc2;
OpusDecoder *dec;
OpusDecoder *dec_err[10];
short *inbuf;
short *outbuf;
short *out2buf;
opus_int32 bitrate_bps;
unsigned char packet[MAX_PACKET];
opus_uint32 enc_final_range;
opus_uint32 dec_final_range;
int fswitch;
int fsize;
int count;
/*FIXME: encoder api tests, fs!=48k, mono, VBR*/
fprintf(stdout," Encode+Decode tests.\n");
enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &err);
if(err != OPUS_OK || enc==NULL)test_failed();
enc2 = opus_encoder_create(8000, 2, OPUS_APPLICATION_VOIP, &err);
if(err != OPUS_OK || enc==NULL)test_failed();
dec = opus_decoder_create(48000, 2, &err);
if(err != OPUS_OK || dec==NULL)test_failed();
dec_err[0]=(OpusDecoder *)malloc(opus_decoder_get_size(2));
memcpy(dec_err[0],dec,opus_decoder_get_size(2));
dec_err[1] = opus_decoder_create(48000, 1, &err);
dec_err[2] = opus_decoder_create(24000, 2, &err);
dec_err[3] = opus_decoder_create(24000, 1, &err);
dec_err[4] = opus_decoder_create(16000, 2, &err);
dec_err[5] = opus_decoder_create(16000, 1, &err);
dec_err[6] = opus_decoder_create(12000, 2, &err);
dec_err[7] = opus_decoder_create(12000, 1, &err);
dec_err[8] = opus_decoder_create(8000, 2, &err);
dec_err[9] = opus_decoder_create(8000, 1, &err);
for(i=0;i<10;i++)if(dec_err[i]==NULL)test_failed();
{
OpusEncoder *enccpy;
/*The opus state structures contain no pointers and can be freely copied*/
enccpy=(OpusEncoder *)malloc(opus_encoder_get_size(2));
memcpy(enccpy,enc,opus_encoder_get_size(2));
memset(enc,255,opus_encoder_get_size(2));
opus_encoder_destroy(enc);
enc=enccpy;
}
inbuf=(short *)malloc(sizeof(short)*SAMPLES*2);
outbuf=(short *)malloc(sizeof(short)*SAMPLES*2);
out2buf=(short *)malloc(sizeof(short)*MAX_FRAME_SAMP*2);
if(inbuf==NULL || outbuf==NULL || out2buf==NULL)test_failed();
generate_music(inbuf,SAMPLES);
/* FILE *foo;
foo = fopen("foo.sw", "wb+");
fwrite(inbuf, 1, SAMPLES*2*2, foo);
fclose(foo);*/
if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(-2))!=OPUS_BAD_ARG)test_failed();
for(rc=0;rc<3;rc++)
{
if(opus_encoder_ctl(enc, OPUS_SET_VBR(rc<2))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed();
for(j=0;j<12;j++)
{
int rate;
int modes[12]={0,0,0,1,1,1,1,2,2,2,2,2};
int rates[12]={6000,12000,48000,16000,32000,48000,64000,24000,32000,48000,64000,128000};
int frame[12]={960*2,960,480,960,960,960,480,960*3,960,480,240,120};
if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_SILK_ONLY+modes[j]))!=OPUS_OK)test_failed();
rate=rates[j]+fast_rand()%rates[j];
if(opus_encoder_ctl(enc, OPUS_SET_DTX(fast_rand()&1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS((rates[j]>=64000?2:1)))!=OPUS_OK)test_failed();
count=i=0;
do {
int bw,len,out_samples,frame_size;
frame_size=frame[j];
if(opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed();
bw=modes[j]==0?OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%3):
modes[j]==1?OPUS_BANDWIDTH_SUPERWIDEBAND+(fast_rand()&1):
OPUS_BANDWIDTH_NARROWBAND+(fast_rand()%5);
if(modes[j]==2&&bw==OPUS_BANDWIDTH_MEDIUMBAND)bw+=3;
if(opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bw))!=OPUS_OK)test_failed();
len = opus_encode(enc, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
if(len<0 || len>MAX_PACKET)test_failed();
if(opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME_SAMP, 0);
if(out_samples!=frame_size)test_failed();
if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();
if(enc_final_range!=dec_final_range)test_failed();
i+=frame_size;
count++;
}while(i<(SSAMPLES-MAX_FRAME_SAMP));
fprintf(stdout," Mode %s FB encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
}
}
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(OPUS_AUTO))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(OPUS_AUTO))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(0))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc, OPUS_SET_DTX(0))!=OPUS_OK)test_failed();
for(rc=0;rc<3;rc++)
{
if(opus_encoder_ctl(enc2, OPUS_SET_VBR(rc<2))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_VBR_CONSTRAINT(rc==1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_INBAND_FEC(rc==0))!=OPUS_OK)test_failed();
for(j=0;j<16;j++)
{
int rate;
int modes[16]={0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2};
int rates[16]={4000,12000,32000,8000,16000,32000,48000,88000,4000,12000,32000,8000,16000,32000,48000,88000};
int frame[16]={160*3,160,80,160,160,80,40,20,160*3,160,80,160,160,80,40,20};
if(opus_encoder_ctl(enc2, OPUS_SET_INBAND_FEC(rc==0&&j==1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_FORCE_MODE(MODE_SILK_ONLY+modes[j]))!=OPUS_OK)test_failed();
rate=rates[j]+fast_rand()%rates[j];
if(opus_encoder_ctl(enc2, OPUS_SET_DTX(fast_rand()&1))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_BITRATE(rate))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_FORCE_CHANNELS((rates[j]>=48000?2:1)))!=OPUS_OK)test_failed();
count=i=0;
do {
int len,out_samples,frame_size;
frame_size=frame[j];
if(opus_encoder_ctl(enc2, OPUS_SET_COMPLEXITY((count>>2)%11))!=OPUS_OK)test_failed();
if(opus_encoder_ctl(enc2, OPUS_SET_PACKET_LOSS_PERC((fast_rand()&15)&(fast_rand()%15)))!=OPUS_OK)test_failed();
len = opus_encode(enc2, &inbuf[i<<1], frame_size, packet, MAX_PACKET);
if(len<0 || len>MAX_PACKET)test_failed();
if(opus_encoder_ctl(enc2, OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
out_samples = opus_decode(dec, packet, len, &outbuf[i<<1], MAX_FRAME_SAMP, 0);
if(out_samples!=frame_size*6)test_failed();
if(opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range))!=OPUS_OK)test_failed();
if(enc_final_range!=dec_final_range)test_failed();
i+=frame_size;
count++;
}while(i<(SSAMPLES/6-MAX_FRAME_SAMP));
fprintf(stdout," Mode %s NB encode %s, %6d bps OK.\n",mstrings[modes[j]],rc==0?" VBR":rc==1?"CVBR":" CBR",rate);
}
}
bitrate_bps=512000;
fsize=fast_rand()%31;
fswitch=100;
debruijn2(6,db62);
count=i=0;
do {
unsigned char toc;
const unsigned char *frames[48];
short size[48];
int payload_offset;
opus_uint32 dec_final_range2;
int jj,dec2;
int len,out_samples;
int frame_size=fsizes[db62[fsize]];
opus_int32 offset=i%(SAMPLES-MAX_FRAME_SAMP);
opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps));
len = opus_encode(enc, &inbuf[offset<<1], frame_size, packet, MAX_PACKET);
if(len<0 || len>MAX_PACKET)test_failed();
count++;
opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range));
out_samples = opus_decode(dec, packet, len, &outbuf[offset<<1], MAX_FRAME_SAMP, 0);
if(out_samples!=frame_size)test_failed();
opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
/* compare final range encoder rng values of encoder and decoder */
if(dec_final_range!=enc_final_range)test_failed();
/* We fuzz the packet, but take care not to only corrupt the payload
Corrupted headers are tested elsewhere and we need to actually run
the decoders in order to compare them. */
if(opus_packet_parse(packet,len,&toc,frames,size,&payload_offset)<=0)test_failed();
if((fast_rand()&1023)==0)len=0;
for(j=payload_offset;j<len;j++)for(jj=0;jj<8;jj++)packet[j]^=((fast_rand()&1023)==0)<<jj;
out_samples = opus_decode(dec_err[0], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0);
if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed();
if((len>0&&out_samples!=frame_size))test_failed(); /*FIXME use lastframe*/
opus_decoder_ctl(dec_err[0], OPUS_GET_FINAL_RANGE(&dec_final_range));
/*randomly select one of the decoders to compare with*/
dec2=fast_rand()%9+1;
out_samples = opus_decode(dec_err[dec2], len>0?packet:NULL, len, out2buf, MAX_FRAME_SAMP, 0);
if(out_samples<0||out_samples>MAX_FRAME_SAMP)test_failed(); /*FIXME, use factor, lastframe for loss*/
opus_decoder_ctl(dec_err[dec2], OPUS_GET_FINAL_RANGE(&dec_final_range2));
if(len>0&&dec_final_range!=dec_final_range2)test_failed();
fswitch--;
if(fswitch<1)
{
int new_size;
fsize=(fsize+1)%36;
new_size=fsizes[db62[fsize]];
if(new_size==960||new_size==480)fswitch=2880/new_size*(fast_rand()%19+1);
else fswitch=(fast_rand()%(2880/new_size))+1;
}
bitrate_bps=((fast_rand()%508000+4000)+bitrate_bps)>>1;
i+=frame_size;
}while(i<SAMPLES*4);
fprintf(stdout," All framesize pairs switching encode, %d frames OK.\n",count);
opus_encoder_destroy(enc);
opus_encoder_destroy(enc2);
opus_decoder_destroy(dec);
for(i=0;i<10;i++)opus_decoder_destroy(dec_err[i]);
free(inbuf);
free(outbuf);
free(out2buf);
return 0;
}
int main(int _argc, char **_argv)
{
const char * oversion;
if(_argc>2)
{
fprintf(stderr,"Usage: %s [<seed>]\n",_argv[0]);
return 1;
}
if(_argc>1)iseed=atoi(_argv[1]);
else iseed=(opus_uint32)time(NULL)^((getpid()&65535)<<16);
Rw=Rz=iseed;
oversion=opus_get_version_string();
if(!oversion)test_failed();
fprintf(stderr,"Testing %s encoder. Random seed: %u (%.4X)\n", oversion, iseed, fast_rand() % 65535);
run_test1();
fprintf(stderr,"Tests completed successfully.\n");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment