Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/quicknes/nes_emu/Nes_Effects_Buffer.cpp
2 views
1
2
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
3
4
#include "Nes_Effects_Buffer.h"
5
6
#include "Nes_Apu.h"
7
8
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
9
can redistribute it and/or modify it under the terms of the GNU Lesser
10
General Public License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version. This
12
module is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15
more details. You should have received a copy of the GNU Lesser General
16
Public License along with this module; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
19
#include "blargg_source.h"
20
21
Nes_Effects_Buffer::Nes_Effects_Buffer() :
22
Effects_Buffer( true ) // nes never uses stereo channels
23
{
24
config_t c;
25
c.effects_enabled = false;
26
config( c );
27
}
28
29
Nes_Effects_Buffer::~Nes_Effects_Buffer() { }
30
31
Multi_Buffer* set_apu( Nes_Effects_Buffer* buf, Nes_Apu* apu )
32
{
33
buf->set_apu( apu );
34
return buf;
35
}
36
37
void Nes_Effects_Buffer::enable_nonlinearity( bool b )
38
{
39
if ( b )
40
clear();
41
Nes_Apu* apu = nonlin.enable( b, channel( 2 ).center );
42
apu->osc_output( 0, channel( 0 ).center );
43
apu->osc_output( 1, channel( 1 ).center );
44
}
45
46
void Nes_Effects_Buffer::config( const config_t& in )
47
{
48
config_t c = in;
49
if ( !c.effects_enabled )
50
{
51
// effects must always be enabled to keep separate buffers, so
52
// set parameters to be equivalent to disabled
53
c.pan_1 = 0;
54
c.pan_2 = 0;
55
c.echo_level = 0;
56
c.reverb_level = 0;
57
c.effects_enabled = true;
58
}
59
Effects_Buffer::config( c );
60
}
61
62
blargg_err_t Nes_Effects_Buffer::set_sample_rate( long rate, int msec )
63
{
64
enable_nonlinearity( nonlin.enabled ); // reapply
65
return Effects_Buffer::set_sample_rate( rate, msec );
66
}
67
68
void Nes_Effects_Buffer::clear()
69
{
70
nonlin.clear();
71
Effects_Buffer::clear();
72
}
73
74
Nes_Effects_Buffer::channel_t Nes_Effects_Buffer::channel( int i )
75
{
76
return Effects_Buffer::channel( (2 <= i && i <= 4) ? 2 : i & 1 );
77
}
78
79
long Nes_Effects_Buffer::read_samples( blip_sample_t* out, long count )
80
{
81
count = 2 * nonlin.make_nonlinear( *channel( 2 ).center, count / 2 );
82
return Effects_Buffer::read_samples( out, count );
83
}
84
85
86