mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-12 13:21:51 +00:00
040cb17370
# Conflicts: # CMakeLists.txt # libraries/glslang/OGLCompilersDLL/CMakeLists.txt # libraries/glslang/OGLCompilersDLL/InitializeDll.cpp # libraries/glslang/OGLCompilersDLL/InitializeDll.h # libraries/glslang/glslang/CMakeLists.txt # libraries/glslang/glslang/GenericCodeGen/CodeGen.cpp # libraries/glslang/glslang/GenericCodeGen/Link.cpp # libraries/glslang/glslang/Include/BaseTypes.h # libraries/glslang/glslang/Include/Common.h # libraries/glslang/glslang/Include/ConstantUnion.h # libraries/glslang/glslang/Include/InfoSink.h # libraries/glslang/glslang/Include/InitializeGlobals.h # libraries/glslang/glslang/Include/PoolAlloc.h # libraries/glslang/glslang/Include/ResourceLimits.h # libraries/glslang/glslang/Include/ShHandle.h # libraries/glslang/glslang/Include/Types.h # libraries/glslang/glslang/Include/arrays.h # libraries/glslang/glslang/Include/intermediate.h # libraries/glslang/glslang/Include/revision.h # libraries/glslang/glslang/Include/revision.template # libraries/glslang/glslang/MachineIndependent/Constant.cpp # libraries/glslang/glslang/MachineIndependent/InfoSink.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.h # libraries/glslang/glslang/MachineIndependent/IntermTraverse.cpp # libraries/glslang/glslang/MachineIndependent/Intermediate.cpp # libraries/glslang/glslang/MachineIndependent/LiveTraverser.h # libraries/glslang/glslang/MachineIndependent/ParseContextBase.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.h # libraries/glslang/glslang/MachineIndependent/PoolAlloc.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.h # libraries/glslang/glslang/MachineIndependent/Scan.cpp # libraries/glslang/glslang/MachineIndependent/Scan.h # libraries/glslang/glslang/MachineIndependent/ScanContext.h # libraries/glslang/glslang/MachineIndependent/ShaderLang.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.h # libraries/glslang/glslang/MachineIndependent/Versions.cpp # libraries/glslang/glslang/MachineIndependent/Versions.h # libraries/glslang/glslang/MachineIndependent/attribute.cpp # libraries/glslang/glslang/MachineIndependent/attribute.h # libraries/glslang/glslang/MachineIndependent/gl_types.h # libraries/glslang/glslang/MachineIndependent/glslang.y # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp.h # libraries/glslang/glslang/MachineIndependent/intermOut.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.h # libraries/glslang/glslang/MachineIndependent/limits.cpp # libraries/glslang/glslang/MachineIndependent/linkValidate.cpp # libraries/glslang/glslang/MachineIndependent/localintermediate.h # libraries/glslang/glslang/MachineIndependent/parseConst.cpp # libraries/glslang/glslang/MachineIndependent/parseVersions.h # libraries/glslang/glslang/MachineIndependent/pch.cpp # libraries/glslang/glslang/MachineIndependent/pch.h # libraries/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.h # libraries/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.cpp # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.h # libraries/glslang/glslang/MachineIndependent/reflection.cpp # libraries/glslang/glslang/MachineIndependent/reflection.h # libraries/glslang/glslang/OSDependent/Unix/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Unix/ossource.cpp # libraries/glslang/glslang/OSDependent/Windows/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Windows/main.cpp # libraries/glslang/glslang/OSDependent/Windows/ossource.cpp # libraries/glslang/glslang/OSDependent/osinclude.h # libraries/glslang/glslang/Public/ShaderLang.h # libraries/glslang/glslang/updateGrammar # libraries/glslang/spirv/CMakeLists.txt # libraries/glslang/spirv/GLSL.ext.AMD.h # libraries/glslang/spirv/GLSL.ext.EXT.h # libraries/glslang/spirv/GLSL.ext.KHR.h # libraries/glslang/spirv/GLSL.ext.NV.h # libraries/glslang/spirv/GLSL.std.450.h # libraries/glslang/spirv/GlslangToSpv.cpp # libraries/glslang/spirv/GlslangToSpv.h # libraries/glslang/spirv/InReadableOrder.cpp # libraries/glslang/spirv/Logger.cpp # libraries/glslang/spirv/Logger.h # libraries/glslang/spirv/SPVRemapper.cpp # libraries/glslang/spirv/SPVRemapper.h # libraries/glslang/spirv/SpvBuilder.cpp # libraries/glslang/spirv/SpvBuilder.h # libraries/glslang/spirv/SpvPostProcess.cpp # libraries/glslang/spirv/SpvTools.cpp # libraries/glslang/spirv/SpvTools.h # libraries/glslang/spirv/bitutils.h # libraries/glslang/spirv/disassemble.cpp # libraries/glslang/spirv/disassemble.h # libraries/glslang/spirv/doc.cpp # libraries/glslang/spirv/doc.h # libraries/glslang/spirv/hex_float.h # libraries/glslang/spirv/spirv.hpp # libraries/glslang/spirv/spvIR.h # src/CMakeLists.txt
232 lines
5.6 KiB
C++
232 lines
5.6 KiB
C++
// Blip_Buffer 0.4.1. http://www.slack.net/~ant/
|
|
|
|
#include "Multi_Buffer.h"
|
|
|
|
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
|
|
can redistribute it and/or modify it under the terms of the GNU Lesser
|
|
General Public License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version. This
|
|
module is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
details. You should have received a copy of the GNU Lesser General Public
|
|
License along with this module; if not, write to the Free Software Foundation,
|
|
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
|
|
#include "blargg_source.h"
|
|
|
|
#ifdef BLARGG_ENABLE_OPTIMIZER
|
|
#include BLARGG_ENABLE_OPTIMIZER
|
|
#endif
|
|
|
|
Multi_Buffer::Multi_Buffer( int spf ) : samples_per_frame_( spf )
|
|
{
|
|
length_ = 0;
|
|
sample_rate_ = 0;
|
|
channels_changed_count_ = 1;
|
|
}
|
|
|
|
blargg_err_t Multi_Buffer::set_channel_count( int ) { return 0; }
|
|
|
|
// Silent_Buffer
|
|
|
|
Silent_Buffer::Silent_Buffer() : Multi_Buffer( 1 ) // 0 channels would probably confuse
|
|
{
|
|
// TODO: better to use empty Blip_Buffer so caller never has to check for NULL?
|
|
chan.left = 0;
|
|
chan.center = 0;
|
|
chan.right = 0;
|
|
}
|
|
|
|
// Mono_Buffer
|
|
|
|
Mono_Buffer::Mono_Buffer() : Multi_Buffer( 1 )
|
|
{
|
|
chan.center = &buf;
|
|
chan.left = &buf;
|
|
chan.right = &buf;
|
|
}
|
|
|
|
Mono_Buffer::~Mono_Buffer() { }
|
|
|
|
blargg_err_t Mono_Buffer::set_sample_rate( long rate, int msec )
|
|
{
|
|
RETURN_ERR( buf.set_sample_rate( rate, msec ) );
|
|
return Multi_Buffer::set_sample_rate( buf.sample_rate(), buf.length() );
|
|
}
|
|
|
|
// Stereo_Buffer
|
|
|
|
Stereo_Buffer::Stereo_Buffer() : Multi_Buffer( 2 )
|
|
{
|
|
chan.center = &bufs [0];
|
|
chan.left = &bufs [1];
|
|
chan.right = &bufs [2];
|
|
}
|
|
|
|
Stereo_Buffer::~Stereo_Buffer() { }
|
|
|
|
blargg_err_t Stereo_Buffer::set_sample_rate( long rate, int msec )
|
|
{
|
|
for ( int i = 0; i < buf_count; i++ )
|
|
RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) );
|
|
return Multi_Buffer::set_sample_rate( bufs [0].sample_rate(), bufs [0].length() );
|
|
}
|
|
|
|
void Stereo_Buffer::clock_rate( long rate )
|
|
{
|
|
for ( int i = 0; i < buf_count; i++ )
|
|
bufs [i].clock_rate( rate );
|
|
}
|
|
|
|
void Stereo_Buffer::bass_freq( int bass )
|
|
{
|
|
for ( int i = 0; i < buf_count; i++ )
|
|
bufs [i].bass_freq( bass );
|
|
}
|
|
|
|
void Stereo_Buffer::clear()
|
|
{
|
|
stereo_added = 0;
|
|
was_stereo = false;
|
|
for ( int i = 0; i < buf_count; i++ )
|
|
bufs [i].clear();
|
|
}
|
|
|
|
void Stereo_Buffer::end_frame( blip_time_t clock_count )
|
|
{
|
|
stereo_added = 0;
|
|
for ( int i = 0; i < buf_count; i++ )
|
|
{
|
|
stereo_added |= bufs [i].clear_modified() << i;
|
|
bufs [i].end_frame( clock_count );
|
|
}
|
|
}
|
|
|
|
long Stereo_Buffer::read_samples( blip_sample_t* out, long count )
|
|
{
|
|
require( !(count & 1) ); // count must be even
|
|
count = (unsigned) count / 2;
|
|
|
|
long avail = bufs [0].samples_avail();
|
|
if ( count > avail )
|
|
count = avail;
|
|
if ( count )
|
|
{
|
|
int bufs_used = stereo_added | was_stereo;
|
|
//debug_printf( "%X\n", bufs_used );
|
|
if ( bufs_used <= 1 )
|
|
{
|
|
mix_mono( out, count );
|
|
bufs [0].remove_samples( count );
|
|
bufs [1].remove_silence( count );
|
|
bufs [2].remove_silence( count );
|
|
}
|
|
else if ( bufs_used & 1 )
|
|
{
|
|
mix_stereo( out, count );
|
|
bufs [0].remove_samples( count );
|
|
bufs [1].remove_samples( count );
|
|
bufs [2].remove_samples( count );
|
|
}
|
|
else
|
|
{
|
|
mix_stereo_no_center( out, count );
|
|
bufs [0].remove_silence( count );
|
|
bufs [1].remove_samples( count );
|
|
bufs [2].remove_samples( count );
|
|
}
|
|
|
|
// to do: this might miss opportunities for optimization
|
|
if ( !bufs [0].samples_avail() )
|
|
{
|
|
was_stereo = stereo_added;
|
|
stereo_added = 0;
|
|
}
|
|
}
|
|
|
|
return count * 2;
|
|
}
|
|
|
|
void Stereo_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count )
|
|
{
|
|
blip_sample_t* BLIP_RESTRICT out = out_;
|
|
int const bass = BLIP_READER_BASS( bufs [1] );
|
|
BLIP_READER_BEGIN( left, bufs [1] );
|
|
BLIP_READER_BEGIN( right, bufs [2] );
|
|
BLIP_READER_BEGIN( center, bufs [0] );
|
|
|
|
for ( ; count; --count )
|
|
{
|
|
int c = BLIP_READER_READ( center );
|
|
blargg_long l = c + BLIP_READER_READ( left );
|
|
blargg_long r = c + BLIP_READER_READ( right );
|
|
if ( (int16_t) l != l )
|
|
l = 0x7FFF - (l >> 24);
|
|
|
|
BLIP_READER_NEXT( center, bass );
|
|
if ( (int16_t) r != r )
|
|
r = 0x7FFF - (r >> 24);
|
|
|
|
BLIP_READER_NEXT( left, bass );
|
|
BLIP_READER_NEXT( right, bass );
|
|
|
|
out [0] = l;
|
|
out [1] = r;
|
|
out += 2;
|
|
}
|
|
|
|
BLIP_READER_END( center, bufs [0] );
|
|
BLIP_READER_END( right, bufs [2] );
|
|
BLIP_READER_END( left, bufs [1] );
|
|
}
|
|
|
|
void Stereo_Buffer::mix_stereo_no_center( blip_sample_t* out_, blargg_long count )
|
|
{
|
|
blip_sample_t* BLIP_RESTRICT out = out_;
|
|
int const bass = BLIP_READER_BASS( bufs [1] );
|
|
BLIP_READER_BEGIN( left, bufs [1] );
|
|
BLIP_READER_BEGIN( right, bufs [2] );
|
|
|
|
for ( ; count; --count )
|
|
{
|
|
blargg_long l = BLIP_READER_READ( left );
|
|
if ( (int16_t) l != l )
|
|
l = 0x7FFF - (l >> 24);
|
|
|
|
blargg_long r = BLIP_READER_READ( right );
|
|
if ( (int16_t) r != r )
|
|
r = 0x7FFF - (r >> 24);
|
|
|
|
BLIP_READER_NEXT( left, bass );
|
|
BLIP_READER_NEXT( right, bass );
|
|
|
|
out [0] = l;
|
|
out [1] = r;
|
|
out += 2;
|
|
}
|
|
|
|
BLIP_READER_END( right, bufs [2] );
|
|
BLIP_READER_END( left, bufs [1] );
|
|
}
|
|
|
|
void Stereo_Buffer::mix_mono( blip_sample_t* out_, blargg_long count )
|
|
{
|
|
blip_sample_t* BLIP_RESTRICT out = out_;
|
|
int const bass = BLIP_READER_BASS( bufs [0] );
|
|
BLIP_READER_BEGIN( center, bufs [0] );
|
|
|
|
for ( ; count; --count )
|
|
{
|
|
blargg_long s = BLIP_READER_READ( center );
|
|
if ( (int16_t) s != s )
|
|
s = 0x7FFF - (s >> 24);
|
|
|
|
BLIP_READER_NEXT( center, bass );
|
|
out [0] = s;
|
|
out [1] = s;
|
|
out += 2;
|
|
}
|
|
|
|
BLIP_READER_END( center, bufs [0] );
|
|
}
|