Remove Stereo_Buffer

This commit is contained in:
twinaphex 2014-06-19 00:04:20 +02:00
parent 5a53d6c65a
commit 000aa38f80
10 changed files with 0 additions and 523 deletions

View File

@ -32,7 +32,6 @@ endif
NEED_TREMOR = 1
NEED_BLIP = 1
NEED_CD = 1
NEED_STEREO_SOUND = 1
NEED_SCSI_CD = 1
NEED_THREADING = 1
NEED_CRC32 = 1
@ -69,10 +68,6 @@ ifeq ($(NEED_BLIP), 1)
RESAMPLER_SOURCES += $(MEDNAFEN_DIR)/sound/Blip_Buffer.cpp
endif
ifeq ($(NEED_STEREO_SOUND), 1)
SOUND_DEFINE := -DWANT_STEREO_SOUND
endif
CORE_INCDIR := -I$(CORE_DIR)
ifeq ($(platform), unix)
@ -289,7 +284,6 @@ MEDNAFEN_SOURCES := $(MEDNAFEN_DIR)/mednafen.cpp \
$(MEDNAFEN_DIR)/mempatcher.cpp \
$(MEDNAFEN_DIR)/video/surface.cpp \
$(RESAMPLER_SOURCES) \
$(MEDNAFEN_DIR)/sound/Stereo_Buffer.cpp \
$(MEDNAFEN_DIR)/file.cpp \
$(OKIADPCM_SOURCES) \
$(MEDNAFEN_DIR)/md5.cpp

View File

@ -107,7 +107,6 @@ MEDNAFEN_SOURCES := $(MEDNAFEN_DIR)/mednafen.cpp \
$(MEDNAFEN_DIR)/mempatcher.cpp \
$(MEDNAFEN_DIR)/video/surface.cpp \
$(MEDNAFEN_DIR)/sound/Blip_Buffer.cpp \
$(MEDNAFEN_DIR)/sound/Stereo_Buffer.cpp \
$(MEDNAFEN_DIR)/file.cpp \
$(MEDNAFEN_DIR)/endian.cpp \
$(OKIADPCM_SOURCES) \

View File

