mirror of
https://github.com/Q3Rally-Team/q3rally.git
synced 2024-12-02 00:11:58 +00:00
0d5fb492cd
Fix GCC 6 misleading-indentation warning add SECURITY.md OpenGL2: Restore adding fixed ambient light when HDR is enabled Few LCC memory fixes. fix a few potential buffer overwrite in Game VM Enable compiler optimization on all macOS architectures Don't allow qagame module to create "botlib.log" at ANY filesystem location Make FS_BuildOSPath for botlib.log consistent with typical usage tiny readme thing Remove extra plus sign from Huff_Compress() Fix VMs being able to change CVAR_PROTECTED cvars Don't register fs_game cvar everywhere just to get the value Don't let VMs change engine latch cvars immediately Fix fs_game '..' reading outside of home and base path Fix VMs forcing engine latch cvar to update to latched value Revert my recent cvar latch changes Revert "Don't let VMs change engine latch cvars immediately" Partially revert "Fix fs_game '..' reading outside of home and base path" Revert "Fix VMs forcing engine latch cvar to update to latched value" Fix exploit to bypass filename restrictions on Windows Changes to systemd q3a.service Fix Q_vsnprintf for mingw-w64 Fix timelimit causing an infinite map ending loop Fix invalid access to cluster 0 in AAS_AreaRouteToGoalArea() Fix negative frag/capturelimit causing an infinite map end loop OpenGL2: Fix dark lightmap on shader in mpteam6 Make FS_InvalidGameDir() consider subdirectories invalid [qcommon] Remove dead serialization code [qcommon] Make several zone variables and functions static. Fix MAC_OS_X_VERSION_MIN_REQUIRED for macOS 10.10 and later Increase q3_ui .arena filename list buffer size to 4096 bytes OpenGL2: Fix crash when BSP has deluxe maps and vertex lit surfaces Support Unicode characters greater than 0xFF in cl_consoleKeys Fix macOS app bundle with space in name OpenGL1: Use glGenTextures instead of hardcoded values Remove CON_FlushIn function and where STDIN needs flushing, use tcflush POSIX function Update libogg from 1.3.2 to 1.3.3 Rename (already updated) libogg-1.3.2 to libogg-1.3.3 Update libvorbis from 1.3.5 to 1.3.6 * Fix CVE-2018-5146 - out-of-bounds write on codebook decoding. * Fix CVE-2017-14632 - free() on unitialized data * Fix CVE-2017-14633 - out-of-bounds read Rename (already updated) libvorbis-1.3.5 to libvorbis-1.3.6 Update opus from 1.1.4 to 1.2.1 Rename (already updated) opus-1.1.4 to opus-1.2.1 Update opusfile from 0.8 to 0.9 Rename (already updated) opusfile-0.8 to opusfile-0.9 First swing at a CONTRIBUTING.md Allow loading system OpenAL library on macOS again Remove duplicate setting of FREETYPE_CFLAGS in Makefile Fix exploit to reset player by sending wrong serverId Fix "Going to CS_ZOMBIE for [clientname]" developer message Fix MSG_Read*String*() functions not being able to read last byte from message
215 lines
9.7 KiB
C
215 lines
9.7 KiB
C
/***********************************************************************
|
|
Copyright (c) 2006-2011, Skype Limited. All rights reserved.
|
|
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.
|
|
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
|
names of specific contributors, may be used to endorse or promote
|
|
products derived from this software without specific prior written
|
|
permission.
|
|
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
|
|
|
|
/*
|
|
* Matrix of resampling methods used:
|
|
* Fs_out (kHz)
|
|
* 8 12 16 24 48
|
|
*
|
|
* 8 C UF U UF UF
|
|
* 12 AF C UF U UF
|
|
* Fs_in (kHz) 16 D AF C UF UF
|
|
* 24 AF D AF C U
|
|
* 48 AF AF AF D C
|
|
*
|
|
* C -> Copy (no resampling)
|
|
* D -> Allpass-based 2x downsampling
|
|
* U -> Allpass-based 2x upsampling
|
|
* UF -> Allpass-based 2x upsampling followed by FIR interpolation
|
|
* AF -> AR2 filter followed by FIR interpolation
|
|
*/
|
|
|
|
#include "resampler_private.h"
|
|
|
|
/* Tables with delay compensation values to equalize total delay for different modes */
|
|
static const opus_int8 delay_matrix_enc[ 5 ][ 3 ] = {
|
|
/* in \ out 8 12 16 */
|
|
/* 8 */ { 6, 0, 3 },
|
|
/* 12 */ { 0, 7, 3 },
|
|
/* 16 */ { 0, 1, 10 },
|
|
/* 24 */ { 0, 2, 6 },
|
|
/* 48 */ { 18, 10, 12 }
|
|
};
|
|
|
|
static const opus_int8 delay_matrix_dec[ 3 ][ 5 ] = {
|
|
/* in \ out 8 12 16 24 48 */
|
|
/* 8 */ { 4, 0, 2, 0, 0 },
|
|
/* 12 */ { 0, 9, 4, 7, 4 },
|
|
/* 16 */ { 0, 3, 12, 7, 7 }
|
|
};
|
|
|
|
/* Simple way to make [8000, 12000, 16000, 24000, 48000] to [0, 1, 2, 3, 4] */
|
|
#define rateID(R) ( ( ( ((R)>>12) - ((R)>16000) ) >> ((R)>24000) ) - 1 )
|
|
|
|
#define USE_silk_resampler_copy (0)
|
|
#define USE_silk_resampler_private_up2_HQ_wrapper (1)
|
|
#define USE_silk_resampler_private_IIR_FIR (2)
|
|
#define USE_silk_resampler_private_down_FIR (3)
|
|
|
|
/* Initialize/reset the resampler state for a given pair of input/output sampling rates */
|
|
opus_int silk_resampler_init(
|
|
silk_resampler_state_struct *S, /* I/O Resampler state */
|
|
opus_int32 Fs_Hz_in, /* I Input sampling rate (Hz) */
|
|
opus_int32 Fs_Hz_out, /* I Output sampling rate (Hz) */
|
|
opus_int forEnc /* I If 1: encoder; if 0: decoder */
|
|
)
|
|
{
|
|
opus_int up2x;
|
|
|
|
/* Clear state */
|
|
silk_memset( S, 0, sizeof( silk_resampler_state_struct ) );
|
|
|
|
/* Input checking */
|
|
if( forEnc ) {
|
|
if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 && Fs_Hz_in != 24000 && Fs_Hz_in != 48000 ) ||
|
|
( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 ) ) {
|
|
silk_assert( 0 );
|
|
return -1;
|
|
}
|
|
S->inputDelay = delay_matrix_enc[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
|
|
} else {
|
|
if( ( Fs_Hz_in != 8000 && Fs_Hz_in != 12000 && Fs_Hz_in != 16000 ) ||
|
|
( Fs_Hz_out != 8000 && Fs_Hz_out != 12000 && Fs_Hz_out != 16000 && Fs_Hz_out != 24000 && Fs_Hz_out != 48000 ) ) {
|
|
silk_assert( 0 );
|
|
return -1;
|
|
}
|
|
S->inputDelay = delay_matrix_dec[ rateID( Fs_Hz_in ) ][ rateID( Fs_Hz_out ) ];
|
|
}
|
|
|
|
S->Fs_in_kHz = silk_DIV32_16( Fs_Hz_in, 1000 );
|
|
S->Fs_out_kHz = silk_DIV32_16( Fs_Hz_out, 1000 );
|
|
|
|
/* Number of samples processed per batch */
|
|
S->batchSize = S->Fs_in_kHz * RESAMPLER_MAX_BATCH_SIZE_MS;
|
|
|
|
/* Find resampler with the right sampling ratio */
|
|
up2x = 0;
|
|
if( Fs_Hz_out > Fs_Hz_in ) {
|
|
/* Upsample */
|
|
if( Fs_Hz_out == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 1 */
|
|
/* Special case: directly use 2x upsampler */
|
|
S->resampler_function = USE_silk_resampler_private_up2_HQ_wrapper;
|
|
} else {
|
|
/* Default resampler */
|
|
S->resampler_function = USE_silk_resampler_private_IIR_FIR;
|
|
up2x = 1;
|
|
}
|
|
} else if ( Fs_Hz_out < Fs_Hz_in ) {
|
|
/* Downsample */
|
|
S->resampler_function = USE_silk_resampler_private_down_FIR;
|
|
if( silk_MUL( Fs_Hz_out, 4 ) == silk_MUL( Fs_Hz_in, 3 ) ) { /* Fs_out : Fs_in = 3 : 4 */
|
|
S->FIR_Fracs = 3;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
|
|
S->Coefs = silk_Resampler_3_4_COEFS;
|
|
} else if( silk_MUL( Fs_Hz_out, 3 ) == silk_MUL( Fs_Hz_in, 2 ) ) { /* Fs_out : Fs_in = 2 : 3 */
|
|
S->FIR_Fracs = 2;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR0;
|
|
S->Coefs = silk_Resampler_2_3_COEFS;
|
|
} else if( silk_MUL( Fs_Hz_out, 2 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 2 */
|
|
S->FIR_Fracs = 1;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR1;
|
|
S->Coefs = silk_Resampler_1_2_COEFS;
|
|
} else if( silk_MUL( Fs_Hz_out, 3 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 3 */
|
|
S->FIR_Fracs = 1;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
|
|
S->Coefs = silk_Resampler_1_3_COEFS;
|
|
} else if( silk_MUL( Fs_Hz_out, 4 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 4 */
|
|
S->FIR_Fracs = 1;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
|
|
S->Coefs = silk_Resampler_1_4_COEFS;
|
|
} else if( silk_MUL( Fs_Hz_out, 6 ) == Fs_Hz_in ) { /* Fs_out : Fs_in = 1 : 6 */
|
|
S->FIR_Fracs = 1;
|
|
S->FIR_Order = RESAMPLER_DOWN_ORDER_FIR2;
|
|
S->Coefs = silk_Resampler_1_6_COEFS;
|
|
} else {
|
|
/* None available */
|
|
silk_assert( 0 );
|
|
return -1;
|
|
}
|
|
} else {
|
|
/* Input and output sampling rates are equal: copy */
|
|
S->resampler_function = USE_silk_resampler_copy;
|
|
}
|
|
|
|
/* Ratio of input/output samples */
|
|
S->invRatio_Q16 = silk_LSHIFT32( silk_DIV32( silk_LSHIFT32( Fs_Hz_in, 14 + up2x ), Fs_Hz_out ), 2 );
|
|
/* Make sure the ratio is rounded up */
|
|
while( silk_SMULWW( S->invRatio_Q16, Fs_Hz_out ) < silk_LSHIFT32( Fs_Hz_in, up2x ) ) {
|
|
S->invRatio_Q16++;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Resampler: convert from one sampling rate to another */
|
|
/* Input and output sampling rate are at most 48000 Hz */
|
|
opus_int silk_resampler(
|
|
silk_resampler_state_struct *S, /* I/O Resampler state */
|
|
opus_int16 out[], /* O Output signal */
|
|
const opus_int16 in[], /* I Input signal */
|
|
opus_int32 inLen /* I Number of input samples */
|
|
)
|
|
{
|
|
opus_int nSamples;
|
|
|
|
/* Need at least 1 ms of input data */
|
|
silk_assert( inLen >= S->Fs_in_kHz );
|
|
/* Delay can't exceed the 1 ms of buffering */
|
|
silk_assert( S->inputDelay <= S->Fs_in_kHz );
|
|
|
|
nSamples = S->Fs_in_kHz - S->inputDelay;
|
|
|
|
/* Copy to delay buffer */
|
|
silk_memcpy( &S->delayBuf[ S->inputDelay ], in, nSamples * sizeof( opus_int16 ) );
|
|
|
|
switch( S->resampler_function ) {
|
|
case USE_silk_resampler_private_up2_HQ_wrapper:
|
|
silk_resampler_private_up2_HQ_wrapper( S, out, S->delayBuf, S->Fs_in_kHz );
|
|
silk_resampler_private_up2_HQ_wrapper( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
|
|
break;
|
|
case USE_silk_resampler_private_IIR_FIR:
|
|
silk_resampler_private_IIR_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
|
|
silk_resampler_private_IIR_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
|
|
break;
|
|
case USE_silk_resampler_private_down_FIR:
|
|
silk_resampler_private_down_FIR( S, out, S->delayBuf, S->Fs_in_kHz );
|
|
silk_resampler_private_down_FIR( S, &out[ S->Fs_out_kHz ], &in[ nSamples ], inLen - S->Fs_in_kHz );
|
|
break;
|
|
default:
|
|
silk_memcpy( out, S->delayBuf, S->Fs_in_kHz * sizeof( opus_int16 ) );
|
|
silk_memcpy( &out[ S->Fs_out_kHz ], &in[ nSamples ], ( inLen - S->Fs_in_kHz ) * sizeof( opus_int16 ) );
|
|
}
|
|
|
|
/* Copy to delay buffer */
|
|
silk_memcpy( S->delayBuf, &in[ inLen - S->inputDelay ], S->inputDelay * sizeof( opus_int16 ) );
|
|
|
|
return 0;
|
|
}
|