mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-16 22:38:38 +00:00
bring the code up to the release tarball
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@17026 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
92eef1edf7
commit
5bb9d2062e
151 files changed
+26639
-28320
No files matched your search
@@ -0,0 +1,217 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="Dec_SDK"
|
||||
ProjectGUID="{82685D7F-0589-42BD-877C-31A952D53A8E}"
|
||||
RootNamespace="Test"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)_Dec"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../interface;../src"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;COMPILE_SDK"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)\Decoder_debug.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreAllDefaultLibraries="false"
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)_Dec"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../interface;../src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;COMPILE_SDK"
|
||||
RuntimeLibrary="0"
|
||||
FloatingPointModel="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/fixed:no"
|
||||
OutputFile="$(OutDir)\Decoder.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Decoder.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="interface"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_control.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_errors.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_SDK_API.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_typedef.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
+363
-408
@@ -1,408 +1,363 @@
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
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.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE.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.
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
/******************************************************/
|
||||
/* Silk decoder test program */
|
||||
/******************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SKP_Silk_SDK_API.h"
|
||||
#include "SKP_Silk_SigProc_FIX.h"
|
||||
|
||||
/* Define codec specific settings should be moved to h file */
|
||||
#define MAX_BYTES_PER_FRAME 1024
|
||||
#define MAX_INPUT_FRAMES 5
|
||||
#define MAX_FRAME_LENGTH 480
|
||||
#define MAX_LBRR_DELAY 2
|
||||
|
||||
static void print_usage(char* argv[]) {
|
||||
printf( "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] );
|
||||
printf( "\nin.bit : Bitstream input to decoder" );
|
||||
printf( "\nout.pcm : Speech output from decoder" );
|
||||
printf( "\n settings:" );
|
||||
printf( "\n-fs <kHz> : Sampling rate of output signal in kHz; default: 24" );
|
||||
printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" );
|
||||
printf( "\n" );
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
size_t counter;
|
||||
SKP_int args, totPackets, i, k;
|
||||
SKP_int16 ret, len, tot_len;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SKP_int16 nBytes;
|
||||
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];
|
||||
SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr;
|
||||
SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL;
|
||||
SKP_int16 nBytesFEC;
|
||||
SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes;
|
||||
SKP_int16 out[ ( MAX_FRAME_LENGTH << 1 ) * MAX_INPUT_FRAMES ], *outPtr;
|
||||
char speechOutFileName[ 150 ], bitInFileName[ 150 ];
|
||||
FILE *bitInFile, *speechOutFile;
|
||||
SKP_int Fs_kHz = 0;
|
||||
SKP_int32 decSizeBytes;
|
||||
void *psDec;
|
||||
float loss_prob;
|
||||
SKP_int frames, lost, quiet;
|
||||
SKP_SILK_SDK_DecControlStruct DecControl;
|
||||
|
||||
if( argc < 3 ) {
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* default settings */
|
||||
quiet = 0;
|
||||
loss_prob = 0.0f;
|
||||
|
||||
/* get arguments */
|
||||
args = 1;
|
||||
strcpy( bitInFileName, argv[ args ] );
|
||||
args++;
|
||||
strcpy( speechOutFileName, argv[ args ] );
|
||||
args++;
|
||||
while( args < argc ) {
|
||||
if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%f", &loss_prob );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &Fs_kHz );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
|
||||
quiet = 1;
|
||||
args++;
|
||||
} else {
|
||||
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if( !quiet ) {
|
||||
printf("******************* Silk Decoder v %s ****************\n", SKP_Silk_SDK_get_version());
|
||||
printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
|
||||
printf( "Input: %s\n", bitInFileName );
|
||||
printf( "Output: %s\n", speechOutFileName );
|
||||
}
|
||||
|
||||
/* Open files */
|
||||
bitInFile = fopen( bitInFileName, "rb" );
|
||||
if( bitInFile == NULL ) {
|
||||
printf( "Error: could not open input file %s\n", bitInFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
speechOutFile = fopen( speechOutFileName, "wb" );
|
||||
if( speechOutFile == NULL ) {
|
||||
printf( "Error: could not open output file %s\n", speechOutFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* Set the samplingrate that is expected for the output */
|
||||
if( Fs_kHz == 0 ) {
|
||||
DecControl.sampleRate = 24000;
|
||||
} else {
|
||||
DecControl.sampleRate = Fs_kHz * 1000;
|
||||
}
|
||||
|
||||
/* Create decoder */
|
||||
ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Get_Decoder_Size returned %d", ret );
|
||||
}
|
||||
psDec = malloc( decSizeBytes );
|
||||
|
||||
/* Reset decoder */
|
||||
ret = SKP_Silk_SDK_InitDecoder( psDec );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_InitDecoder returned %d", ret );
|
||||
}
|
||||
|
||||
totPackets = 0;
|
||||
payloadEnd = payload;
|
||||
|
||||
/* Simulate the jitter buffer holding MAX_FEC_DELAY packets */
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
/* Read payload size */
|
||||
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
|
||||
/* Read payload */
|
||||
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if( (SKP_int16)counter < nBytes ) {
|
||||
break;
|
||||
}
|
||||
nBytesPerPacket[ i ] = nBytes;
|
||||
payloadEnd += nBytes;
|
||||
}
|
||||
|
||||
while( 1 ) {
|
||||
/* Read payload size */
|
||||
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
|
||||
if( nBytes < 0 || counter < 1 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read payload */
|
||||
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
|
||||
if( (SKP_int16)counter < nBytes ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Simulate losses */
|
||||
if( ( (float)rand() / (float)RAND_MAX >= loss_prob / 100 ) && counter > 0 ) {
|
||||
nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;
|
||||
payloadEnd += nBytes;
|
||||
} else {
|
||||
nBytesPerPacket[ MAX_LBRR_DELAY ] = 0;
|
||||
}
|
||||
|
||||
if( nBytesPerPacket[ 0 ] == 0 ) {
|
||||
/* Indicate lost packet */
|
||||
lost = 1;
|
||||
|
||||
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
|
||||
payloadPtr = payload;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
if( nBytesPerPacket[ i + 1 ] > 0 ) {
|
||||
SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
|
||||
if( nBytesFEC > 0 ) {
|
||||
payloadToDec = FECpayload;
|
||||
nBytes = nBytesFEC;
|
||||
lost = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
payloadPtr += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
} else {
|
||||
lost = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nBytes = nBytesPerPacket[ 0 ];
|
||||
payloadToDec = payload;
|
||||
}
|
||||
|
||||
/* Silk decoder */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
|
||||
if( lost == 0 ) {
|
||||
/* No Loss: Decode all frames in the packet */
|
||||
frames = 0;
|
||||
do {
|
||||
/* Decode 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
|
||||
}
|
||||
|
||||
frames++;
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
if( frames > MAX_INPUT_FRAMES ) {
|
||||
/* Hack for corrupt stream that could generate too many frames */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
frames = 0;
|
||||
}
|
||||
/* Until last 20 ms frame of packet has been decoded */
|
||||
} while( DecControl.internalDecoderFrames );
|
||||
} else {
|
||||
/* Loss: Decode enough frames to cover one packet duration */
|
||||
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
|
||||
/* Generate 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Decode returned %d", ret );
|
||||
}
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
}
|
||||
}
|
||||
totPackets++;
|
||||
|
||||
/* Write output to file */
|
||||
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
|
||||
|
||||
/* Update buffer */
|
||||
totBytes = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
totBytes += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
|
||||
payloadEnd -= nBytesPerPacket[ 0 ];
|
||||
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rFrames decoded: %d", totPackets );
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty the recieve buffer */
|
||||
for( k = 0; k < MAX_LBRR_DELAY; k++ ) {
|
||||
if( nBytesPerPacket[ 0 ] == 0 ) {
|
||||
/* Indicate lost packet */
|
||||
lost = 1;
|
||||
|
||||
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
|
||||
payloadPtr = payload;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
if( nBytesPerPacket[ i + 1 ] > 0 ) {
|
||||
SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
|
||||
if( nBytesFEC > 0 ) {
|
||||
payloadToDec = FECpayload;
|
||||
nBytes = nBytesFEC;
|
||||
lost = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
payloadPtr += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
} else {
|
||||
lost = 0;
|
||||
nBytes = nBytesPerPacket[ 0 ];
|
||||
payloadToDec = payload;
|
||||
}
|
||||
|
||||
/* Silk decoder */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
|
||||
if( lost == 0 ) {
|
||||
/* No loss: Decode all frames in the packet */
|
||||
frames = 0;
|
||||
do {
|
||||
/* Decode 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
|
||||
}
|
||||
|
||||
frames++;
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
if( frames > MAX_INPUT_FRAMES ) {
|
||||
/* Hack for corrupt stream that could generate too many frames */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
frames = 0;
|
||||
}
|
||||
/* Until last 20 ms frame of packet has been decoded */
|
||||
} while( DecControl.internalDecoderFrames );
|
||||
} else {
|
||||
/* Loss: Decode enough frames to cover one packet duration */
|
||||
|
||||
/* Generate 20 ms */
|
||||
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Decode returned %d", ret );
|
||||
}
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
}
|
||||
}
|
||||
totPackets++;
|
||||
|
||||
/* Write output to file */
|
||||
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
|
||||
|
||||
/* Update Buffer */
|
||||
totBytes = 0;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
totBytes += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
|
||||
payloadEnd -= nBytesPerPacket[ 0 ];
|
||||
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rPackets decoded: %d", totPackets );
|
||||
}
|
||||
}
|
||||
|
||||
if( !quiet ) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
printf( "\nDecoding Finished \n" );
|
||||
}
|
||||
|
||||
/* Free decoder */
|
||||
free( psDec );
|
||||
|
||||
/* Close files */
|
||||
fclose( speechOutFile );
|
||||
fclose( bitInFile );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
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.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. 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.
|
||||
***********************************************************************/
|
||||
|
||||
/*****************************/
|
||||
/* Silk decoder test program */
|
||||
/*****************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SKP_Silk_SDK_API.h"
|
||||
#include "SKP_Silk_SigProc_FIX.h"
|
||||
|
||||
/* Define codec specific settings should be moved to h file */
|
||||
#define MAX_BYTES_PER_FRAME 1024
|
||||
#define MAX_INPUT_FRAMES 5
|
||||
#define MAX_FRAME_LENGTH 480
|
||||
#define MAX_LBRR_DELAY 2
|
||||
|
||||
static void print_usage(char* argv[]) {
|
||||
printf( "\nusage: %s in.bit out.pcm [settings]\n", argv[ 0 ] );
|
||||
printf( "\nin.bit : Bitstream input to decoder" );
|
||||
printf( "\nout.pcm : Speech output from decoder" );
|
||||
printf( "\n settings:" );
|
||||
printf( "\n-fs <kHz> : Sampling rate of output signal in kHz; default: 24" );
|
||||
printf( "\n-loss <perc> : Simulated packet loss percentage (0-100); default: 0" );
|
||||
printf( "\n" );
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
size_t counter;
|
||||
SKP_int args, totPackets, i, k;
|
||||
SKP_int16 ret, len, tot_len;
|
||||
SKP_int16 nBytes;
|
||||
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES * ( MAX_LBRR_DELAY + 1 ) ];
|
||||
SKP_uint8 FECpayload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ], *payloadPtr;
|
||||
SKP_uint8 *payloadEnd = NULL, *payloadToDec = NULL;
|
||||
SKP_int16 nBytesFEC;
|
||||
SKP_int16 nBytesPerPacket[ MAX_LBRR_DELAY + 1 ], totBytes;
|
||||
SKP_int16 out[ ( MAX_FRAME_LENGTH << 1 ) * MAX_INPUT_FRAMES ], *outPtr;
|
||||
char speechOutFileName[ 150 ], bitInFileName[ 150 ];
|
||||
FILE *bitInFile, *speechOutFile;
|
||||
SKP_int Fs_kHz = 0;
|
||||
SKP_int32 decSizeBytes;
|
||||
void *psDec;
|
||||
float loss_prob;
|
||||
SKP_int frames, lost, quiet;
|
||||
SKP_SILK_SDK_DecControlStruct DecControl;
|
||||
|
||||
if( argc < 3 ) {
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* default settings */
|
||||
quiet = 0;
|
||||
loss_prob = 0.0f;
|
||||
|
||||
/* get arguments */
|
||||
args = 1;
|
||||
strcpy( bitInFileName, argv[ args ] );
|
||||
args++;
|
||||
strcpy( speechOutFileName, argv[ args ] );
|
||||
args++;
|
||||
while( args < argc ) {
|
||||
if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%f", &loss_prob );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &Fs_kHz );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
|
||||
quiet = 1;
|
||||
args++;
|
||||
} else {
|
||||
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if( !quiet ) {
|
||||
printf("******************* Silk Decoder v %s ****************\n", SKP_Silk_SDK_get_version());
|
||||
printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
|
||||
printf( "Input: %s\n", bitInFileName );
|
||||
printf( "Output: %s\n", speechOutFileName );
|
||||
}
|
||||
|
||||
/* Open files */
|
||||
bitInFile = fopen( bitInFileName, "rb" );
|
||||
if( bitInFile == NULL ) {
|
||||
printf( "Error: could not open input file %s\n", bitInFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
speechOutFile = fopen( speechOutFileName, "wb" );
|
||||
if( speechOutFile == NULL ) {
|
||||
printf( "Error: could not open output file %s\n", speechOutFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* Set the samplingrate that is requested for the output */
|
||||
if( Fs_kHz == 0 ) {
|
||||
DecControl.sampleRate = 24000;
|
||||
} else {
|
||||
DecControl.sampleRate = Fs_kHz * 1000;
|
||||
}
|
||||
|
||||
/* Create decoder */
|
||||
ret = SKP_Silk_SDK_Get_Decoder_Size( &decSizeBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Get_Decoder_Size returned %d", ret );
|
||||
}
|
||||
psDec = malloc( decSizeBytes );
|
||||
|
||||
/* Reset decoder */
|
||||
ret = SKP_Silk_SDK_InitDecoder( psDec );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_InitDecoder returned %d", ret );
|
||||
}
|
||||
|
||||
totPackets = 0;
|
||||
payloadEnd = payload;
|
||||
|
||||
/* Simulate the jitter buffer holding MAX_FEC_DELAY packets */
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
/* Read payload size */
|
||||
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
|
||||
/* Read payload */
|
||||
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
|
||||
|
||||
if( (SKP_int16)counter < nBytes ) {
|
||||
break;
|
||||
}
|
||||
nBytesPerPacket[ i ] = nBytes;
|
||||
payloadEnd += nBytes;
|
||||
}
|
||||
|
||||
while( 1 ) {
|
||||
/* Read payload size */
|
||||
counter = fread( &nBytes, sizeof( SKP_int16 ), 1, bitInFile );
|
||||
if( nBytes < 0 || counter < 1 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read payload */
|
||||
counter = fread( payloadEnd, sizeof( SKP_uint8 ), nBytes, bitInFile );
|
||||
if( (SKP_int16)counter < nBytes ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Simulate losses */
|
||||
if( ( (float)rand() / (float)RAND_MAX >= loss_prob / 100 ) && counter > 0 ) {
|
||||
nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;
|
||||
payloadEnd += nBytes;
|
||||
} else {
|
||||
nBytesPerPacket[ MAX_LBRR_DELAY ] = 0;
|
||||
}
|
||||
|
||||
if( nBytesPerPacket[ 0 ] == 0 ) {
|
||||
/* Indicate lost packet */
|
||||
lost = 1;
|
||||
|
||||
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
|
||||
payloadPtr = payload;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
if( nBytesPerPacket[ i + 1 ] > 0 ) {
|
||||
SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
|
||||
if( nBytesFEC > 0 ) {
|
||||
payloadToDec = FECpayload;
|
||||
nBytes = nBytesFEC;
|
||||
lost = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
payloadPtr += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
} else {
|
||||
lost = 0;
|
||||
nBytes = nBytesPerPacket[ 0 ];
|
||||
payloadToDec = payload;
|
||||
}
|
||||
|
||||
/* Silk decoder */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
|
||||
if( lost == 0 ) {
|
||||
/* No Loss: Decode all frames in the packet */
|
||||
frames = 0;
|
||||
do {
|
||||
/* Decode 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
|
||||
}
|
||||
|
||||
frames++;
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
if( frames > MAX_INPUT_FRAMES ) {
|
||||
/* Hack for corrupt stream that could generate too many frames */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
frames = 0;
|
||||
}
|
||||
/* Until last 20 ms frame of packet has been decoded */
|
||||
} while( DecControl.moreInternalDecoderFrames );
|
||||
} else {
|
||||
/* Loss: Decode enough frames to cover one packet duration */
|
||||
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
|
||||
/* Generate 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Decode returned %d", ret );
|
||||
}
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
}
|
||||
}
|
||||
totPackets++;
|
||||
|
||||
/* Write output to file */
|
||||
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
|
||||
|
||||
/* Update buffer */
|
||||
totBytes = 0;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
totBytes += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
|
||||
payloadEnd -= nBytesPerPacket[ 0 ];
|
||||
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rFrames decoded: %d", totPackets );
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty the recieve buffer */
|
||||
for( k = 0; k < MAX_LBRR_DELAY; k++ ) {
|
||||
if( nBytesPerPacket[ 0 ] == 0 ) {
|
||||
/* Indicate lost packet */
|
||||
lost = 1;
|
||||
|
||||
/* Packet loss. Search after FEC in next packets. Should be done in the jitter buffer */
|
||||
payloadPtr = payload;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
if( nBytesPerPacket[ i + 1 ] > 0 ) {
|
||||
SKP_Silk_SDK_search_for_LBRR( psDec, payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
|
||||
if( nBytesFEC > 0 ) {
|
||||
payloadToDec = FECpayload;
|
||||
nBytes = nBytesFEC;
|
||||
lost = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
payloadPtr += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
} else {
|
||||
lost = 0;
|
||||
nBytes = nBytesPerPacket[ 0 ];
|
||||
payloadToDec = payload;
|
||||
}
|
||||
|
||||
/* Silk decoder */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
|
||||
if( lost == 0 ) {
|
||||
/* No loss: Decode all frames in the packet */
|
||||
frames = 0;
|
||||
do {
|
||||
/* Decode 20 ms */
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
|
||||
}
|
||||
|
||||
frames++;
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
if( frames > MAX_INPUT_FRAMES ) {
|
||||
/* Hack for corrupt stream that could generate too many frames */
|
||||
outPtr = out;
|
||||
tot_len = 0;
|
||||
frames = 0;
|
||||
}
|
||||
/* Until last 20 ms frame of packet has been decoded */
|
||||
} while( DecControl.moreInternalDecoderFrames );
|
||||
} else {
|
||||
/* Loss: Decode enough frames to cover one packet duration */
|
||||
|
||||
/* Generate 20 ms */
|
||||
for( i = 0; i < DecControl.framesPerPacket; i++ ) {
|
||||
ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Decode returned %d", ret );
|
||||
}
|
||||
outPtr += len;
|
||||
tot_len += len;
|
||||
}
|
||||
}
|
||||
totPackets++;
|
||||
|
||||
/* Write output to file */
|
||||
fwrite( out, sizeof( SKP_int16 ), tot_len, speechOutFile );
|
||||
|
||||
/* Update Buffer */
|
||||
totBytes = 0;
|
||||
for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
|
||||
totBytes += nBytesPerPacket[ i + 1 ];
|
||||
}
|
||||
SKP_memmove( payload, &payload[ nBytesPerPacket[ 0 ] ], totBytes * sizeof( SKP_uint8 ) );
|
||||
payloadEnd -= nBytesPerPacket[ 0 ];
|
||||
SKP_memmove( nBytesPerPacket, &nBytesPerPacket[ 1 ], MAX_LBRR_DELAY * sizeof( SKP_int16 ) );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rPackets decoded: %d", totPackets );
|
||||
}
|
||||
}
|
||||
|
||||
if( !quiet ) {
|
||||
printf( "\nDecoding Finished \n" );
|
||||
}
|
||||
|
||||
/* Free decoder */
|
||||
free( psDec );
|
||||
|
||||
/* Close files */
|
||||
fclose( speechOutFile );
|
||||
fclose( bitInFile );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="Enc_SDK"
|
||||
ProjectGUID="{6D97A8EF-5724-4D85-8BF4-C583714BBA78}"
|
||||
RootNamespace="Enc"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)\Enc"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../interface"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)\Encoder_debug.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreAllDefaultLibraries="false"
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)_Enc"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../interface"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="0"
|
||||
FloatingPointModel="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/fixed:no"
|
||||
OutputFile="$(OutDir)\Encoder.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\Encoder.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="interface"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_control.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_errors.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_SDK_API.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\interface\SKP_Silk_typedef.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
+269
-308
@@ -1,308 +1,269 @@
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
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.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE.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.
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
/******************************************************/
|
||||
/* Silk encoder test program */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "SKP_Silk_SDK_API.h"
|
||||
|
||||
/* Define codec specific settings */
|
||||
#define MAX_BYTES_PER_FRAME 250 // Equals peak bitrate of 100 kbps
|
||||
#define MAX_INPUT_FRAMES 5
|
||||
#define MAX_LBRR_DELAY 2
|
||||
#define MAX_FRAME_LENGTH 480
|
||||
|
||||
static void print_usage( char* argv[] ) {
|
||||
printf( "\nusage: %s in.pcm out.bit [settings]\n", argv[ 0 ] );
|
||||
printf( "\nin.pcm : Speech input to encoder" );
|
||||
printf( "\nout.bit : Bitstream output from encoder" );
|
||||
printf( "\n settings:" );
|
||||
printf( "\n-fs <kHz> : Sampling rate in kHz, default: 24" );
|
||||
printf( "\n-packetlength <ms> : Packet interval in ms, default: 20" );
|
||||
printf( "\n-rate <bps> : Target bitrate; default: 25000" );
|
||||
printf( "\n-loss <perc> : Uplink loss estimate, in percent (0-100); default: 0" );
|
||||
printf( "\n-inbandFEC <flag> : Enable inband FEC usage (0/1); default: 0" );
|
||||
printf( "\n-complexity <comp> : Set complexity, 0: low, 1: medium, 2: high; default: 2" );
|
||||
printf( "\n-DTX <flag> : Enable DTX (0/1); default: 0" );
|
||||
printf( "\n-quiet : Print only some basic values" );
|
||||
printf( "\n");
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
size_t counter;
|
||||
SKP_int k, args, totPackets, totActPackets, ret;
|
||||
SKP_int16 nBytes;
|
||||
double sumBytes, sumWBytes, sumActBytes, avg_rate, act_rate, wght_rate, nrg;
|
||||
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
|
||||
SKP_int16 in[ MAX_FRAME_LENGTH * MAX_INPUT_FRAMES ];
|
||||
char speechInFileName[ 150 ], bitOutFileName[ 150 ];
|
||||
FILE *bitOutFile, *speechInFile;
|
||||
SKP_int32 encSizeBytes;
|
||||
void *psEnc;
|
||||
|
||||
/* default settings */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SKP_int fs_kHz = 24;
|
||||
SKP_int targetRate_bps = 25000;
|
||||
SKP_int packetSize_ms = 20;
|
||||
SKP_int frameSizeReadFromFile_ms = 20;
|
||||
SKP_int packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;
|
||||
SKP_int INBandFec_enabled = 0, DTX_enabled = 0, quiet = 0;
|
||||
SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder
|
||||
|
||||
if( argc < 3) {
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* get arguments */
|
||||
args = 1;
|
||||
strcpy( speechInFileName, argv[ args ] );
|
||||
args++;
|
||||
strcpy( bitOutFileName, argv[ args ] );
|
||||
args++;
|
||||
while( args < argc ) {
|
||||
if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &fs_kHz );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-packetlength" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &packetSize_ms );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-rate" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &targetRate_bps );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &packetLoss_perc );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-complexity" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &complexity_mode );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandFEC" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &INBandFec_enabled );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-DTX") == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &DTX_enabled );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
|
||||
quiet = 1;
|
||||
args++;
|
||||
} else {
|
||||
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Print options */
|
||||
if( !quiet ) {
|
||||
printf("******************* Silk Encoder v %s ****************\n", SKP_Silk_SDK_get_version());
|
||||
printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
|
||||
printf( "Input: %s\n", speechInFileName );
|
||||
printf( "Output: %s\n", bitOutFileName );
|
||||
printf( "Sampling rate: %d kHz\n", fs_kHz);
|
||||
printf( "Packet interval: %d ms\n", packetSize_ms);
|
||||
printf( "Inband FEC used: %d\n", INBandFec_enabled);
|
||||
printf( "DTX used: %d\n", DTX_enabled);
|
||||
printf( "Complexity: %d\n", complexity_mode);
|
||||
printf( "Target bitrate: %d bps\n", targetRate_bps);
|
||||
}
|
||||
|
||||
/* Open files */
|
||||
speechInFile = fopen( speechInFileName, "rb" );
|
||||
if( speechInFile == NULL ) {
|
||||
printf( "Error: could not open input file %s\n", speechInFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
bitOutFile = fopen( bitOutFileName, "wb" );
|
||||
if( bitOutFile == NULL ) {
|
||||
printf( "Error: could not open output file %s\n", bitOutFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* Create Encoder */
|
||||
ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_create_encoder returned %d", ret );
|
||||
}
|
||||
|
||||
psEnc = malloc( encSizeBytes );
|
||||
|
||||
/* Reset Encoder */
|
||||
ret = SKP_Silk_SDK_InitEncoder( psEnc, &encControl );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_reset_encoder returned %d", ret );
|
||||
}
|
||||
|
||||
/* Set Encoder parameters */
|
||||
encControl.sampleRate = fs_kHz * 1000;
|
||||
encControl.packetSize = packetSize_ms * fs_kHz;
|
||||
encControl.packetLossPercentage = packetLoss_perc;
|
||||
encControl.useInBandFec = INBandFec_enabled;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
encControl.useDtx = DTX_enabled;
|
||||
encControl.complexity = complexity_mode;
|
||||
encControl.bitRate = targetRate_bps;
|
||||
|
||||
if( fs_kHz > 24 || fs_kHz < 0 ) {
|
||||
printf( "\nError: Sampling rate = %d out of range, valid range 8 - 24 \n \n", fs_kHz );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
totPackets = 0;
|
||||
totActPackets = 0;
|
||||
smplsSinceLastPacket = 0;
|
||||
sumBytes = 0.0;
|
||||
sumActBytes = 0.0;
|
||||
sumWBytes = 0.0;
|
||||
|
||||
while( 1 ) {
|
||||
/* Read input to file */
|
||||
counter = fread( in, sizeof( SKP_int16 ), frameSizeReadFromFile_ms * fs_kHz, speechInFile );
|
||||
if( (SKP_int)counter < frameSizeReadFromFile_ms * fs_kHz ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* max payload size */
|
||||
nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
|
||||
|
||||
/* Silk Encoder */
|
||||
ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Encode returned %d", ret );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get packet size */
|
||||
packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate;
|
||||
|
||||
smplsSinceLastPacket += (SKP_int)counter;
|
||||
|
||||
if( ( smplsSinceLastPacket / fs_kHz ) == packetSize_ms ) {
|
||||
/* Sends a dummy zero size packet in case of DTX period */
|
||||
/* to make it work with the decoder test program. */
|
||||
/* In practice should be handled by RTP sequence numbers */
|
||||
totPackets++;
|
||||
sumBytes += nBytes;
|
||||
sumWBytes += pow( nBytes, 10.0 );
|
||||
nrg = 0.0;
|
||||
for( k = 0; k < (SKP_int)counter; k++ ) {
|
||||
nrg += in[ k ] * (double)in[ k ];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
if( ( nrg / (SKP_int)counter ) > 1e3 ) {
|
||||
sumActBytes += nBytes;
|
||||
totActPackets++;
|
||||
}
|
||||
|
||||
/* Write payload size */
|
||||
fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
|
||||
|
||||
/* Write payload */
|
||||
fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rPackets encoded: %d", totPackets );
|
||||
}
|
||||
smplsSinceLastPacket = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Write dummy because it can not end with 0 bytes */
|
||||
nBytes = -1;
|
||||
|
||||
/* Write payload size */
|
||||
fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
|
||||
|
||||
/* Query encoder */
|
||||
packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate;
|
||||
|
||||
/* Free Encoder */
|
||||
free( psEnc );
|
||||
|
||||
fclose( speechInFile );
|
||||
fclose( bitOutFile );
|
||||
|
||||
avg_rate = 8.0 / packetSize_ms * sumBytes / totPackets;
|
||||
act_rate = 8.0 / packetSize_ms * sumActBytes / totActPackets;
|
||||
wght_rate = 8.0 / packetSize_ms * pow( sumWBytes / totPackets, 0.1 );
|
||||
if( !quiet ) {
|
||||
printf( "\nAverage bitrate: %.3f kbps", avg_rate );
|
||||
printf( "\nActive bitrate: %.3f kbps", act_rate );
|
||||
printf( "\nWeighted bitrate: %.3f kbps", wght_rate );
|
||||
printf( "\n\n" );
|
||||
} else {
|
||||
/* print average and weighted bitrates */
|
||||
printf( "%.3f %.3f %.3f \n", avg_rate, act_rate, wght_rate );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
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.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. 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.
|
||||
***********************************************************************/
|
||||
|
||||
/*****************************/
|
||||
/* Silk encoder test program */
|
||||
/*****************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "SKP_Silk_SDK_API.h"
|
||||
|
||||
/* Define codec specific settings */
|
||||
#define MAX_BYTES_PER_FRAME 250 // Equals peak bitrate of 100 kbps
|
||||
#define MAX_INPUT_FRAMES 5
|
||||
#define MAX_LBRR_DELAY 2
|
||||
#define MAX_FRAME_LENGTH 480
|
||||
|
||||
static void print_usage( char* argv[] ) {
|
||||
printf( "\nusage: %s in.pcm out.bit [settings]\n", argv[ 0 ] );
|
||||
printf( "\nin.pcm : Speech input to encoder" );
|
||||
printf( "\nout.bit : Bitstream output from encoder" );
|
||||
printf( "\n settings:" );
|
||||
printf( "\n-fs <kHz> : Sampling rate in kHz, default: 24" );
|
||||
printf( "\n-packetlength <ms> : Packet interval in ms, default: 20" );
|
||||
printf( "\n-rate <bps> : Target bitrate; default: 25000" );
|
||||
printf( "\n-loss <perc> : Uplink loss estimate, in percent (0-100); default: 0" );
|
||||
printf( "\n-inbandFEC <flag> : Enable inband FEC usage (0/1); default: 0" );
|
||||
printf( "\n-complexity <comp> : Set complexity, 0: low, 1: medium, 2: high; default: 2" );
|
||||
printf( "\n-DTX <flag> : Enable DTX (0/1); default: 0" );
|
||||
printf( "\n-quiet : Print only some basic values" );
|
||||
printf( "\n");
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
size_t counter;
|
||||
SKP_int k, args, totPackets, totActPackets, ret;
|
||||
SKP_int16 nBytes;
|
||||
double sumBytes, sumWBytes, sumActBytes, avg_rate, act_rate, wght_rate, nrg;
|
||||
SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
|
||||
SKP_int16 in[ MAX_FRAME_LENGTH * MAX_INPUT_FRAMES ];
|
||||
char speechInFileName[ 150 ], bitOutFileName[ 150 ];
|
||||
FILE *bitOutFile, *speechInFile;
|
||||
SKP_int32 encSizeBytes;
|
||||
void *psEnc;
|
||||
|
||||
/* default settings */
|
||||
SKP_int fs_kHz = 24;
|
||||
SKP_int targetRate_bps = 25000;
|
||||
SKP_int packetSize_ms = 20;
|
||||
SKP_int frameSizeReadFromFile_ms = 20;
|
||||
SKP_int packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;
|
||||
SKP_int INBandFec_enabled = 0, DTX_enabled = 0, quiet = 0;
|
||||
SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder
|
||||
|
||||
if( argc < 3 ) {
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* get arguments */
|
||||
args = 1;
|
||||
strcpy( speechInFileName, argv[ args ] );
|
||||
args++;
|
||||
strcpy( bitOutFileName, argv[ args ] );
|
||||
args++;
|
||||
while( args < argc ) {
|
||||
if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-fs" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &fs_kHz );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-packetlength" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &packetSize_ms );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-rate" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &targetRate_bps );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-loss" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &packetLoss_perc );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-complexity" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &complexity_mode );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-inbandFEC" ) == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &INBandFec_enabled );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-DTX") == 0 ) {
|
||||
sscanf( argv[ args + 1 ], "%d", &DTX_enabled );
|
||||
args += 2;
|
||||
} else if( SKP_STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-quiet" ) == 0 ) {
|
||||
quiet = 1;
|
||||
args++;
|
||||
} else {
|
||||
printf( "Error: unrecognized setting: %s\n\n", argv[ args ] );
|
||||
print_usage( argv );
|
||||
exit( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/* Print options */
|
||||
if( !quiet ) {
|
||||
printf("******************* Silk Encoder v %s ****************\n", SKP_Silk_SDK_get_version());
|
||||
printf("******************* Compiled for %d bit cpu ********* \n", (int)sizeof(void*) * 8 );
|
||||
printf( "Input: %s\n", speechInFileName );
|
||||
printf( "Output: %s\n", bitOutFileName );
|
||||
printf( "Sampling rate: %d kHz\n", fs_kHz);
|
||||
printf( "Packet interval: %d ms\n", packetSize_ms);
|
||||
printf( "Inband FEC used: %d\n", INBandFec_enabled);
|
||||
printf( "DTX used: %d\n", DTX_enabled);
|
||||
printf( "Complexity: %d\n", complexity_mode);
|
||||
printf( "Target bitrate: %d bps\n", targetRate_bps);
|
||||
}
|
||||
|
||||
/* Open files */
|
||||
speechInFile = fopen( speechInFileName, "rb" );
|
||||
if( speechInFile == NULL ) {
|
||||
printf( "Error: could not open input file %s\n", speechInFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
bitOutFile = fopen( bitOutFileName, "wb" );
|
||||
if( bitOutFile == NULL ) {
|
||||
printf( "Error: could not open output file %s\n", bitOutFileName );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
/* Create Encoder */
|
||||
ret = SKP_Silk_SDK_Get_Encoder_Size( &encSizeBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_create_encoder returned %d", ret );
|
||||
}
|
||||
|
||||
psEnc = malloc( encSizeBytes );
|
||||
|
||||
/* Reset Encoder */
|
||||
ret = SKP_Silk_SDK_InitEncoder( psEnc, &encControl );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_reset_encoder returned %d", ret );
|
||||
}
|
||||
|
||||
/* Set Encoder parameters */
|
||||
encControl.sampleRate = fs_kHz * 1000;
|
||||
encControl.packetSize = packetSize_ms * fs_kHz;
|
||||
encControl.packetLossPercentage = packetLoss_perc;
|
||||
encControl.useInBandFEC = INBandFec_enabled;
|
||||
encControl.useDTX = DTX_enabled;
|
||||
encControl.complexity = complexity_mode;
|
||||
encControl.bitRate = targetRate_bps;
|
||||
|
||||
if( fs_kHz > 24 || fs_kHz < 0 ) {
|
||||
printf( "\nError: Sampling rate = %d out of range, valid range 8 - 24 \n \n", fs_kHz );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
totPackets = 0;
|
||||
totActPackets = 0;
|
||||
smplsSinceLastPacket = 0;
|
||||
sumBytes = 0.0;
|
||||
sumActBytes = 0.0;
|
||||
sumWBytes = 0.0;
|
||||
|
||||
while( 1 ) {
|
||||
/* Read input to file */
|
||||
counter = fread( in, sizeof( SKP_int16 ), frameSizeReadFromFile_ms * fs_kHz, speechInFile );
|
||||
if( (SKP_int)counter < frameSizeReadFromFile_ms * fs_kHz ) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* max payload size */
|
||||
nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
|
||||
|
||||
/* Silk Encoder */
|
||||
ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );
|
||||
if( ret ) {
|
||||
printf( "\nSKP_Silk_Encode returned %d", ret );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get packet size */
|
||||
packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate;
|
||||
|
||||
smplsSinceLastPacket += (SKP_int)counter;
|
||||
|
||||
if( ( smplsSinceLastPacket / fs_kHz ) == packetSize_ms ) {
|
||||
/* Sends a dummy zero size packet in case of DTX period */
|
||||
/* to make it work with the decoder test program. */
|
||||
/* In practice should be handled by RTP sequence numbers */
|
||||
totPackets++;
|
||||
sumBytes += nBytes;
|
||||
sumWBytes += pow( (double)nBytes, 10.0 );
|
||||
nrg = 0.0;
|
||||
for( k = 0; k < (SKP_int)counter; k++ ) {
|
||||
nrg += in[ k ] * (double)in[ k ];
|
||||
}
|
||||
if( ( nrg / (SKP_int)counter ) > 1e3 ) {
|
||||
sumActBytes += nBytes;
|
||||
totActPackets++;
|
||||
}
|
||||
|
||||
/* Write payload size */
|
||||
fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
|
||||
|
||||
/* Write payload */
|
||||
fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );
|
||||
|
||||
if( !quiet ) {
|
||||
fprintf( stderr, "\rPackets encoded: %d", totPackets );
|
||||
}
|
||||
smplsSinceLastPacket = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Write dummy because it can not end with 0 bytes */
|
||||
nBytes = -1;
|
||||
|
||||
/* Write payload size */
|
||||
fwrite( &nBytes, sizeof( SKP_int16 ), 1, bitOutFile );
|
||||
|
||||
/* Query encoder */
|
||||
packetSize_ms = (SKP_int)( 1000 * encControl.packetSize ) / encControl.sampleRate;
|
||||
|
||||
/* Free Encoder */
|
||||
free( psEnc );
|
||||
|
||||
fclose( speechInFile );
|
||||
fclose( bitOutFile );
|
||||
|
||||
avg_rate = 8.0 / packetSize_ms * sumBytes / totPackets;
|
||||
act_rate = 8.0 / packetSize_ms * sumActBytes / totActPackets;
|
||||
wght_rate = 8.0 / packetSize_ms * pow( sumWBytes / totPackets, 0.1 );
|
||||
if( !quiet ) {
|
||||
printf( "\nAverage bitrate: %.3f kbps", avg_rate );
|
||||
printf( "\nActive bitrate: %.3f kbps", act_rate );
|
||||
printf( "\nWeighted bitrate: %.3f kbps", wght_rate );
|
||||
printf( "\n\n" );
|
||||
} else {
|
||||
/* print average and weighted bitrates */
|
||||
printf( "%.3f %.3f %.3f \n", avg_rate, act_rate, wght_rate );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="SignalCompare"
|
||||
ProjectGUID="{7FE8F544-9175-40C3-A187-7F15CE9A75D8}"
|
||||
RootNamespace="Test"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)_SigCmp"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\interface;..\src"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="SignalCompare_debug.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreAllDefaultLibraries="false"
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="$(TargetDir)$(TargetName).pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)"
|
||||
IntermediateDirectory="$(ConfigurationName)_SigCmp"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="..\interface;..\src"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="0"
|
||||
FloatingPointModel="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/fixed:no"
|
||||
OutputFile="$(SolutionDir)SignalCompare.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""
|
||||
IgnoreDefaultLibraryNames=""
|
||||
GenerateDebugInformation="false"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\signalCompare.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@@ -0,0 +1,366 @@
|
||||
/***********************************************************************
|
||||
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, (subject to the limitations in the disclaimer below)
|
||||
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.
|
||||
- Neither the name of Skype Limited, nor the names of specific
|
||||
contributors, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
|
||||
BY THIS LICENSE. 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.
|
||||
***********************************************************************/
|
||||
|
||||
/*
|
||||
* Compare two audio signals and compute weighted SNR difference
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SKP_Silk_SigProc_FIX.h"
|
||||
|
||||
#define FRAME_LENGTH_MS 10
|
||||
#define WIN_LENGTH_MS 20
|
||||
#define BW_EXPANSION 0.7f
|
||||
|
||||
#define MAX_FS_KHZ 24
|
||||
#define LPC_ORDER 10
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* Internally used functions */
|
||||
void Autocorrelation(
|
||||
SKP_float *results, /* o result (length correlationCount) */
|
||||
const SKP_float *inputData, /* i input data to correlate */
|
||||
SKP_int inputDataSize, /* i length of input */
|
||||
SKP_int correlationCount /* i number of correlation taps to compute */
|
||||
);
|
||||
|
||||
/* inner product of two SKP_float arrays, with result as double */
|
||||
double Inner_product(
|
||||
const SKP_float *data1,
|
||||
const SKP_float *data2,
|
||||
SKP_int dataSize
|
||||
);
|
||||
/* Solve the normal equations using the Levinson-Durbin recursion */
|
||||
SKP_float Levinsondurbin( /* O prediction error energy */
|
||||
SKP_float A[], /* O prediction coefficients [order] */
|
||||
const SKP_float corr[], /* I input auto-correlations [order + 1] */
|
||||
const SKP_int order /* I prediction order */
|
||||
);
|
||||
|
||||
/* Chirp (bw expand) LP AR filter */
|
||||
void Bwexpander(
|
||||
SKP_float *ar, /* io AR filter to be expanded (without leading 1) */
|
||||
const SKP_int d, /* i length of ar */
|
||||
const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static void print_usage(char* argv[]) {
|
||||
printf("\nusage: %s ref.pcm test.pcm [settings]\n", argv[ 0 ]);
|
||||
printf("\nref.pcm : Reference file");
|
||||
printf("\ntest.pcm : File to be tested, should be of same length as ref.pcm");
|
||||
printf("\n settings:");
|
||||
printf("\n-diff : Only determine bit-exactness");
|
||||
printf("\n-fs <kHz> : Sampling rate in kHz, max: %d; default: 24", MAX_FS_KHZ);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
SKP_int args, n, i, counterRef, counterTest;
|
||||
char testInFileName[150], refInFileName[150];
|
||||
FILE *refInFile, *testInFile;
|
||||
SKP_int nFrames = 0, isUnequal = 0;
|
||||
SKP_int diff = 0, Fs_kHz = 24; /* defaults */
|
||||
SKP_float c, refWhtnd, testWhtnd, refNrg, diffNrg;
|
||||
double SNR = 0.0;
|
||||
SKP_int16 refIn[WIN_LENGTH_MS * MAX_FS_KHZ], testIn[WIN_LENGTH_MS * MAX_FS_KHZ];
|
||||
SKP_float refWin[WIN_LENGTH_MS * MAX_FS_KHZ], testWin[WIN_LENGTH_MS * MAX_FS_KHZ];
|
||||
SKP_float autoCorr[LPC_ORDER + 1], LPC_Coef[LPC_ORDER];
|
||||
|
||||
if (argc < 3) {
|
||||
print_usage(argv);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* get arguments */
|
||||
args = 1;
|
||||
strcpy(refInFileName, argv[args]);
|
||||
args++;
|
||||
strcpy(testInFileName, argv[args]);
|
||||
args++;
|
||||
while(args < argc ) {
|
||||
if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-diff") == 0) {
|
||||
diff = 1;
|
||||
args++;
|
||||
}else if (SKP_STR_CASEINSENSITIVE_COMPARE(argv[args], "-fs") == 0) {
|
||||
sscanf(argv[args+1], "%d", &Fs_kHz);
|
||||
args += 2;
|
||||
} else {
|
||||
printf("Error: unrecognized setting: %s\n\n", argv[args]);
|
||||
print_usage(argv);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if( Fs_kHz > MAX_FS_KHZ ) {
|
||||
printf("Error: sampling rate too high: %d\n\n", Fs_kHz);
|
||||
print_usage(argv);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("Reference: %s\n", refInFileName);
|
||||
//printf("Test: %s\n", testInFileName);
|
||||
|
||||
/* open files */
|
||||
refInFile = fopen(refInFileName, "rb");
|
||||
if (refInFile==NULL) {
|
||||
printf("Error: could not open input file %s\n", refInFileName);
|
||||
exit(0);
|
||||
}
|
||||
testInFile = fopen(testInFileName, "rb");
|
||||
if (testInFile==NULL) {
|
||||
printf("Error: could not open input file %s\n", testInFileName);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
SKP_memset( refIn, 0, sizeof(refIn) );
|
||||
SKP_memset( testIn, 0, sizeof(testIn) );
|
||||
|
||||
while(1) {
|
||||
/* Read inputs */
|
||||
counterRef = (SKP_int)fread(&refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz],
|
||||
sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, refInFile);
|
||||
counterTest = (SKP_int)fread(&testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz],
|
||||
sizeof(SKP_int16), FRAME_LENGTH_MS * Fs_kHz, testInFile);
|
||||
if(counterRef != FRAME_LENGTH_MS * Fs_kHz || counterTest != FRAME_LENGTH_MS * Fs_kHz){
|
||||
break;
|
||||
}
|
||||
|
||||
/* test for bit-exactness */
|
||||
for( n = 0; n < FRAME_LENGTH_MS * Fs_kHz; n++ ) {
|
||||
if( refIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] !=
|
||||
testIn[(WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz + n] ) {
|
||||
isUnequal = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* apply sine window */
|
||||
for( n = 0; n < WIN_LENGTH_MS * Fs_kHz; n++ ) {
|
||||
c = (SKP_float)sin( 3.14159265 * (n + 1) / (WIN_LENGTH_MS * Fs_kHz + 1) );
|
||||
refWin[n] = refIn[n] * c;
|
||||
testWin[n] = testIn[n] * c;
|
||||
}
|
||||
|
||||
/* LPC analysis on reference signal */
|
||||
|
||||
/* Calculate auto correlation */
|
||||
Autocorrelation(autoCorr, refWin, WIN_LENGTH_MS * Fs_kHz, LPC_ORDER + 1);
|
||||
|
||||
/* Add white noise */
|
||||
autoCorr[ 0 ] += autoCorr[ 0 ] * 1e-6f + 1.0f;
|
||||
|
||||
/* Convert correlations to prediction coefficients */
|
||||
Levinsondurbin(LPC_Coef, autoCorr, LPC_ORDER);
|
||||
|
||||
/* Bandwdith expansion */
|
||||
Bwexpander(LPC_Coef, LPC_ORDER, BW_EXPANSION);
|
||||
|
||||
/* Filter both signals */
|
||||
refNrg = 1.0f;
|
||||
diffNrg = 1e-10f;
|
||||
for( n = (WIN_LENGTH_MS - FRAME_LENGTH_MS) / 2 * Fs_kHz;
|
||||
n < (WIN_LENGTH_MS + FRAME_LENGTH_MS) / 2 * Fs_kHz; n++ ) {
|
||||
refWhtnd = refIn[n];
|
||||
testWhtnd = testIn[n];
|
||||
for( i = 0; i < LPC_ORDER; i++ ) {
|
||||
refWhtnd -= LPC_Coef[ i ] * refIn[n - i - 1];
|
||||
testWhtnd -= LPC_Coef[ i ] * testIn[n - i - 1];
|
||||
}
|
||||
refNrg += refWhtnd * refWhtnd;
|
||||
diffNrg += (refWhtnd - testWhtnd) * (refWhtnd - testWhtnd);
|
||||
}
|
||||
|
||||
/* weighted SNR */
|
||||
if( refNrg > FRAME_LENGTH_MS * Fs_kHz ) {
|
||||
SNR += 10.0 * log10( refNrg / diffNrg );
|
||||
nFrames++;
|
||||
}
|
||||
|
||||
/* Update Buffer */
|
||||
SKP_memmove( refIn, &refIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));
|
||||
SKP_memmove( testIn, &testIn[FRAME_LENGTH_MS * Fs_kHz], (WIN_LENGTH_MS - FRAME_LENGTH_MS) * Fs_kHz * sizeof(SKP_int16));
|
||||
}
|
||||
|
||||
if( diff ) {
|
||||
if( isUnequal ) {
|
||||
printf("Signals DIFFER\n");
|
||||
} else {
|
||||
if(counterRef != counterTest){
|
||||
printf("Warning: signals differ in length\n");
|
||||
}
|
||||
printf("Signals BIT-EXACT\n");
|
||||
}
|
||||
} else {
|
||||
if( nFrames == 0 ) {
|
||||
printf("At least one signal too short or not loud enough\n");
|
||||
exit(0);
|
||||
}
|
||||
if(counterRef != counterTest){
|
||||
printf("Warning: signals differ in length\n");
|
||||
}
|
||||
if( isUnequal == 0 ) {
|
||||
printf("Signals BIT-EXACT\n");
|
||||
} else {
|
||||
printf("AVERAGE WEIGHTED SNR: %4.1f dB\n", SNR / nFrames);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/* Close Files */
|
||||
fclose(refInFile);
|
||||
fclose(testInFile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* compute autocorrelation */
|
||||
void Autocorrelation(
|
||||
SKP_float *results, /* o result (length correlationCount) */
|
||||
const SKP_float *inputData, /* i input data to correlate */
|
||||
SKP_int inputDataSize, /* i length of input */
|
||||
SKP_int correlationCount /* i number of correlation taps to compute */
|
||||
)
|
||||
{
|
||||
SKP_int i;
|
||||
|
||||
if (correlationCount > inputDataSize) {
|
||||
correlationCount = inputDataSize;
|
||||
}
|
||||
|
||||
for( i = 0; i < correlationCount; i++ ) {
|
||||
results[ i ] = (SKP_float)Inner_product( inputData, inputData + i, inputDataSize - i );
|
||||
}
|
||||
}
|
||||
|
||||
/* inner product of two SKP_float arrays, with result as double */
|
||||
double Inner_product(
|
||||
const SKP_float *data1,
|
||||
const SKP_float *data2,
|
||||
SKP_int dataSize
|
||||
)
|
||||
{
|
||||
SKP_int i, dataSize4;
|
||||
double result;
|
||||
|
||||
/* 4x unrolled loop */
|
||||
result = 0.0f;
|
||||
dataSize4 = dataSize & 0xFFFC;
|
||||
for( i = 0; i < dataSize4; i += 4 ) {
|
||||
result += data1[ i + 0 ] * data2[ i + 0 ] +
|
||||
data1[ i + 1 ] * data2[ i + 1 ] +
|
||||
data1[ i + 2 ] * data2[ i + 2 ] +
|
||||
data1[ i + 3 ] * data2[ i + 3 ];
|
||||
}
|
||||
|
||||
/* add any remaining products */
|
||||
for( ; i < dataSize; i++ ) {
|
||||
result += data1[ i ] * data2[ i ];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Solve the normal equations using the Levinson-Durbin recursion */
|
||||
SKP_float Levinsondurbin( /* O prediction error energy */
|
||||
SKP_float A[], /* O prediction coefficients [order] */
|
||||
const SKP_float corr[], /* I input auto-correlations [order + 1] */
|
||||
const SKP_int order /* I prediction order */
|
||||
)
|
||||
{
|
||||
SKP_int i, mHalf, m;
|
||||
SKP_float min_nrg, nrg, t, km, Atmp1, Atmp2;
|
||||
|
||||
min_nrg = 1e-12f * corr[ 0 ] + 1e-9f;
|
||||
nrg = corr[ 0 ];
|
||||
nrg = SKP_max(min_nrg, nrg);
|
||||
A[ 0 ] = corr[ 1 ] / nrg;
|
||||
nrg -= A[ 0 ] * corr[ 1 ];
|
||||
nrg = SKP_max(min_nrg, nrg);
|
||||
|
||||
for( m = 1; m < order; m++ )
|
||||
{
|
||||
t = corr[ m + 1 ];
|
||||
for( i = 0; i < m; i++ ) {
|
||||
t -= A[ i ] * corr[ m - i ];
|
||||
}
|
||||
|
||||
/* reflection coefficient */
|
||||
km = t / nrg;
|
||||
|
||||
/* residual energy */
|
||||
nrg -= km * t;
|
||||
nrg = SKP_max(min_nrg, nrg);
|
||||
|
||||
mHalf = m >> 1;
|
||||
for( i = 0; i < mHalf; i++ ) {
|
||||
Atmp1 = A[ i ];
|
||||
Atmp2 = A[ m - i - 1 ];
|
||||
A[ m - i - 1 ] -= km * Atmp1;
|
||||
A[ i ] -= km * Atmp2;
|
||||
}
|
||||
if( m & 1 ) {
|
||||
A[ mHalf ] -= km * A[ mHalf ];
|
||||
}
|
||||
A[ m ] = km;
|
||||
}
|
||||
|
||||
/* return the residual energy */
|
||||
return nrg;
|
||||
}
|
||||
|
||||
/* Chirp (bw expand) LP AR filter */
|
||||
void Bwexpander(
|
||||
SKP_float *ar, /* io AR filter to be expanded (without leading 1) */
|
||||
const SKP_int d, /* i length of ar */
|
||||
const SKP_float chirp /* i chirp factor (typically in range (0..1) ) */
|
||||
)
|
||||
{
|
||||
SKP_int i;
|
||||
SKP_float cfac = chirp;
|
||||
|
||||
for( i = 0; i < d - 1; i++ ) {
|
||||
ar[ i ] *= cfac;
|
||||
cfac *= chirp;
|
||||
}
|
||||
ar[ d - 1 ] *= cfac;
|
||||
}
|
||||
Reference in new issue
Block a user