@ -1,243 +0,0 @@
// Finite impulse response (FIR) resampler with adjustable FIR size
// Game_Music_Emu 0.5.2
#ifndef FIR_RESAMPLER_H
#define FIR_RESAMPLER_H
#include "blargg_common.h"
#include <string.h>
class Fir_Resampler_ {
public:
// Use Fir_Resampler<width> (below)
// Set input/output resampling ratio and optionally low-pass rolloff and gain.
// Returns actual ratio used (rounded to internal precision).
double time_ratio( double factor, double rolloff = 0.999, double gain = 1.0 );
// Current input/output ratio
double ratio() const { return ratio_; }
// Input
typedef short sample_t;
// Resize and clear input buffer
blargg_err_t buffer_size( int );
// Clear input buffer. At least two output samples will be available after
// two input samples are written.
void clear();
// Number of input samples that can be written
int max_write() const { return buf.end() - write_pos; }
// Pointer to place to write input samples
sample_t* buffer() { return write_pos; }
// Notify resampler that 'count' input samples have been written
void write( long count );
// Number of input samples in buffer
int written() const { return write_pos - &buf [write_offset]; }
// Skip 'count' input samples. Returns number of samples actually skipped.
int skip_input( long count );
// Output
// Number of extra input samples needed until 'count' output samples are available
int input_needed( blargg_long count ) const;
// Number of output samples available
int avail() const { return avail_( write_pos - &buf [width_ * stereo] ); }
public:
~Fir_Resampler_();
protected:
enum { stereo = 2 };
enum { max_res = 32 };
blargg_vector<sample_t> buf;
sample_t* write_pos;
int res;
int imp_phase;
int const width_;
int const write_offset;
blargg_ulong skip_bits;
int step;
int input_per_cycle;
double ratio_;
sample_t* impulses;
Fir_Resampler_( int width, sample_t* );
int avail_( blargg_long input_count ) const;
};
// Width is number of points in FIR. Must be even and 4 or more. More points give
// better quality and rolloff effectiveness, and take longer to calculate.
template<int width>
class Fir_Resampler : public Fir_Resampler_ {
BOOST_STATIC_ASSERT( width >= 4 && width % 2 == 0 );
short impulses [max_res] [width];
public:
Fir_Resampler() : Fir_Resampler_( width, impulses [0] ) { }
// Read at most 'count' samples. Returns number of samples actually read.
typedef short sample_t;
int read( sample_t* out, blargg_long count );
int read_mono_hack( sample_t* out, blargg_long count );
};
// End of public interface
inline void Fir_Resampler_::write( long count )
{
write_pos += count;
assert( write_pos <= buf.end() );
}
template<int width>
int Fir_Resampler<width>::read( sample_t* out_begin, blargg_long count )
{
sample_t* out = out_begin;
const sample_t* in = buf.begin();
sample_t* end_pos = write_pos;
blargg_ulong skip = skip_bits >> imp_phase;
sample_t const* imp = impulses [imp_phase];
int remain = res - imp_phase;
int const local_step = this->step;
count >>= 1;
if ( end_pos - in >= width * stereo )
{
end_pos -= width * stereo;
do
{
count--;
// accumulate in extended precision
blargg_long l = 0;
blargg_long r = 0;
const sample_t* i = in;
if ( count < 0 )
break;
for ( int n = width / 2; n; --n )
{
int pt0 = imp [0];
l += pt0 * i [0];
r += pt0 * i [1];
int pt1 = imp [1];
imp += 2;
l += pt1 * i [2];
r += pt1 * i [3];
i += 4;
}
remain--;
l >>= 15;
r >>= 15;
in += (skip * stereo) & stereo;
skip >>= 1;
in += local_step;
if ( !remain )
{
imp = impulses [0];
skip = skip_bits;
remain = res;
}
out [0] = (sample_t) l;
out [1] = (sample_t) r;
out += 2;
}
while ( in <= end_pos );
}
imp_phase = res - remain;
int left = write_pos - in;
write_pos = &buf [left];
memmove( buf.begin(), in, left * sizeof *in );
return out - out_begin;
}
#include <stdio.h>
template<int width>
int Fir_Resampler<width>::read_mono_hack( sample_t* out_begin, blargg_long count )
{
sample_t* out = out_begin;
const sample_t* in = buf.begin();
sample_t* end_pos = write_pos;
blargg_ulong skip = skip_bits >> imp_phase;
sample_t const* imp = impulses [imp_phase];
int remain = res - imp_phase;
int const local_step = this->step;
count >>= 1;
if ( end_pos - in >= width * stereo )
{
end_pos -= width * stereo;
do
{
count--;
// accumulate in extended precision
blargg_long l = 0;
const sample_t* i = in;
if ( count < 0 )
break;
for ( int n = width / 2; n; --n )
{
int pt0 = imp [0];
l += pt0 * i [0];
int pt1 = imp [1];
imp += 2;
l += pt1 * i [2];
i += 4;
}
remain--;
l >>= 15;
in += (skip * stereo) & stereo;
skip >>= 1;
in += local_step;
if ( !remain )
{
imp = impulses [0];
skip = skip_bits;
remain = res;
}
*out = (sample_t) l;
out ++;
}
while ( in <= end_pos );
}
imp_phase = res - remain;
int left = write_pos - in;
write_pos = &buf [left];
memmove( buf.begin(), in, left * sizeof *in );
return out - out_begin;
}
#endif

View File

