annotate Plugins/Input/console/Classic_Emu.cpp @ 256:84aabc053b6e trunk

[svn] C++ warning fixes by external contractor Stephen Bennett.
author chainsaw
date Sun, 04 Dec 2005 08:49:53 -0800
parents 252843aac42f
children 7c5e886205ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
2 // Game_Music_Emu 0.2.4. http://www.slack.net/~ant/libs/
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
3
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
4 #include "Classic_Emu.h"
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
5
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
6 #include "Multi_Buffer.h"
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
7
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
8 /* Copyright (C) 2003-2005 Shay Green. This module is free software; you
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
9 can redistribute it and/or modify it under the terms of the GNU Lesser
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
10 General Public License as published by the Free Software Foundation; either
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
11 version 2.1 of the License, or (at your option) any later version. This
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
12 module is distributed in the hope that it will be useful, but WITHOUT ANY
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
14 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
15 more details. You should have received a copy of the GNU Lesser General
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
16 Public License along with this module; if not, write to the Free Software
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
18
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
19 #include BLARGG_SOURCE_BEGIN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
20
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
21 Classic_Emu::Classic_Emu()
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
22 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
23 buf = NULL;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
24 std_buf = NULL;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
25 set_equalizer( equalizer_t( -8.87, 8800 ) );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
26 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
27
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
28 Classic_Emu::~Classic_Emu()
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
29 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
30 delete std_buf;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
31 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
32
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
33 void Classic_Emu::update_eq_()
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
34 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
35 update_eq( blip_eq_t( equalizer_.treble, equalizer_.cutoff, buf->sample_rate() ) );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
36 buf->bass_freq( equalizer_.bass );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
37 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
38
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
39 void Classic_Emu::set_equalizer( const equalizer_t& eq )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
40 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
41 equalizer_ = eq;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
42 if ( buf )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
43 update_eq_();
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
44 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
45
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
46 blargg_err_t Classic_Emu::init( long sample_rate )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
47 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
48 buf = NULL;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
49 delete std_buf;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
50 std_buf = NULL;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
51
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
52 Stereo_Buffer* sb = new Stereo_Buffer;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
53 if ( !sb )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
54 return "Out of memory";
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
55 std_buf = sb;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
56
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
57 BLARGG_RETURN_ERR( sb->sample_rate( sample_rate, 1000 / 20 ) );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
58
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
59 buf = std_buf;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
60 return blargg_success;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
61 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
62
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
63 void Classic_Emu::mute_voices( int mask )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
64 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
65 require( buf ); // init() must have been called
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
66
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
67 mute_mask_ = mask;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
68 for ( int i = voice_count(); i--; )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
69 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
70 if ( mask & (1 << i) ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
71 set_voice( i, NULL );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
72 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
73 else {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
74 Multi_Buffer::channel_t ch = buf->channel( i );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
75 set_voice( i, ch.center, ch.left, ch.right );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
76 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
77 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
78 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
79
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
80 blargg_err_t Classic_Emu::setup_buffer( long clock_rate )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
81 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
82 require( buf ); // init() must have been called
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
83
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
84 buf->clock_rate( clock_rate );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
85 update_eq_();
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
86 return buf->set_channel_count( voice_count() );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
87 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
88
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
89 void Classic_Emu::starting_track()
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
90 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
91 require( buf ); // init() must have been called
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
92
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
93 mute_voices( 0 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
94 buf->clear();
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
95 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
96
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
97 blargg_err_t Classic_Emu::play( long count, sample_t* out )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
98 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
99 require( buf ); // init() must have been called
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
100
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
101 long remain = count;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
102 while ( remain )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
103 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
104 remain -= buf->read_samples( &out [count - remain], remain );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
105 if ( remain )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
106 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
107 bool added_stereo = false;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
108 blip_time_t cyc = run( buf->length(), &added_stereo );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
109 if ( !cyc )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
110 return "Emulation error";
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
111 buf->end_frame( cyc, added_stereo );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
112 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
113 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
114 return blargg_success;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
115 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
116