Built SDL2_image and _mixer static

This commit is contained in:
2022-09-30 15:49:16 -04:00
parent e2605bf6c1
commit 1dec4347e0
4473 changed files with 1964551 additions and 9 deletions

View File

@@ -0,0 +1,47 @@
/* Copyright (c) 2011 Xiph.Org Foundation, Skype Limited
Written by Jean-Marc Valin and Koen Vos */
/*
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 COPYRIGHT OWNER
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 "opus.h"
#include "opus_private.h"
int encode_size(int size, unsigned char *data)
{
if (size < 252)
{
data[0] = size;
return 1;
} else {
data[0] = 252+(size&0x3);
data[1] = (size-(int)data[0])>>2;
return 2;
}
}

View File

@@ -0,0 +1,218 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectName>opus</ProjectName>
<ProjectGuid>{219EC965-228A-1824-174D-96449D05F88A}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<CustomBuildBeforeTargets>
</CustomBuildBeforeTargets>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>"$(ProjectDir)..\win32\genversion.bat" "$(ProjectDir)..\win32\version.h" OPUS_VERSION</Command>
<Message>Generating version.h</Message>
</PreBuildEvent>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
<CustomBuildStep>
<Outputs>
</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>"$(ProjectDir)..\win32\genversion.bat" "$(ProjectDir)..\win32\version.h" OPUS_VERSION</Command>
<Message>Generating version.h</Message>
</PreBuildEvent>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
<CustomBuildStep>
<Outputs>
</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LinkStatus>false</LinkStatus>
</Link>
<PreBuildEvent>
<Command>"$(ProjectDir)..\win32\genversion.bat" "$(ProjectDir)..\win32\version.h" OPUS_VERSION</Command>
<Message>Generating version.h</Message>
</PreBuildEvent>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
<CustomBuildStep>
<Outputs>
</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>celt.lib;silk_common.lib;silk_fixed.lib;silk_float.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LinkStatus>false</LinkStatus>
</Link>
<PreBuildEvent>
<Command>"$(ProjectDir)..\win32\genversion.bat" "$(ProjectDir)..\win32\version.h" OPUS_VERSION</Command>
<Message>Generating version.h</Message>
</PreBuildEvent>
<CustomBuildStep>
<Command>
</Command>
</CustomBuildStep>
<CustomBuildStep>
<Outputs>
</Outputs>
</CustomBuildStep>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="opus.c" />
<ClCompile Include="opus_decoder.c" />
<ClCompile Include="opus_encoder.c" />
<ClCompile Include="opus_multistream.c" />
<ClCompile Include="repacketizer.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\celt\arch.h" />
<ClInclude Include="..\celt\celt.h" />
<ClInclude Include="..\celt\entdec.h" />
<ClInclude Include="..\celt\entenc.h" />
<ClInclude Include="..\celt\float_cast.h" />
<ClInclude Include="..\celt\os_support.h" />
<ClInclude Include="..\celt\stack_alloc.h" />
<ClInclude Include="..\include\opus.h" />
<ClInclude Include="..\include\opus_defines.h" />
<ClInclude Include="..\include\opus_types.h" />
<ClInclude Include="..\include\opus_multistream.h" />
<ClInclude Include="..\win32\config.h" />
<ClInclude Include="opus_private.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="opus_decoder.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_encoder.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="repacketizer.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_multistream.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\win32\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="opus_private.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\arch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\celt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\entdec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\entenc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\float_cast.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\os_support.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\stack_alloc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus_defines.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus_types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus_multistream.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,379 @@
/* Copyright (c) 2011-2012 Xiph.Org Foundation, Mozilla Corporation
Written by Jean-Marc Valin and Timothy B. Terriberry */
/*
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 COPYRIGHT OWNER
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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define OPUS_PI (3.14159265F)
#define OPUS_COSF(_x) ((float)cos(_x))
#define OPUS_SINF(_x) ((float)sin(_x))
static void *check_alloc(void *_ptr){
if(_ptr==NULL){
fprintf(stderr,"Out of memory.\n");
exit(EXIT_FAILURE);
}
return _ptr;
}
static void *opus_malloc(size_t _size){
return check_alloc(malloc(_size));
}
static void *opus_realloc(void *_ptr,size_t _size){
return check_alloc(realloc(_ptr,_size));
}
static size_t read_pcm16(float **_samples,FILE *_fin,int _nchannels){
unsigned char buf[1024];
float *samples;
size_t nsamples;
size_t csamples;
size_t xi;
size_t nread;
samples=NULL;
nsamples=csamples=0;
for(;;){
nread=fread(buf,2*_nchannels,1024/(2*_nchannels),_fin);
if(nread<=0)break;
if(nsamples+nread>csamples){
do csamples=csamples<<1|1;
while(nsamples+nread>csamples);
samples=(float *)opus_realloc(samples,
_nchannels*csamples*sizeof(*samples));
}
for(xi=0;xi<nread;xi++){
int ci;
for(ci=0;ci<_nchannels;ci++){
int s;
s=buf[2*(xi*_nchannels+ci)+1]<<8|buf[2*(xi*_nchannels+ci)];
s=((s&0xFFFF)^0x8000)-0x8000;
samples[(nsamples+xi)*_nchannels+ci]=s;
}
}
nsamples+=nread;
}
*_samples=(float *)opus_realloc(samples,
_nchannels*nsamples*sizeof(*samples));
return nsamples;
}
static void band_energy(float *_out,float *_ps,const int *_bands,int _nbands,
const float *_in,int _nchannels,size_t _nframes,int _window_sz,
int _step,int _downsample){
float *window;
float *x;
float *c;
float *s;
size_t xi;
int xj;
int ps_sz;
window=(float *)opus_malloc((3+_nchannels)*_window_sz*sizeof(*window));
c=window+_window_sz;
s=c+_window_sz;
x=s+_window_sz;
ps_sz=_window_sz/2;
for(xj=0;xj<_window_sz;xj++){
window[xj]=0.5F-0.5F*OPUS_COSF((2*OPUS_PI/(_window_sz-1))*xj);
}
for(xj=0;xj<_window_sz;xj++){
c[xj]=OPUS_COSF((2*OPUS_PI/_window_sz)*xj);
}
for(xj=0;xj<_window_sz;xj++){
s[xj]=OPUS_SINF((2*OPUS_PI/_window_sz)*xj);
}
for(xi=0;xi<_nframes;xi++){
int ci;
int xk;
int bi;
for(ci=0;ci<_nchannels;ci++){
for(xk=0;xk<_window_sz;xk++){
x[ci*_window_sz+xk]=window[xk]*_in[(xi*_step+xk)*_nchannels+ci];
}
}
for(bi=xj=0;bi<_nbands;bi++){
float p[2]={0};
for(;xj<_bands[bi+1];xj++){
for(ci=0;ci<_nchannels;ci++){
float re;
float im;
int ti;
ti=0;
re=im=0;
for(xk=0;xk<_window_sz;xk++){
re+=c[ti]*x[ci*_window_sz+xk];
im-=s[ti]*x[ci*_window_sz+xk];
ti+=xj;
if(ti>=_window_sz)ti-=_window_sz;
}
re*=_downsample;
im*=_downsample;
_ps[(xi*ps_sz+xj)*_nchannels+ci]=re*re+im*im+100000;
p[ci]+=_ps[(xi*ps_sz+xj)*_nchannels+ci];
}
}
if(_out){
_out[(xi*_nbands+bi)*_nchannels]=p[0]/(_bands[bi+1]-_bands[bi]);
if(_nchannels==2){
_out[(xi*_nbands+bi)*_nchannels+1]=p[1]/(_bands[bi+1]-_bands[bi]);
}
}
}
}
free(window);
}
#define NBANDS (21)
#define NFREQS (240)
/*Bands on which we compute the pseudo-NMR (Bark-derived
CELT bands).*/
static const int BANDS[NBANDS+1]={
0,2,4,6,8,10,12,14,16,20,24,28,32,40,48,56,68,80,96,120,156,200
};
#define TEST_WIN_SIZE (480)
#define TEST_WIN_STEP (120)
int main(int _argc,const char **_argv){
FILE *fin1;
FILE *fin2;
float *x;
float *y;
float *xb;
float *X;
float *Y;
double err;
float Q;
size_t xlength;
size_t ylength;
size_t nframes;
size_t xi;
int ci;
int xj;
int bi;
int nchannels;
unsigned rate;
int downsample;
int ybands;
int yfreqs;
int max_compare;
if(_argc<3||_argc>6){
fprintf(stderr,"Usage: %s [-s] [-r rate2] <file1.sw> <file2.sw>\n",
_argv[0]);
return EXIT_FAILURE;
}
nchannels=1;
if(strcmp(_argv[1],"-s")==0){
nchannels=2;
_argv++;
}
rate=48000;
ybands=NBANDS;
yfreqs=NFREQS;
downsample=1;
if(strcmp(_argv[1],"-r")==0){
rate=atoi(_argv[2]);
if(rate!=8000&&rate!=12000&&rate!=16000&&rate!=24000&&rate!=48000){
fprintf(stderr,
"Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n");
return EXIT_FAILURE;
}
downsample=48000/rate;
switch(rate){
case 8000:ybands=13;break;
case 12000:ybands=15;break;
case 16000:ybands=17;break;
case 24000:ybands=19;break;
}
yfreqs=NFREQS/downsample;
_argv+=2;
}
fin1=fopen(_argv[1],"rb");
if(fin1==NULL){
fprintf(stderr,"Error opening '%s'.\n",_argv[1]);
return EXIT_FAILURE;
}
fin2=fopen(_argv[2],"rb");
if(fin2==NULL){
fprintf(stderr,"Error opening '%s'.\n",_argv[2]);
fclose(fin1);
return EXIT_FAILURE;
}
/*Read in the data and allocate scratch space.*/
xlength=read_pcm16(&x,fin1,2);
if(nchannels==1){
for(xi=0;xi<xlength;xi++)x[xi]=.5*(x[2*xi]+x[2*xi+1]);
}
fclose(fin1);
ylength=read_pcm16(&y,fin2,nchannels);
fclose(fin2);
if(xlength!=ylength*downsample){
fprintf(stderr,"Sample counts do not match (%lu!=%lu).\n",
(unsigned long)xlength,(unsigned long)ylength*downsample);
return EXIT_FAILURE;
}
if(xlength<TEST_WIN_SIZE){
fprintf(stderr,"Insufficient sample data (%lu<%i).\n",
(unsigned long)xlength,TEST_WIN_SIZE);
return EXIT_FAILURE;
}
nframes=(xlength-TEST_WIN_SIZE+TEST_WIN_STEP)/TEST_WIN_STEP;
xb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb));
X=(float *)opus_malloc(nframes*NFREQS*nchannels*sizeof(*X));
Y=(float *)opus_malloc(nframes*yfreqs*nchannels*sizeof(*Y));
/*Compute the per-band spectral energy of the original signal
and the error.*/
band_energy(xb,X,BANDS,NBANDS,x,nchannels,nframes,
TEST_WIN_SIZE,TEST_WIN_STEP,1);
free(x);
band_energy(NULL,Y,BANDS,ybands,y,nchannels,nframes,
TEST_WIN_SIZE/downsample,TEST_WIN_STEP/downsample,downsample);
free(y);
for(xi=0;xi<nframes;xi++){
/*Frequency masking (low to high): 10 dB/Bark slope.*/
for(bi=1;bi<NBANDS;bi++){
for(ci=0;ci<nchannels;ci++){
xb[(xi*NBANDS+bi)*nchannels+ci]+=
0.1F*xb[(xi*NBANDS+bi-1)*nchannels+ci];
}
}
/*Frequency masking (high to low): 15 dB/Bark slope.*/
for(bi=NBANDS-1;bi-->0;){
for(ci=0;ci<nchannels;ci++){
xb[(xi*NBANDS+bi)*nchannels+ci]+=
0.03F*xb[(xi*NBANDS+bi+1)*nchannels+ci];
}
}
if(xi>0){
/*Temporal masking: -3 dB/2.5ms slope.*/
for(bi=0;bi<NBANDS;bi++){
for(ci=0;ci<nchannels;ci++){
xb[(xi*NBANDS+bi)*nchannels+ci]+=
0.5F*xb[((xi-1)*NBANDS+bi)*nchannels+ci];
}
}
}
/* Allowing some cross-talk */
if(nchannels==2){
for(bi=0;bi<NBANDS;bi++){
float l,r;
l=xb[(xi*NBANDS+bi)*nchannels+0];
r=xb[(xi*NBANDS+bi)*nchannels+1];
xb[(xi*NBANDS+bi)*nchannels+0]+=0.01F*r;
xb[(xi*NBANDS+bi)*nchannels+1]+=0.01F*l;
}
}
/* Apply masking */
for(bi=0;bi<ybands;bi++){
for(xj=BANDS[bi];xj<BANDS[bi+1];xj++){
for(ci=0;ci<nchannels;ci++){
X[(xi*NFREQS+xj)*nchannels+ci]+=
0.1F*xb[(xi*NBANDS+bi)*nchannels+ci];
Y[(xi*yfreqs+xj)*nchannels+ci]+=
0.1F*xb[(xi*NBANDS+bi)*nchannels+ci];
}
}
}
}
/* Average of consecutive frames to make comparison slightly less sensitive */
for(bi=0;bi<ybands;bi++){
for(xj=BANDS[bi];xj<BANDS[bi+1];xj++){
for(ci=0;ci<nchannels;ci++){
float xtmp;
float ytmp;
xtmp = X[xj*nchannels+ci];
ytmp = Y[xj*nchannels+ci];
for(xi=1;xi<nframes;xi++){
float xtmp2;
float ytmp2;
xtmp2 = X[(xi*NFREQS+xj)*nchannels+ci];
ytmp2 = Y[(xi*yfreqs+xj)*nchannels+ci];
X[(xi*NFREQS+xj)*nchannels+ci] += xtmp;
Y[(xi*yfreqs+xj)*nchannels+ci] += ytmp;
xtmp = xtmp2;
ytmp = ytmp2;
}
}
}
}
/*If working at a lower sampling rate, don't take into account the last
300 Hz to allow for different transition bands.
For 12 kHz, we don't skip anything, because the last band already skips
400 Hz.*/
if(rate==48000)max_compare=BANDS[NBANDS];
else if(rate==12000)max_compare=BANDS[ybands];
else max_compare=BANDS[ybands]-3;
err=0;
for(xi=0;xi<nframes;xi++){
double Ef;
Ef=0;
for(bi=0;bi<ybands;bi++){
double Eb;
Eb=0;
for(xj=BANDS[bi];xj<BANDS[bi+1]&&xj<max_compare;xj++){
for(ci=0;ci<nchannels;ci++){
float re;
float im;
re=Y[(xi*yfreqs+xj)*nchannels+ci]/X[(xi*NFREQS+xj)*nchannels+ci];
im=re-log(re)-1;
/*Make comparison less sensitive around the SILK/CELT cross-over to
allow for mode freedom in the filters.*/
if(xj>=79&&xj<=81)im*=0.1F;
if(xj==80)im*=0.1F;
Eb+=im;
}
}
Eb /= (BANDS[bi+1]-BANDS[bi])*nchannels;
Ef += Eb*Eb;
}
/*Using a fixed normalization value means we're willing to accept slightly
lower quality for lower sampling rates.*/
Ef/=NBANDS;
Ef*=Ef;
err+=Ef*Ef;
}
err=pow(err/nframes,1.0/16);
Q=100*(1-0.5*log(1+err)/log(1.13));
if(Q<0){
fprintf(stderr,"Test vector FAILS\n");
fprintf(stderr,"Internal weighted error is %f\n",err);
return EXIT_FAILURE;
}
else{
fprintf(stderr,"Test vector PASSES\n");
fprintf(stderr,
"Opus quality metric: %.1f %% (internal weighted error is %f)\n",Q,err);
return EXIT_SUCCESS;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,794 @@
/* Copyright (c) 2007-2008 CSIRO
Copyright (c) 2007-2009 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
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 COPYRIGHT OWNER
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 <math.h>
#include <string.h>
#include "opus.h"
#include "debug.h"
#include "opus_types.h"
#include "opus_private.h"
#define MAX_PACKET 1500
void print_usage( char* argv[] )
{
fprintf(stderr, "Usage: %s [-e] <application> <sampling rate (Hz)> <channels (1/2)> "
"<bits per second> [options] <input> <output>\n", argv[0]);
fprintf(stderr, " %s -d <sampling rate (Hz)> <channels (1/2)> "
"[options] <input> <output>\n\n", argv[0]);
fprintf(stderr, "mode: voip | audio | restricted-lowdelay\n" );
fprintf(stderr, "options:\n" );
fprintf(stderr, "-e : only runs the encoder (output the bit-stream)\n" );
fprintf(stderr, "-d : only runs the decoder (reads the bit-stream as input)\n" );
fprintf(stderr, "-cbr : enable constant bitrate; default: variable bitrate\n" );
fprintf(stderr, "-cvbr : enable constrained variable bitrate; default: unconstrained\n" );
fprintf(stderr, "-bandwidth <NB|MB|WB|SWB|FB> : audio bandwidth (from narrowband to fullband); default: sampling rate\n" );
fprintf(stderr, "-framesize <2.5|5|10|20|40|60> : frame size in ms; default: 20 \n" );
fprintf(stderr, "-max_payload <bytes> : maximum payload size in bytes, default: 1024\n" );
fprintf(stderr, "-complexity <comp> : complexity, 0 (lowest) ... 10 (highest); default: 10\n" );
fprintf(stderr, "-inbandfec : enable SILK inband FEC\n" );
fprintf(stderr, "-forcemono : force mono encoding, even for stereo input\n" );
fprintf(stderr, "-dtx : enable SILK DTX\n" );
fprintf(stderr, "-loss <perc> : simulate packet loss, in percent (0-100); default: 0\n" );
}
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 opus_uint32 char_to_int(unsigned char ch[4])
{
return ((opus_uint32)ch[0]<<24) | ((opus_uint32)ch[1]<<16)
| ((opus_uint32)ch[2]<< 8) | (opus_uint32)ch[3];
}
static void check_decoder_option(int encode_only, const char *opt)
{
if (encode_only)
{
fprintf(stderr, "option %s is only for decoding\n", opt);
exit(EXIT_FAILURE);
}
}
static void check_encoder_option(int decode_only, const char *opt)
{
if (decode_only)
{
fprintf(stderr, "option %s is only for encoding\n", opt);
exit(EXIT_FAILURE);
}
}
static const int silk8_test[][4] = {
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960*3, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960*2, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 480, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960*3, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960*2, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_NARROWBAND, 480, 2}
};
static const int silk12_test[][4] = {
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960*3, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960*2, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 480, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960*3, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960*2, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 960, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_MEDIUMBAND, 480, 2}
};
static const int silk16_test[][4] = {
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960*3, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960*2, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 480, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960*3, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960*2, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_WIDEBAND, 480, 2}
};
static const int hybrid24_test[][4] = {
{MODE_SILK_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 960, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 480, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 960, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 480, 2}
};
static const int hybrid48_test[][4] = {
{MODE_SILK_ONLY, OPUS_BANDWIDTH_FULLBAND, 960, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_FULLBAND, 480, 1},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_FULLBAND, 960, 2},
{MODE_SILK_ONLY, OPUS_BANDWIDTH_FULLBAND, 480, 2}
};
static const int celt_test[][4] = {
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 960, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 960, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 480, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 480, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 480, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 480, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 240, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 240, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 240, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 240, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 120, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 120, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 120, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 120, 1},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 960, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 960, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 960, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 960, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 480, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 480, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 480, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 480, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 240, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 240, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 240, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 240, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 120, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_SUPERWIDEBAND, 120, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_WIDEBAND, 120, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_NARROWBAND, 120, 2},
};
static const int celt_hq_test[][4] = {
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 960, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 480, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 240, 2},
{MODE_CELT_ONLY, OPUS_BANDWIDTH_FULLBAND, 120, 2},
};
int main(int argc, char *argv[])
{
int err;
char *inFile, *outFile;
FILE *fin, *fout;
OpusEncoder *enc=NULL;
OpusDecoder *dec=NULL;
int args;
int len[2];
int frame_size, channels;
opus_int32 bitrate_bps=0;
unsigned char *data[2];
unsigned char *fbytes;
opus_int32 sampling_rate;
int use_vbr;
int max_payload_bytes;
int complexity;
int use_inbandfec;
int use_dtx;
int forcechannels;
int cvbr = 0;
int packet_loss_perc;
opus_int32 count=0, count_act=0;
int k;
opus_int32 skip=0;
int stop=0;
short *in, *out;
int application=OPUS_APPLICATION_AUDIO;
double bits=0.0, bits_max=0.0, bits_act=0.0, bits2=0.0, nrg;
int bandwidth=-1;
const char *bandwidth_string;
int lost = 0, lost_prev = 1;
int toggle = 0;
opus_uint32 enc_final_range[2];
opus_uint32 dec_final_range;
int encode_only=0, decode_only=0;
int max_frame_size = 960*6;
int curr_read=0;
int sweep_bps = 0;
int random_framesize=0, newsize=0, delayed_celt=0;
int sweep_max=0, sweep_min=0;
int random_fec=0;
const int (*mode_list)[4]=NULL;
int nb_modes_in_list=0;
int curr_mode=0;
int curr_mode_count=0;
int mode_switch_time = 48000;
if (argc < 5 )
{
print_usage( argv );
return EXIT_FAILURE;
}
fprintf(stderr, "%s\n", opus_get_version_string());
args = 1;
if (strcmp(argv[args], "-e")==0)
{
encode_only = 1;
args++;
} else if (strcmp(argv[args], "-d")==0)
{
decode_only = 1;
args++;
}
if (!decode_only && argc < 7 )
{
print_usage( argv );
return EXIT_FAILURE;
}
if (!decode_only)
{
if (strcmp(argv[args], "voip")==0)
application = OPUS_APPLICATION_VOIP;
else if (strcmp(argv[args], "restricted-lowdelay")==0)
application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
else if (strcmp(argv[args], "audio")!=0) {
fprintf(stderr, "unknown application: %s\n", argv[args]);
print_usage(argv);
return EXIT_FAILURE;
}
args++;
}
sampling_rate = (opus_int32)atol(argv[args]);
args++;
channels = atoi(argv[args]);
args++;
if (!decode_only)
{
bitrate_bps = (opus_int32)atol(argv[args]);
args++;
}
if (sampling_rate != 8000 && sampling_rate != 12000
&& sampling_rate != 16000 && sampling_rate != 24000
&& sampling_rate != 48000)
{
fprintf(stderr, "Supported sampling rates are 8000, 12000, "
"16000, 24000 and 48000.\n");
return EXIT_FAILURE;
}
frame_size = sampling_rate/50;
/* defaults: */
use_vbr = 1;
bandwidth = OPUS_AUTO;
max_payload_bytes = MAX_PACKET;
complexity = 10;
use_inbandfec = 0;
forcechannels = OPUS_AUTO;
use_dtx = 0;
packet_loss_perc = 0;
max_frame_size = 960*6;
curr_read=0;
while( args < argc - 2 ) {
/* process command line options */
if( strcmp( argv[ args ], "-cbr" ) == 0 ) {
check_encoder_option(decode_only, "-cbr");
use_vbr = 0;
args++;
} else if( strcmp( argv[ args ], "-bandwidth" ) == 0 ) {
check_encoder_option(decode_only, "-bandwidth");
if (strcmp(argv[ args + 1 ], "NB")==0)
bandwidth = OPUS_BANDWIDTH_NARROWBAND;
else if (strcmp(argv[ args + 1 ], "MB")==0)
bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
else if (strcmp(argv[ args + 1 ], "WB")==0)
bandwidth = OPUS_BANDWIDTH_WIDEBAND;
else if (strcmp(argv[ args + 1 ], "SWB")==0)
bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
else if (strcmp(argv[ args + 1 ], "FB")==0)
bandwidth = OPUS_BANDWIDTH_FULLBAND;
else {
fprintf(stderr, "Unknown bandwidth %s. "
"Supported are NB, MB, WB, SWB, FB.\n",
argv[ args + 1 ]);
return EXIT_FAILURE;
}
args += 2;
} else if( strcmp( argv[ args ], "-framesize" ) == 0 ) {
check_encoder_option(decode_only, "-framesize");
if (strcmp(argv[ args + 1 ], "2.5")==0)
frame_size = sampling_rate/400;
else if (strcmp(argv[ args + 1 ], "5")==0)
frame_size = sampling_rate/200;
else if (strcmp(argv[ args + 1 ], "10")==0)
frame_size = sampling_rate/100;
else if (strcmp(argv[ args + 1 ], "20")==0)
frame_size = sampling_rate/50;
else if (strcmp(argv[ args + 1 ], "40")==0)
frame_size = sampling_rate/25;
else if (strcmp(argv[ args + 1 ], "60")==0)
frame_size = 3*sampling_rate/50;
else {
fprintf(stderr, "Unsupported frame size: %s ms. "
"Supported are 2.5, 5, 10, 20, 40, 60.\n",
argv[ args + 1 ]);
return EXIT_FAILURE;
}
args += 2;
} else if( strcmp( argv[ args ], "-max_payload" ) == 0 ) {
check_encoder_option(decode_only, "-max_payload");
max_payload_bytes = atoi( argv[ args + 1 ] );
args += 2;
} else if( strcmp( argv[ args ], "-complexity" ) == 0 ) {
check_encoder_option(decode_only, "-complexity");
complexity = atoi( argv[ args + 1 ] );
args += 2;
} else if( strcmp( argv[ args ], "-inbandfec" ) == 0 ) {
use_inbandfec = 1;
args++;
} else if( strcmp( argv[ args ], "-forcemono" ) == 0 ) {
check_encoder_option(decode_only, "-forcemono");
forcechannels = 1;
args++;
} else if( strcmp( argv[ args ], "-cvbr" ) == 0 ) {
check_encoder_option(decode_only, "-cvbr");
cvbr = 1;
args++;
} else if( strcmp( argv[ args ], "-dtx") == 0 ) {
check_encoder_option(decode_only, "-dtx");
use_dtx = 1;
args++;
} else if( strcmp( argv[ args ], "-loss" ) == 0 ) {
check_decoder_option(encode_only, "-loss");
packet_loss_perc = atoi( argv[ args + 1 ] );
args += 2;
} else if( strcmp( argv[ args ], "-sweep" ) == 0 ) {
check_encoder_option(decode_only, "-sweep");
sweep_bps = atoi( argv[ args + 1 ] );
args += 2;
} else if( strcmp( argv[ args ], "-random_framesize" ) == 0 ) {
check_encoder_option(decode_only, "-random_framesize");
random_framesize = 1;
args++;
} else if( strcmp( argv[ args ], "-sweep_max" ) == 0 ) {
check_encoder_option(decode_only, "-sweep_max");
sweep_max = atoi( argv[ args + 1 ] );
args += 2;
} else if( strcmp( argv[ args ], "-random_fec" ) == 0 ) {
check_encoder_option(decode_only, "-random_fec");
random_fec = 1;
args++;
} else if( strcmp( argv[ args ], "-silk8k_test" ) == 0 ) {
check_encoder_option(decode_only, "-silk8k_test");
mode_list = silk8_test;
nb_modes_in_list = 8;
args++;
} else if( strcmp( argv[ args ], "-silk12k_test" ) == 0 ) {
check_encoder_option(decode_only, "-silk12k_test");
mode_list = silk12_test;
nb_modes_in_list = 8;
args++;
} else if( strcmp( argv[ args ], "-silk16k_test" ) == 0 ) {
check_encoder_option(decode_only, "-silk16k_test");
mode_list = silk16_test;
nb_modes_in_list = 8;
args++;
} else if( strcmp( argv[ args ], "-hybrid24k_test" ) == 0 ) {
check_encoder_option(decode_only, "-hybrid24k_test");
mode_list = hybrid24_test;
nb_modes_in_list = 4;
args++;
} else if( strcmp( argv[ args ], "-hybrid48k_test" ) == 0 ) {
check_encoder_option(decode_only, "-hybrid48k_test");
mode_list = hybrid48_test;
nb_modes_in_list = 4;
args++;
} else if( strcmp( argv[ args ], "-celt_test" ) == 0 ) {
check_encoder_option(decode_only, "-celt_test");
mode_list = celt_test;
nb_modes_in_list = 32;
args++;
} else if( strcmp( argv[ args ], "-celt_hq_test" ) == 0 ) {
check_encoder_option(decode_only, "-celt_hq_test");
mode_list = celt_hq_test;
nb_modes_in_list = 4;
args++;
} else {
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
print_usage( argv );
return EXIT_FAILURE;
}
}
if (sweep_max)
sweep_min = bitrate_bps;
if (max_payload_bytes < 0 || max_payload_bytes > MAX_PACKET)
{
fprintf (stderr, "max_payload_bytes must be between 0 and %d\n",
MAX_PACKET);
return EXIT_FAILURE;
}
inFile = argv[argc-2];
fin = fopen(inFile, "rb");
if (!fin)
{
fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
return EXIT_FAILURE;
}
if (mode_list)
{
int size;
fseek(fin, 0, SEEK_END);
size = ftell(fin);
fprintf(stderr, "File size is %d bytes\n", size);
fseek(fin, 0, SEEK_SET);
mode_switch_time = size/sizeof(short)/channels/nb_modes_in_list;
fprintf(stderr, "Switching mode every %d samples\n", mode_switch_time);
}
outFile = argv[argc-1];
fout = fopen(outFile, "wb+");
if (!fout)
{
fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
fclose(fin);
return EXIT_FAILURE;
}
if (!decode_only)
{
enc = opus_encoder_create(sampling_rate, channels, application, &err);
if (err != OPUS_OK)
{
fprintf(stderr, "Cannot create encoder: %s\n", opus_strerror(err));
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps));
opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(bandwidth));
opus_encoder_ctl(enc, OPUS_SET_VBR(use_vbr));
opus_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(cvbr));
opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(use_inbandfec));
opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(forcechannels));
opus_encoder_ctl(enc, OPUS_SET_DTX(use_dtx));
opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(packet_loss_perc));
opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&skip));
opus_encoder_ctl(enc, OPUS_SET_LSB_DEPTH(16));
}
if (!encode_only)
{
dec = opus_decoder_create(sampling_rate, channels, &err);
if (err != OPUS_OK)
{
fprintf(stderr, "Cannot create decoder: %s\n", opus_strerror(err));
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
}
switch(bandwidth)
{
case OPUS_BANDWIDTH_NARROWBAND:
bandwidth_string = "narrowband";
break;
case OPUS_BANDWIDTH_MEDIUMBAND:
bandwidth_string = "mediumband";
break;
case OPUS_BANDWIDTH_WIDEBAND:
bandwidth_string = "wideband";
break;
case OPUS_BANDWIDTH_SUPERWIDEBAND:
bandwidth_string = "superwideband";
break;
case OPUS_BANDWIDTH_FULLBAND:
bandwidth_string = "fullband";
break;
case OPUS_AUTO:
bandwidth_string = "auto";
break;
default:
bandwidth_string = "unknown";
break;
}
if (decode_only)
fprintf(stderr, "Decoding with %ld Hz output (%d channels)\n",
(long)sampling_rate, channels);
else
fprintf(stderr, "Encoding %ld Hz input at %.3f kb/s "
"in %s mode with %d-sample frames.\n",
(long)sampling_rate, bitrate_bps*0.001,
bandwidth_string, frame_size);
in = (short*)malloc(max_frame_size*channels*sizeof(short));
out = (short*)malloc(max_frame_size*channels*sizeof(short));
fbytes = (unsigned char*)malloc(max_frame_size*channels*sizeof(short));
data[0] = (unsigned char*)calloc(max_payload_bytes,sizeof(char));
if ( use_inbandfec ) {
data[1] = (unsigned char*)calloc(max_payload_bytes,sizeof(char));
}
while (!stop)
{
if (delayed_celt)
{
frame_size = newsize;
delayed_celt = 0;
} else if (random_framesize && rand()%20==0)
{
newsize = rand()%6;
switch(newsize)
{
case 0: newsize=sampling_rate/400; break;
case 1: newsize=sampling_rate/200; break;
case 2: newsize=sampling_rate/100; break;
case 3: newsize=sampling_rate/50; break;
case 4: newsize=sampling_rate/25; break;
case 5: newsize=3*sampling_rate/50; break;
}
while (newsize < sampling_rate/25 && bitrate_bps-fabs(sweep_bps) <= 3*12*sampling_rate/newsize)
newsize*=2;
if (newsize < sampling_rate/100 && frame_size >= sampling_rate/100)
{
opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(MODE_CELT_ONLY));
delayed_celt=1;
} else {
frame_size = newsize;
}
}
if (random_fec && rand()%30==0)
{
opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC(rand()%4==0));
}
if (decode_only)
{
unsigned char ch[4];
err = fread(ch, 1, 4, fin);
if (feof(fin))
break;
len[toggle] = char_to_int(ch);
if (len[toggle]>max_payload_bytes || len[toggle]<0)
{
fprintf(stderr, "Invalid payload length: %d\n",len[toggle]);
break;
}
err = fread(ch, 1, 4, fin);
enc_final_range[toggle] = char_to_int(ch);
err = fread(data[toggle], 1, len[toggle], fin);
if (err<len[toggle])
{
fprintf(stderr, "Ran out of input, "
"expecting %d bytes got %d\n",
len[toggle],err);
break;
}
} else {
int i;
if (mode_list!=NULL)
{
opus_encoder_ctl(enc, OPUS_SET_BANDWIDTH(mode_list[curr_mode][1]));
opus_encoder_ctl(enc, OPUS_SET_FORCE_MODE(mode_list[curr_mode][0]));
opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(mode_list[curr_mode][3]));
frame_size = mode_list[curr_mode][2];
}
err = fread(fbytes, sizeof(short)*channels, frame_size, fin);
curr_read = err;
for(i=0;i<curr_read*channels;i++)
{
opus_int32 s;
s=fbytes[2*i+1]<<8|fbytes[2*i];
s=((s&0xFFFF)^0x8000)-0x8000;
in[i]=s;
}
if (curr_read < frame_size)
{
for (i=curr_read*channels;i<frame_size*channels;i++)
in[i] = 0;
stop = 1;
}
len[toggle] = opus_encode(enc, in, frame_size, data[toggle], max_payload_bytes);
if (sweep_bps!=0)
{
bitrate_bps += sweep_bps;
if (sweep_max)
{
if (bitrate_bps > sweep_max)
sweep_bps = -sweep_bps;
else if (bitrate_bps < sweep_min)
sweep_bps = -sweep_bps;
}
/* safety */
if (bitrate_bps<1000)
bitrate_bps = 1000;
opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate_bps));
}
opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range[toggle]));
if (len[toggle] < 0)
{
fprintf (stderr, "opus_encode() returned %d\n", len[toggle]);
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
curr_mode_count += frame_size;
if (curr_mode_count > mode_switch_time && curr_mode < nb_modes_in_list-1)
{
curr_mode++;
curr_mode_count = 0;
}
}
if (encode_only)
{
unsigned char int_field[4];
int_to_char(len[toggle], int_field);
if (fwrite(int_field, 1, 4, fout) != 4) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
int_to_char(enc_final_range[toggle], int_field);
if (fwrite(int_field, 1, 4, fout) != 4) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
if (fwrite(data[toggle], 1, len[toggle], fout) != (unsigned)len[toggle]) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
} else {
int output_samples;
lost = len[toggle]==0 || (packet_loss_perc>0 && rand()%100 < packet_loss_perc);
if (lost)
opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
else
output_samples = max_frame_size;
if( count >= use_inbandfec ) {
/* delay by one packet when using in-band FEC */
if( use_inbandfec ) {
if( lost_prev ) {
/* attempt to decode with in-band FEC from next packet */
opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
output_samples = opus_decode(dec, lost ? NULL : data[toggle], len[toggle], out, output_samples, 1);
} else {
/* regular decode */
output_samples = max_frame_size;
output_samples = opus_decode(dec, data[1-toggle], len[1-toggle], out, output_samples, 0);
}
} else {
output_samples = opus_decode(dec, lost ? NULL : data[toggle], len[toggle], out, output_samples, 0);
}
if (output_samples>0)
{
if (output_samples>skip) {
int i;
for(i=0;i<(output_samples-skip)*channels;i++)
{
short s;
s=out[i+(skip*channels)];
fbytes[2*i]=s&0xFF;
fbytes[2*i+1]=(s>>8)&0xFF;
}
if (fwrite(fbytes, sizeof(short)*channels, output_samples-skip, fout) != (unsigned)(output_samples-skip)){
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
}
if (output_samples<skip) skip -= output_samples;
else skip = 0;
} else {
fprintf(stderr, "error decoding frame: %s\n",
opus_strerror(output_samples));
}
}
}
if (!encode_only)
opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
/* compare final range encoder rng values of encoder and decoder */
if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only
&& !lost && !lost_prev
&& dec_final_range != enc_final_range[toggle^use_inbandfec] ) {
fprintf (stderr, "Error: Range coder state mismatch "
"between encoder and decoder "
"in frame %ld: 0x%8lx vs 0x%8lx\n",
(long)count,
(unsigned long)enc_final_range[toggle^use_inbandfec],
(unsigned long)dec_final_range);
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
lost_prev = lost;
/* count bits */
bits += len[toggle]*8;
bits_max = ( len[toggle]*8 > bits_max ) ? len[toggle]*8 : bits_max;
if( count >= use_inbandfec ) {
nrg = 0.0;
if (!decode_only)
{
for ( k = 0; k < frame_size * channels; k++ ) {
nrg += in[ k ] * (double)in[ k ];
}
}
if ( ( nrg / ( frame_size * channels ) ) > 1e5 ) {
bits_act += len[toggle]*8;
count_act++;
}
/* Variance */
bits2 += len[toggle]*len[toggle]*64;
}
count++;
toggle = (toggle + use_inbandfec) & 1;
}
fprintf (stderr, "average bitrate: %7.3f kb/s\n",
1e-3*bits*sampling_rate/(frame_size*(double)count));
fprintf (stderr, "maximum bitrate: %7.3f kb/s\n",
1e-3*bits_max*sampling_rate/frame_size);
if (!decode_only)
fprintf (stderr, "active bitrate: %7.3f kb/s\n",
1e-3*bits_act*sampling_rate/(frame_size*(double)count_act));
fprintf (stderr, "bitrate standard deviation: %7.3f kb/s\n",
1e-3*sqrt(bits2/count - bits*bits/(count*(double)count))*sampling_rate/frame_size);
/* Close any files to which intermediate results were stored */
SILK_DEBUG_STORE_CLOSE_FILES
silk_TimerSave("opus_timing.txt");
opus_encoder_destroy(enc);
opus_decoder_destroy(dec);
free(data[0]);
if (use_inbandfec)
free(data[1]);
fclose(fin);
fclose(fout);
free(in);
free(out);
free(fbytes);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="opus.c" />
<ClCompile Include="opus_decoder.c" />
<ClCompile Include="opus_demo.c" />
<ClCompile Include="opus_encoder.c" />
<ClCompile Include="opus_multistream.c" />
<ClCompile Include="repacketizer.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\celt\arch.h" />
<ClInclude Include="..\celt\celt.h" />
<ClInclude Include="..\celt\entdec.h" />
<ClInclude Include="..\celt\entenc.h" />
<ClInclude Include="..\celt\float_cast.h" />
<ClInclude Include="..\celt\os_support.h" />
<ClInclude Include="..\celt\stack_alloc.h" />
<ClInclude Include="..\include\opus.h" />
<ClInclude Include="..\include\opus_defines.h" />
<ClInclude Include="..\include\opus_types.h" />
<ClInclude Include="..\win32\config.h" />
<ClInclude Include="opus_private.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{016C739D-6389-43BF-8D88-24B2BF6F620F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>opus_demo</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(SolutionDir)$(Configuration)\opus.lib;$(SolutionDir)$(Configuration)\celt.lib;$(SolutionDir)$(Configuration)\silk_common.lib;$(SolutionDir)$(Configuration)\silk_float.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>HAVE_CONFIG_H;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>../silk;../celt;../win32;../include;</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)$(Configuration)\opus.lib;$(SolutionDir)$(Configuration)\celt.lib;$(SolutionDir)$(Configuration)\silk_common.lib;$(SolutionDir)$(Configuration)\silk_float.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="opus.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_decoder.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_encoder.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_multistream.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="repacketizer.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="opus_demo.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\celt\arch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\stack_alloc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\celt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\win32\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\entdec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\entenc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\float_cast.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus_defines.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="opus_private.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\opus_types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\celt\os_support.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
/* Copyright (c) 2012 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
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 COPYRIGHT OWNER
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.
*/
#ifndef OPUS_PRIVATE_H
#define OPUS_PRIVATE_H
#include "arch.h"
#include "opus.h"
struct OpusRepacketizer {
unsigned char toc;
int nb_frames;
const unsigned char *frames[48];
opus_int16 len[48];
int framesize;
};
#define MODE_SILK_ONLY 1000
#define MODE_HYBRID 1001
#define MODE_CELT_ONLY 1002
#define OPUS_SET_VOICE_RATIO_REQUEST 11018
#define OPUS_GET_VOICE_RATIO_REQUEST 11019
/** Configures the encoder's expected percentage of voice
* opposed to music or other signals.
*
* @note This interface is currently more aspiration than actuality. It's
* ultimately expected to bias an automatic signal classifier, but it currently
* just shifts the static bitrate to mode mapping around a little bit.
*
* @param[in] x <tt>int</tt>: Voice percentage in the range 0-100, inclusive.
* @hideinitializer */
#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
/** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
*
* @param[out] x <tt>int*</tt>: Voice percentage in the range 0-100, inclusive.
* @hideinitializer */
#define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
#define OPUS_SET_FORCE_MODE_REQUEST 11002
#define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
int encode_size(int size, unsigned char *data);
int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited, int *packet_offset);
/* Make sure everything's aligned to sizeof(void *) bytes */
static inline int align(int i)
{
return (i+sizeof(void *)-1)&-((int)sizeof(void *));
}
opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen, int self_delimited);
#endif /* OPUS_PRIVATE_H */

