*** empty log message ***
[chuck-blob.git] / exile / v1 / src / chuck_bbq.cpp
blobe70bdf4ed481404be4f5f5b389eae24a2132b6c4
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_bbq.cpp
27 // desc: implementation
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 //-----------------------------------------------------------------------------
32 #include "chuck_bbq.h"
33 #include <math.h>
34 #include <memory.h>
35 #include <stdlib.h>
40 //-----------------------------------------------------------------------------
41 // name: BBQ()
42 // desc: ...
43 //-----------------------------------------------------------------------------
44 BBQ::BBQ()
46 m_max_midi_device = 1024;
47 m_digi_out = new DigitalOut;
48 m_digi_in = new DigitalIn;
49 m_midi_out = new MidiOut * [m_max_midi_device];
50 m_midi_in = new MidiIn * [m_max_midi_device];
51 m_in_count = new DWORD__[m_max_midi_device];
52 m_out_count = new DWORD__[m_max_midi_device];
53 memset( m_midi_out, 0, m_max_midi_device * sizeof(MidiOut *) );
54 memset( m_midi_in, 0, m_max_midi_device * sizeof(MidiIn *) );
55 memset( m_in_count, 0, m_max_midi_device * sizeof(DWORD__) );
56 memset( m_out_count, 0, m_max_midi_device * sizeof(DWORD__) );
57 //m_midi_out[0] = new MidiOut;
58 //m_midi_in[0] = new MidiIn;
64 //-----------------------------------------------------------------------------
65 // name: ~BBQ()
66 // desc: ...
67 //-----------------------------------------------------------------------------
68 BBQ::~BBQ()
70 SAFE_DELETE( m_digi_out );
71 SAFE_DELETE( m_digi_in );
72 SAFE_DELETE_ARRAY( m_midi_out );
73 SAFE_DELETE_ARRAY( m_midi_in );
74 SAFE_DELETE_ARRAY( m_in_count );
75 SAFE_DELETE_ARRAY( m_out_count );
81 //-----------------------------------------------------------------------------
82 // name: initialize()
83 // desc: ...
84 //-----------------------------------------------------------------------------
85 BOOL__ BBQ::initialize( DWORD__ num_channels, DWORD__ sampling_rate,
86 DWORD__ bps, DWORD__ buffer_size, DWORD__ num_buffers,
87 DWORD__ dac, DWORD__ adc )
89 Digitalio::m_dac_n = dac;
90 Digitalio::m_adc_n = adc;
92 return Digitalio::initialize(
93 num_channels, sampling_rate, bps, buffer_size, num_buffers
100 //-----------------------------------------------------------------------------
101 // name: set_srate()
102 // desc: ...
103 //-----------------------------------------------------------------------------
104 void BBQ::set_srate( DWORD__ srate )
106 Digitalio::m_sampling_rate = srate;
112 //-----------------------------------------------------------------------------
113 // name: set_bufsize()
114 // desc: ...
115 //-----------------------------------------------------------------------------
116 void BBQ::set_bufsize( DWORD__ bufsize )
118 Digitalio::m_buffer_size = bufsize;
123 //-----------------------------------------------------------------------------
124 // name: shutdown()
125 // desc: ...
126 //-----------------------------------------------------------------------------
127 void BBQ::shutdown()
129 Digitalio::shutdown();
135 //-----------------------------------------------------------------------------
136 // name: digi_out()
137 // desc: digital out
138 //-----------------------------------------------------------------------------
139 DigitalOut * BBQ::digi_out()
141 return m_digi_out;
147 //-----------------------------------------------------------------------------
148 // name: digi_in()
149 // desc: digital in
150 //-----------------------------------------------------------------------------
151 DigitalIn * BBQ::digi_in()
153 return m_digi_in;
159 //-----------------------------------------------------------------------------
160 // name: midi_out()
161 // desc: midi out
162 //-----------------------------------------------------------------------------
163 MidiOut * BBQ::midi_out( DWORD__ index )
165 if( index >= m_max_midi_device )
166 return NULL;
168 if( m_midi_out[index] == NULL )
170 m_midi_out[index] = new MidiOut;
171 if( !m_midi_out[index]->open( index ) )
173 delete m_midi_out[index];
174 m_midi_out[index] = NULL;
175 m_out_count[index]++;
177 else
178 m_out_count[index] = 0;
181 return m_midi_out[index];
187 //-----------------------------------------------------------------------------
188 // name: midi_in()
189 // desc: ...
190 //-----------------------------------------------------------------------------
191 MidiIn * BBQ::midi_in( DWORD__ index )
193 if( index >= m_max_midi_device )
194 return NULL;
196 if( m_midi_in[index] == NULL )
198 m_midi_in[index] = new MidiIn;
199 if( !m_midi_in[index]->open( index ) )
201 delete m_midi_in[index];
202 m_midi_in[index] = NULL;
203 m_in_count[index]++;
205 else
206 m_in_count[index] = 0;
209 return m_midi_in[index];
215 //-----------------------------------------------------------------------------
216 // name: RangeMapper()
217 // desc: constructor
218 //-----------------------------------------------------------------------------
219 RangeMapper::RangeMapper( SAMPLE low_l, SAMPLE high_l,
220 SAMPLE low_r, SAMPLE high_r )
222 SAMPLE dx = high_l - low_l;
223 if( fabs( (double)dx ) < .000001 )
224 m_slope = 0.0f;
225 else
226 m_slope = ( high_r - low_r ) / dx;
228 m_inter = high_r - m_slope * high_l;
234 //-----------------------------------------------------------------------------
235 // name: map()
236 // desc: ...
237 //-----------------------------------------------------------------------------
238 SAMPLE RangeMapper::map( SAMPLE x )
240 return m_slope * x + m_inter;