Path: blob/master/quicknes/nes_emu/Nes_Effects_Buffer.cpp
2 views
1// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/23#include "Nes_Effects_Buffer.h"45#include "Nes_Apu.h"67/* Copyright (C) 2004-2006 Shay Green. This module is free software; you8can redistribute it and/or modify it under the terms of the GNU Lesser9General Public License as published by the Free Software Foundation; either10version 2.1 of the License, or (at your option) any later version. This11module is distributed in the hope that it will be useful, but WITHOUT ANY12WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS13FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for14more details. You should have received a copy of the GNU Lesser General15Public License along with this module; if not, write to the Free Software16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */1718#include "blargg_source.h"1920Nes_Effects_Buffer::Nes_Effects_Buffer() :21Effects_Buffer( true ) // nes never uses stereo channels22{23config_t c;24c.effects_enabled = false;25config( c );26}2728Nes_Effects_Buffer::~Nes_Effects_Buffer() { }2930Multi_Buffer* set_apu( Nes_Effects_Buffer* buf, Nes_Apu* apu )31{32buf->set_apu( apu );33return buf;34}3536void Nes_Effects_Buffer::enable_nonlinearity( bool b )37{38if ( b )39clear();40Nes_Apu* apu = nonlin.enable( b, channel( 2 ).center );41apu->osc_output( 0, channel( 0 ).center );42apu->osc_output( 1, channel( 1 ).center );43}4445void Nes_Effects_Buffer::config( const config_t& in )46{47config_t c = in;48if ( !c.effects_enabled )49{50// effects must always be enabled to keep separate buffers, so51// set parameters to be equivalent to disabled52c.pan_1 = 0;53c.pan_2 = 0;54c.echo_level = 0;55c.reverb_level = 0;56c.effects_enabled = true;57}58Effects_Buffer::config( c );59}6061blargg_err_t Nes_Effects_Buffer::set_sample_rate( long rate, int msec )62{63enable_nonlinearity( nonlin.enabled ); // reapply64return Effects_Buffer::set_sample_rate( rate, msec );65}6667void Nes_Effects_Buffer::clear()68{69nonlin.clear();70Effects_Buffer::clear();71}7273Nes_Effects_Buffer::channel_t Nes_Effects_Buffer::channel( int i )74{75return Effects_Buffer::channel( (2 <= i && i <= 4) ? 2 : i & 1 );76}7778long Nes_Effects_Buffer::read_samples( blip_sample_t* out, long count )79{80count = 2 * nonlin.make_nonlinear( *channel( 2 ).center, count / 2 );81return Effects_Buffer::read_samples( out, count );82}83848586