View File

@@ -0,0 +1,208 @@
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
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 COPYRIGHT OWNER
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 "opus.h"
#include "opus_private.h"
#include "os_support.h"
int opus_repacketizer_get_size(void)
{
return sizeof(OpusRepacketizer);
}
OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp)
{
rp->nb_frames = 0;
return rp;
}
OpusRepacketizer *opus_repacketizer_create(void)
{
OpusRepacketizer *rp;
rp=(OpusRepacketizer *)opus_alloc(opus_repacketizer_get_size());
if(rp==NULL)return NULL;
return opus_repacketizer_init(rp);
}
void opus_repacketizer_destroy(OpusRepacketizer *rp)
{
opus_free(rp);
}
int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len)
{
unsigned char tmp_toc;
int curr_nb_frames,ret;
/* Set of check ToC */
if (len<1) return OPUS_INVALID_PACKET;
if (rp->nb_frames == 0)
{
rp->toc = data[0];
rp->framesize = opus_packet_get_samples_per_frame(data, 8000);
} else if ((rp->toc&0xFC) != (data[0]&0xFC))
{
/*fprintf(stderr, "toc mismatch: 0x%x vs 0x%x\n", rp->toc, data[0]);*/
return OPUS_INVALID_PACKET;
}
curr_nb_frames = opus_packet_get_nb_frames(data, len);
if(curr_nb_frames<1) return OPUS_INVALID_PACKET;
/* Check the 120 ms maximum packet size */
if ((curr_nb_frames+rp->nb_frames)*rp->framesize > 960)
{
return OPUS_INVALID_PACKET;
}
ret=opus_packet_parse(data, len, &tmp_toc, &rp->frames[rp->nb_frames], &rp->len[rp->nb_frames], NULL);
if(ret<1)return ret;
rp->nb_frames += curr_nb_frames;
return OPUS_OK;
}
int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp)
{
return rp->nb_frames;
}
opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen, int self_delimited)
{
int i, count;
opus_int32 tot_size;
opus_int16 *len;
const unsigned char **frames;
if (begin<0 || begin>=end || end>rp->nb_frames)
{
/*fprintf(stderr, "%d %d %d\n", begin, end, rp->nb_frames);*/
return OPUS_BAD_ARG;
}
count = end-begin;
len = rp->len+begin;
frames = rp->frames+begin;
if (self_delimited)
tot_size = 1 + (len[count-1]>=252);
else
tot_size = 0;
switch (count)
{
case 1:
{
/* Code 0 */
tot_size += len[0]+1;
if (tot_size > maxlen)
return OPUS_BUFFER_TOO_SMALL;
*data++ = rp->toc&0xFC;
}
break;
case 2:
{
if (len[1] == len[0])
{
/* Code 1 */
tot_size += 2*len[0]+1;
if (tot_size > maxlen)
return OPUS_BUFFER_TOO_SMALL;
*data++ = (rp->toc&0xFC) | 0x1;
} else {
/* Code 2 */
tot_size += len[0]+len[1]+2+(len[0]>=252);
if (tot_size > maxlen)
return OPUS_BUFFER_TOO_SMALL;
*data++ = (rp->toc&0xFC) | 0x2;
data += encode_size(len[0], data);
}
}
break;
default:
{
/* Code 3 */
int vbr;
vbr = 0;
for (i=1;i<count;i++)
{
if (len[i] != len[0])
{
vbr=1;
break;
}
}
if (vbr)
{
tot_size += 2;
for (i=0;i<count-1;i++)
tot_size += 1 + (len[i]>=252) + len[i];
tot_size += len[count-1];
if (tot_size > maxlen)
return OPUS_BUFFER_TOO_SMALL;
*data++ = (rp->toc&0xFC) | 0x3;
*data++ = count | 0x80;
for (i=0;i<count-1;i++)
data += encode_size(len[i], data);
} else {
tot_size += count*len[0]+2;
if (tot_size > maxlen)
return OPUS_BUFFER_TOO_SMALL;
*data++ = (rp->toc&0xFC) | 0x3;
*data++ = count;
}
}
break;
}
if (self_delimited) {
int sdlen = encode_size(len[count-1], data);
data += sdlen;
}
/* Copy the actual data */
for (i=0;i<count;i++)
{
OPUS_COPY(data, frames[i], len[i]);
data += len[i];
}
return tot_size;
}
opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen)
{
return opus_repacketizer_out_range_impl(rp, begin, end, data, maxlen, 0);
}
opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen)
{
return opus_repacketizer_out_range_impl(rp, 0, rp->nb_frames, data, maxlen, 0);
}