@ -1,71 +0,0 @@
// Simple stereo Blip_Buffer for sound emulators whose oscillators output
// either on the left only, center, or right only.
// Blip_Buffer 0.3.0. Copyright (C) 2003-2004 Shay Green. GNU GPL license.
#ifndef STEREO_BUFFER_H
#define STEREO_BUFFER_H
#include "Blip_Buffer.h"
class Stereo_Buffer {
public:
Stereo_Buffer();
~Stereo_Buffer();
// Same as in Blip_Buffer (see Blip_Buffer.h)
bool set_sample_rate( long, int msec = 0 );
void clock_rate( long );
void bass_freq( int );
void clear();
// Buffers to output synthesis to
Blip_Buffer* left();
Blip_Buffer* center();
Blip_Buffer* right();
// Same as in Blip_Buffer. For more efficient operation, pass false
// for was_stereo if the left and right buffers had nothing added
// to them for this frame.
void end_frame( blip_time_t, bool was_stereo = true );
// Output is stereo with channels interleved, left before right. Counts
// are in samples, *not* pairs.
long samples_avail() const;
long read_samples( blip_sample_t*, long );
private:
// noncopyable
Stereo_Buffer( const Stereo_Buffer& );
Stereo_Buffer& operator = ( const Stereo_Buffer& );
enum { buf_count = 3 };
Blip_Buffer bufs [buf_count];
bool stereo_added;
bool was_stereo;
void mix_stereo( blip_sample_t*, long );
void mix_mono( blip_sample_t*, long );
void mix_stereo( float*, long );
void mix_mono( float*, long );
};
inline Blip_Buffer* Stereo_Buffer::left() {
return &bufs [1];
}
inline Blip_Buffer* Stereo_Buffer::center() {
return &bufs [0];
}
inline Blip_Buffer* Stereo_Buffer::right() {
return &bufs [2];
}
inline long Stereo_Buffer::samples_avail() const {
return bufs [0].samples_avail();
}
#endif

View File

