Mercurial > audlegacy-plugins
comparison src/console/Classic_Emu.cxx @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/console/Classic_Emu.cxx@13389e613d67 |
children | fb513e10174e |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 | |
2 // Game_Music_Emu 0.3.0. http://www.slack.net/~ant/ | |
3 | |
4 #include "Classic_Emu.h" | |
5 | |
6 #include "Multi_Buffer.h" | |
7 | |
8 /* Copyright (C) 2003-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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ | |
18 | |
19 #include BLARGG_SOURCE_BEGIN | |
20 | |
21 Classic_Emu::Classic_Emu() | |
22 { | |
23 buf = NULL; | |
24 stereo_buffer = NULL; | |
25 } | |
26 | |
27 Classic_Emu::~Classic_Emu() | |
28 { | |
29 delete stereo_buffer; | |
30 } | |
31 | |
32 void Classic_Emu::set_equalizer( equalizer_t const& eq ) | |
33 { | |
34 Music_Emu::set_equalizer( eq ); | |
35 update_eq( eq.treble ); | |
36 if ( buf ) | |
37 buf->bass_freq( equalizer().bass ); | |
38 } | |
39 | |
40 blargg_err_t Classic_Emu::set_sample_rate( long sample_rate ) | |
41 { | |
42 if ( !buf ) | |
43 { | |
44 if ( !stereo_buffer ) | |
45 BLARGG_CHECK_ALLOC( stereo_buffer = BLARGG_NEW Stereo_Buffer ); | |
46 buf = stereo_buffer; | |
47 } | |
48 | |
49 BLARGG_RETURN_ERR( buf->set_sample_rate( sample_rate, 1000 / 20 ) ); | |
50 return Music_Emu::set_sample_rate( sample_rate ); | |
51 } | |
52 | |
53 void Classic_Emu::mute_voices( int mask ) | |
54 { | |
55 require( buf ); // set_sample_rate() must have been called | |
56 | |
57 Music_Emu::mute_voices( mask ); | |
58 for ( int i = voice_count(); i--; ) | |
59 { | |
60 if ( mask & (1 << i) ) | |
61 { | |
62 set_voice( i, NULL, NULL, NULL ); | |
63 } | |
64 else | |
65 { | |
66 Multi_Buffer::channel_t ch = buf->channel( i ); | |
67 set_voice( i, ch.center, ch.left, ch.right ); | |
68 } | |
69 } | |
70 } | |
71 | |
72 blargg_err_t Classic_Emu::setup_buffer( long new_clock_rate ) | |
73 { | |
74 require( sample_rate() ); // fails if set_sample_rate() hasn't been called yet | |
75 | |
76 clock_rate = new_clock_rate; | |
77 buf->clock_rate( clock_rate ); | |
78 BLARGG_RETURN_ERR( buf->set_channel_count( voice_count() ) ); | |
79 set_equalizer( equalizer() ); | |
80 remute_voices(); | |
81 return blargg_success; | |
82 } | |
83 | |
84 void Classic_Emu::start_track( int track ) | |
85 { | |
86 Music_Emu::start_track( track ); | |
87 buf->clear(); | |
88 } | |
89 | |
90 blip_time_t Classic_Emu::run_clocks( blip_time_t t, bool* ) | |
91 { | |
92 assert( false ); | |
93 return t; | |
94 } | |
95 | |
96 blip_time_t Classic_Emu::run( int msec, bool* added_stereo ) | |
97 { | |
98 return run_clocks( (long) msec * clock_rate / 1000, added_stereo ); | |
99 } | |
100 | |
101 void Classic_Emu::play( long count, sample_t* out ) | |
102 { | |
103 require( sample_rate() ); // fails if set_sample_rate() hasn't been called yet | |
104 | |
105 long remain = count; | |
106 while ( remain ) | |
107 { | |
108 remain -= buf->read_samples( &out [count - remain], remain ); | |
109 if ( remain ) | |
110 { | |
111 bool added_stereo = false; | |
112 blip_time_t clocks_emulated = run( buf->length(), &added_stereo ); | |
113 buf->end_frame( clocks_emulated, added_stereo ); | |
114 } | |
115 } | |
116 } | |
117 |