View File

@@ -0,0 +1,212 @@
/* Copyright (c) 2011 Xiph.Org Foundation
Written by Jean-Marc Valin */
/*
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 COPYRIGHT OWNER
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 "opus.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PACKETOUT 32000
void usage(char *argv0)
{
fprintf(stderr, "usage: %s [options] input_file output_file\n", argv0);
}
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 opus_uint32 char_to_int(unsigned char ch[4])
{
return ((opus_uint32)ch[0]<<24) | ((opus_uint32)ch[1]<<16)
| ((opus_uint32)ch[2]<< 8) | (opus_uint32)ch[3];
}
int main(int argc, char *argv[])
{
int i, eof=0;
FILE *fin, *fout;
unsigned char packets[48][1500];
int len[48];
int rng[48];
OpusRepacketizer *rp;
unsigned char output_packet[MAX_PACKETOUT];
int merge = 1, split=0;
if (argc < 3)
{
usage(argv[0]);
return EXIT_FAILURE;
}
for (i=1;i<argc-2;i++)
{
if (strcmp(argv[i], "-merge")==0)
{
merge = atoi(argv[i+1]);
if(merge<1)
{
fprintf(stderr, "-merge parameter must be at least 1.\n");
return EXIT_FAILURE;
}
i++;
} else if (strcmp(argv[i], "-split")==0)
split = 1;
else
{
fprintf(stderr, "Unknown option: %s\n", argv[i]);
usage(argv[0]);
return EXIT_FAILURE;
}
}
fin = fopen(argv[argc-2], "r");
if(fin==NULL)
{
fprintf(stderr, "Error opening input file: %s\n", argv[argc-2]);
return EXIT_FAILURE;
}
fout = fopen(argv[argc-1], "w");
if(fout==NULL)
{
fprintf(stderr, "Error opening output file: %s\n", argv[argc-1]);
fclose(fin);
return EXIT_FAILURE;
}
rp = opus_repacketizer_create();
while (!eof)
{
int err;
int nb_packets=merge;
opus_repacketizer_init(rp);
for (i=0;i<nb_packets;i++)
{
unsigned char ch[4];
err = fread(ch, 1, 4, fin);
len[i] = char_to_int(ch);
/*fprintf(stderr, "in len = %d\n", len[i]);*/
if (len[i]>1500 || len[i]<0)
{
if (feof(fin))
{
eof = 1;
} else {
fprintf(stderr, "Invalid payload length\n");
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
break;
}
err = fread(ch, 1, 4, fin);
rng[i] = char_to_int(ch);
err = fread(packets[i], 1, len[i], fin);
if (feof(fin))
{
eof = 1;
break;
}
err = opus_repacketizer_cat(rp, packets[i], len[i]);
if (err!=OPUS_OK)
{
fprintf(stderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
break;
}
}
nb_packets = i;
if (eof)
break;
if (!split)
{
err = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);
if (err>0) {
unsigned char int_field[4];
int_to_char(err, int_field);
if(fwrite(int_field, 1, 4, fout)!=4){
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
int_to_char(rng[nb_packets-1], int_field);
if (fwrite(int_field, 1, 4, fout)!=4) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
/*fprintf(stderr, "out len = %d\n", err);*/
} else {
fprintf(stderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
}
} else {
int nb_frames = opus_repacketizer_get_nb_frames(rp);
for (i=0;i<nb_frames;i++)
{
err = opus_repacketizer_out_range(rp, i, i+1, output_packet, MAX_PACKETOUT);
if (err>0) {
unsigned char int_field[4];
int_to_char(err, int_field);
if (fwrite(int_field, 1, 4, fout)!=4) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
if (i==nb_frames-1)
int_to_char(rng[nb_packets-1], int_field);
else
int_to_char(0, int_field);
if (fwrite(int_field, 1, 4, fout)!=4) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
fprintf(stderr, "Error writing.\n");
return EXIT_FAILURE;
}
/*fprintf(stderr, "out len = %d\n", err);*/
} else {
fprintf(stderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
}
}
}
}
fclose(fin);
fclose(fout);
return EXIT_SUCCESS;
}