@ -1,191 +0,0 @@
// Blip_Buffer 0.3.0. http://www.slack.net/~ant/nes-emu/
#include <blip/Stereo_Buffer.h>
/* Library Copyright (C) 2004 Shay Green. Blip_Buffer is free software;
you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
Stereo_Buffer 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 General Public License
for more details. You should have received a copy of the GNU General
Public License along with Stereo_Buffer; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
Stereo_Buffer::Stereo_Buffer() {
}
Stereo_Buffer::~Stereo_Buffer() {
}
bool Stereo_Buffer::set_sample_rate( long rate, int msec )
{
for ( int i = 0; i < buf_count; i++ ) {
if ( bufs [i].set_sample_rate( rate, msec ) )
{
return false;
}
}
return true;
}
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 ( unsigned i = 0; i < buf_count; i++ )
bufs [i].bass_freq( bass );
}
void Stereo_Buffer::clear()
{
stereo_added = false;
was_stereo = false;
for ( int i = 0; i < buf_count; i++ )
bufs [i].clear();
}
void Stereo_Buffer::end_frame( blip_time_t clock_count, bool stereo )
{
for ( unsigned i = 0; i < buf_count; i++ )
{
bufs [i].end_frame( clock_count );
}
stereo_added |= stereo;
}
long Stereo_Buffer::read_samples( blip_sample_t* out, long max_samples )
{
long count = bufs [0].samples_avail();
if ( count > max_samples / 2 )
count = max_samples / 2;
if ( count )
{
if ( stereo_added || was_stereo )
{
mix_stereo( out, count );
bufs [0].remove_samples( count );
bufs [1].remove_samples( count );
bufs [2].remove_samples( count );
}
#ifndef WANT_STEREO_SOUND
else
{
mix_mono( out, count );
bufs [0].remove_samples( count );
bufs [1].remove_silence( count );
bufs [2].remove_silence( count );
}
#endif
// to do: this might miss opportunities for optimization
if ( !bufs [0].samples_avail() ) {
was_stereo = stereo_added;
stereo_added = false;
}
}
return count * 2;
}
void Stereo_Buffer::mix_stereo( blip_sample_t* out, long count )
{
Blip_Reader left;
Blip_Reader right;
Blip_Reader center;
left.begin( bufs [1] );
right.begin( bufs [2] );
int bass = center.begin( bufs [0] );
while ( count-- )
{
int c = center.read();
out [0] = c + left.read();
out [1] = c + right.read();
out += 2;
center.next( bass );
left.next( bass );
right.next( bass );
}
center.end( bufs [0] );
right.end( bufs [2] );
left.end( bufs [1] );
}
void Stereo_Buffer::mix_stereo( float* out, long count )
{
Blip_Reader left;
Blip_Reader right;
Blip_Reader center;
left.begin( bufs [1] );
right.begin( bufs [2] );
int bass = center.begin( bufs [0] );
while ( count-- )
{
int c = center.read();
out [0] = (float)(c + left.read()) / 32768;
out [1] = (float)(c + right.read()) / 32768;
out += 2;
center.next( bass );
left.next( bass );
right.next( bass );
}
center.end( bufs [0] );
right.end( bufs [2] );
left.end( bufs [1] );
}
#ifndef WANT_STEREO_SOUND
void Stereo_Buffer::mix_mono( blip_sample_t* out, long count )
{
Blip_Reader in;
int bass = in.begin( bufs [0] );
while ( count-- )
{
int sample = in.read();
out [0] = sample;
out [1] = sample;
out += 2;
in.next( bass );
}
in.end( bufs [0] );
}
void Stereo_Buffer::mix_mono( float* out, long count )
{
Blip_Reader in;
int bass = in.begin( bufs [0] );
while ( count-- )
{
int sample = in.read();
out [0] = (float)(sample) / 32768;
out [1] = (float)(sample) / 32768;
out += 2;
in.next( bass );
}
in.end( bufs [0] );
}
#endif

View File

@ -339,9 +339,6 @@
<File
RelativePath="..\..\..\mednafen\sound\Blip_Buffer.cpp">
</File>
<File
RelativePath="..\..\..\mednafen\sound\Stereo_Buffer.cpp">
</File>
</Filter>
<Filter
Name="pce_fast"

View File

@ -67,7 +67,6 @@
<ClCompile Include="..\..\..\mednafen\pce_fast\vdc.cpp" />
<ClCompile Include="..\..\..\mednafen\settings.cpp" />
<ClCompile Include="..\..\..\mednafen\sound\Blip_Buffer.cpp" />
<ClCompile Include="..\..\..\mednafen\sound\Stereo_Buffer.cpp" />
<ClCompile Include="..\..\..\mednafen\state.cpp" />
<ClCompile Include="..\..\..\mednafen\Stream.cpp" />
<ClCompile Include="..\..\..\mednafen\tremor\bitwise.c">

View File

@ -122,9 +122,6 @@
<ClCompile Include="..\..\..\mednafen\trio\trio.c">
<Filter>Source Files\mednafen\trio</Filter>
</ClCompile>
<ClCompile Include="..\..\..\mednafen\sound\Stereo_Buffer.cpp">
<Filter>Source Files\mednafen\sound</Filter>
</ClCompile>
<ClCompile Include="..\..\..\mednafen\cdrom\scsicd.cpp">
<Filter>Source Files\mednafen\cdrom</Filter>
</ClCompile>

View File

@ -51,7 +51,6 @@
<ClCompile Include="..\..\..\mednafen\pce_fast\vdc.cpp" />
<ClCompile Include="..\..\..\mednafen\settings.cpp" />
<ClCompile Include="..\..\..\mednafen\sound\Blip_Buffer.cpp" />
<ClCompile Include="..\..\..\mednafen\sound\Stereo_Buffer.cpp" />
<ClCompile Include="..\..\..\mednafen\state.cpp" />
<ClCompile Include="..\..\..\mednafen\Stream.cpp" />
<ClCompile Include="..\..\..\mednafen\tremor\bitwise.c">

View File

@ -122,9 +122,6 @@
<ClCompile Include="..\..\..\mednafen\trio\trio.c">
<Filter>Source Files\mednafen\trio</Filter>
</ClCompile>
<ClCompile Include="..\..\..\mednafen\sound\Stereo_Buffer.cpp">
<Filter>Source Files\mednafen\sound</Filter>
</ClCompile>
<ClCompile Include="..\..\..\mednafen\cdrom\scsicd.cpp">
<Filter>Source Files\mednafen\cdrom</Filter>
</ClCompile>