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
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: digitalio_osx.cpp
27 // desc: digitalio for osx
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // Ari Lazier (alazier@cs.princeton.edu)
32 //-----------------------------------------------------------------------------
33 #include "digitalio_osx.h"
41 BOOL__
Digitalio::m_init
= FALSE
;
42 DWORD__
Digitalio::m_num_channels
= NUM_CHANNELS_DEFAULT
;
43 DWORD__
Digitalio::m_sampling_rate
= SAMPLING_RATE_DEFAULT
;
44 DWORD__
Digitalio::m_bps
= BITS_PER_SAMPLE_DEFAULT
;
45 DWORD__
Digitalio::m_buffer_size
= BUFFER_SIZE_DEFAULT
;
46 DWORD__
Digitalio::m_num_buffers
= NUM_BUFFERS_DEFAULT
;
51 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
55 BOOL__
Digitalio::initialize( DWORD__ num_channels
, DWORD__ sampling_rate
,
56 DWORD__ bps
, DWORD__ buffer_size
, DWORD__ num_buffers
)
61 m_num_channels
= num_channels
;
62 m_sampling_rate
= sampling_rate
;
64 m_buffer_size
= buffer_size
;
65 m_num_buffers
= num_buffers
;
73 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
77 void Digitalio::shutdown()
85 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
89 DigitalOut::DigitalOut()
92 m_render_start
= FALSE
;
98 m_device_handle
= kAudioDeviceUnknown
;
101 m_out_buffers
= NULL
;
102 m_num_out_buffers
= 0;
103 m_out_buffer_size
= 0;
104 m_curr_buffer_out
= 0;
106 m_data_ptr_out
= NULL
;
107 m_data_max_out
= NULL
;
110 pthread_mutex_init( &m_mutex
, NULL
);
118 //-----------------------------------------------------------------------------
119 // name: ~DigitalOut()
121 //-----------------------------------------------------------------------------
122 DigitalOut::~DigitalOut()
130 //-----------------------------------------------------------------------------
131 // name: callback_handler_output()
133 //-----------------------------------------------------------------------------
134 OSStatus
callback_handler_output( AudioDeviceID inDevice
,
135 const AudioTimeStamp
* inNow
,
136 const AudioBufferList
* inInputData
,
137 const AudioTimeStamp
* inInputTime
,
138 AudioBufferList
* outOutputData
,
139 const AudioTimeStamp
* inOutputTime
,
142 DigitalOut
* out
= (DigitalOut
*)infoPointer
;
146 if( !out
->render( outOutputData
) )
147 return kAudioHardwareUnspecifiedError
;
149 return kAudioHardwareNoError
;
154 //-----------------------------------------------------------------------------
155 // name: initialize()
156 // desc: initialize audio out
157 //-----------------------------------------------------------------------------
158 BOOL__
DigitalOut::initialize( DWORD__ device_number
, DWORD__ num_channels
,
159 DWORD__ sampling_rate
, DWORD__ bps
,
160 DWORD__ buffer_size
, DWORD__ num_buffers
)
163 OSStatus err
= noErr
;
165 UInt32 the_buffer_size
= 0;
166 AudioStreamBasicDescription format
;
167 AudioBufferList
* buffer_list
= NULL
;
172 sprintf( msg
, "error: initialize(); DigitalOut already initialized..." );
176 // set the parameters
177 m_num_channels
= num_channels
;
178 m_sampling_rate
= sampling_rate
;
180 m_out_buffer_size
= buffer_size
;
181 m_num_out_buffers
= num_buffers
;
182 m_device_num
= device_number
;
184 // allocate the buffers
185 m_out_buffers
= new InternalBuffer
[m_num_out_buffers
];
186 for( int i
= 0; i
< m_num_out_buffers
; i
++ )
187 m_out_buffers
[i
].initialize( m_out_buffer_size
* sizeof(SAMPLE_INTERNAL
) *
190 m_curr_buffer_out
= 0;
191 m_data_ptr_out
= m_out_buffers
[0].data();
192 m_data_max_out
= m_data_ptr_out
+ m_out_buffer_size
* m_num_channels
;
195 // get the default device
196 dataSize
= sizeof( AudioDeviceID
);
197 err
= AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice
,
198 &dataSize
, &m_device_handle
);
201 sprintf( msg
, "error opening output device device..." );
205 // configure the device
206 err
= AudioDeviceGetPropertyInfo( m_device_handle
, 0, FALSE
,
207 kAudioDevicePropertyStreamConfiguration
,
209 if( err
!= noErr
|| dataSize
<= 0 )
211 sprintf( msg
, "error configuring audio device..." );
214 buffer_list
= (AudioBufferList
*)malloc(dataSize
);
215 err
= AudioDeviceGetProperty( m_device_handle
, 0, FALSE
,
216 kAudioDevicePropertyStreamConfiguration
,
217 &dataSize
, buffer_list
);
220 sprintf( msg
, "error configuring audio device..." );
224 AudioValueRange buffer_range
;
225 dataSize
= sizeof(AudioValueRange
);
226 err
= AudioDeviceGetProperty( m_device_handle
, 0, FALSE
,
227 kAudioDevicePropertyBufferSizeRange
,
228 &dataSize
, &buffer_range
);
231 sprintf( msg
, "error dealing with range" );
235 the_buffer_size
= m_out_buffer_size
* m_num_channels
* sizeof(SAMPLE_INTERNAL
);
237 // set the buffer size
238 dataSize
= sizeof(UInt32
);
239 err
= AudioDeviceSetProperty( m_device_handle
, NULL
, 0, FALSE
,
240 kAudioDevicePropertyBufferSize
,
241 dataSize
, &the_buffer_size
);
244 sprintf( msg
, "error setting buffer size '%d'", the_buffer_size
);
248 // set the sample rate
249 dataSize
= sizeof(AudioStreamBasicDescription
);
250 err
= AudioDeviceGetProperty( m_device_handle
, 0, FALSE
,
251 kAudioDevicePropertyStreamFormat
,
252 &dataSize
, &format
);
255 sprintf( msg
, "error setting sampling rate..." );
259 format
.mSampleRate
= m_sampling_rate
;
260 format
.mFormatID
= kAudioFormatLinearPCM
;
261 err
= AudioDeviceSetProperty( m_device_handle
, NULL
, 0, FALSE
,
262 kAudioDevicePropertyStreamFormat
,
266 sprintf( msg
, "error setting sampling rate '%d'", m_sampling_rate
);
270 // register callback handler
271 err
= AudioDeviceAddIOProc( m_device_handle
, callback_handler_output
, this );
274 sprintf( msg
, "error setting callback" );
284 // print out the error
296 //-----------------------------------------------------------------------------
299 //-----------------------------------------------------------------------------
300 BOOL__
DigitalOut::start()
305 pthread_mutex_lock( &m_mutex
);
309 sprintf( msg
, "error: start(): DigitalOut not initialized..." );
313 // check to see if started already
316 sprintf( msg
, "error: start(): DigitalOut already started..." );
321 err
= AudioDeviceStart( m_device_handle
, callback_handler_output
);
324 sprintf( msg
, "error starting audio device..." );
332 m_render_start
= TRUE
;
334 pthread_mutex_unlock( &m_mutex
);
338 // print out the error
341 pthread_mutex_unlock( &m_mutex
);
348 //-----------------------------------------------------------------------------
351 //-----------------------------------------------------------------------------
352 BOOL__
DigitalOut::stop()
357 // check to see if started
358 if( !m_render_start
)
360 sprintf( msg
, "error: stop(): DigitalOut not started..." );
364 pthread_mutex_lock( &m_mutex
);
366 err
= AudioDeviceStop( m_device_handle
, callback_handler_output
);
369 sprintf( msg
, "error stopping audio device..." );
374 m_render_start
= FALSE
;
376 pthread_mutex_unlock( &m_mutex
);
380 // print out the error
383 pthread_mutex_unlock( &m_mutex
);
390 //-----------------------------------------------------------------------------
393 //-----------------------------------------------------------------------------
394 void DigitalOut::cleanup()
404 SAFE_DELETE_ARRAY( m_out_buffers
);
413 //-----------------------------------------------------------------------------
416 //-----------------------------------------------------------------------------
417 BOOL__
DigitalOut::tick_out( SAMPLE sample
)
419 if( !prepare_tick_out() )
422 *m_data_ptr_out
++ = SAMPLE_TO_INTERNAL( sample
);
430 //-----------------------------------------------------------------------------
433 //-----------------------------------------------------------------------------
434 BOOL__
DigitalOut::tick_out( SAMPLE sample_l
, SAMPLE sample_r
)
436 if( !prepare_tick_out() )
439 *m_data_ptr_out
++ = SAMPLE_TO_INTERNAL( sample_l
);
440 *m_data_ptr_out
++ = SAMPLE_TO_INTERNAL( sample_r
);
448 //-----------------------------------------------------------------------------
450 // desc: all channels
451 //-----------------------------------------------------------------------------
452 BOOL__
DigitalOut::tick_out( const SAMPLE
* samples
, DWORD__ n
)
454 if( !prepare_tick_out() )
457 if( !n
) n
= m_num_channels
;
459 *m_data_ptr_out
++ = SAMPLE_TO_INTERNAL( *samples
++ );
467 //-----------------------------------------------------------------------------
468 // name: prepare_tick_out()
470 //-----------------------------------------------------------------------------
471 inline BOOL__
DigitalOut::prepare_tick_out()
476 if( m_data_ptr_out
>= m_data_max_out
)
478 if( !m_render_start
&& !start() )
482 while( m_block
>= m_num_out_buffers
)
485 m_curr_buffer_out
= (m_curr_buffer_out
+ 1) % m_num_out_buffers
;
486 m_data_ptr_out
= m_out_buffers
[m_curr_buffer_out
].data();
487 m_data_max_out
= m_data_ptr_out
+ m_out_buffer_size
* m_num_channels
;
496 //-----------------------------------------------------------------------------
499 //-----------------------------------------------------------------------------
500 DWORD__
DigitalOut::render( AudioBufferList
* buffer_list
)
509 memcpy( buffer_list
->mBuffers
[0].mData
,
510 m_out_buffers
[m_out2
].data(),
511 buffer_list
->mBuffers
[0].mDataByteSize
);
513 m_out2
= (m_out2
+ 1) % m_num_out_buffers
;
531 //-----------------------------------------------------------------------------
534 //-----------------------------------------------------------------------------
535 DigitalIn::DigitalIn()
538 m_capture_start
= FALSE
;
545 m_num_in_buffers
= 0;
546 m_in_buffer_size
= 0;
547 m_curr_buffer_in
= 0;
549 m_data_ptr_in
= NULL
;
550 m_data_max_in
= NULL
;
552 m_device_handle
= kAudioDeviceUnknown
;
555 pthread_mutex_init( &m_mutex
, NULL
);
563 //-----------------------------------------------------------------------------
564 // name: ~DigitalIn()
566 //-----------------------------------------------------------------------------
567 DigitalIn::~DigitalIn()
575 //-----------------------------------------------------------------------------
576 // name: callback_handler_input()
578 //-----------------------------------------------------------------------------
579 OSStatus
callback_handler_input( AudioDeviceID inDevice
,
580 const AudioTimeStamp
* inNow
,
581 const AudioBufferList
* inInputData
,
582 const AudioTimeStamp
* inInputTime
,
583 AudioBufferList
* outOutputData
,
584 const AudioTimeStamp
* inOutputTime
,
587 DigitalIn
* in
= (DigitalIn
*)infoPointer
;
591 if( !in
->capture( inInputData
) )
592 return kAudioHardwareUnspecifiedError
;
594 return kAudioHardwareNoError
;
600 //-----------------------------------------------------------------------------
601 // name: initialize()
602 // desc: initialize audio in
603 //-----------------------------------------------------------------------------
604 BOOL__
DigitalIn::initialize( DWORD__ device_number
, DWORD__ num_channels
,
605 DWORD__ sampling_rate
, DWORD__ bps
,
606 DWORD__ buffer_size
, DWORD__ num_buffers
)
609 OSStatus err
= noErr
;
611 UInt32 the_buffer_size
= 0;
612 AudioStreamBasicDescription format
;
613 AudioBufferList
* buffer_list
= NULL
;
618 sprintf( msg
, "error: initialize(); DigitalIn already initialized..." );
622 // set the parameters
623 m_num_channels
= num_channels
;
624 m_sampling_rate
= sampling_rate
;
626 m_in_buffer_size
= buffer_size
;
627 m_num_in_buffers
= num_buffers
;
628 m_device_num
= device_number
;
630 // allocate the buffers
631 m_in_buffers
= new InternalBuffer
[m_num_in_buffers
];
632 for( int i
= 0; i
< m_num_in_buffers
; i
++ )
633 m_in_buffers
[i
].initialize( m_in_buffer_size
* sizeof(SAMPLE_INTERNAL
) *
636 m_curr_buffer_in
= 0;
637 m_data_ptr_in
= m_in_buffers
[0].data();
638 m_data_max_in
= m_data_ptr_in
+ m_in_buffer_size
* m_num_channels
;
640 // get the default device
641 dataSize
= sizeof( AudioDeviceID
);
642 err
= AudioHardwareGetProperty( kAudioHardwarePropertyDefaultOutputDevice
,
643 &dataSize
, &m_device_handle
);
646 sprintf( msg
, "error opening input device device..." );
650 // configure the device
651 err
= AudioDeviceGetPropertyInfo( m_device_handle
, 0, TRUE
,
652 kAudioDevicePropertyStreamConfiguration
,
654 if( err
!= noErr
|| dataSize
<= 0 )
656 sprintf( msg
, "error configuring audio device..." );
659 buffer_list
= (AudioBufferList
*)malloc(dataSize
);
660 err
= AudioDeviceGetProperty( m_device_handle
, 0, TRUE
,
661 kAudioDevicePropertyStreamConfiguration
,
662 &dataSize
, buffer_list
);
665 sprintf( msg
, "error configuring audio device..." );
669 AudioValueRange buffer_range
;
670 dataSize
= sizeof(AudioValueRange
);
671 err
= AudioDeviceGetProperty( m_device_handle
, 0, TRUE
,
672 kAudioDevicePropertyBufferSizeRange
,
673 &dataSize
, &buffer_range
);
676 sprintf( msg
, "error dealing with range" );
680 the_buffer_size
= m_in_buffer_size
* m_num_channels
* sizeof(SAMPLE_INTERNAL
);
682 // set the buffer size
683 dataSize
= sizeof(UInt32
);
684 err
= AudioDeviceSetProperty( m_device_handle
, NULL
, 0, TRUE
,
685 kAudioDevicePropertyBufferSize
,
686 dataSize
, &the_buffer_size
);
689 sprintf( msg
, "error setting buffer size '%d'", the_buffer_size
);
693 // set the sample rate
694 dataSize
= sizeof(AudioStreamBasicDescription
);
695 err
= AudioDeviceGetProperty( m_device_handle
, 0, TRUE
,
696 kAudioDevicePropertyStreamFormat
,
697 &dataSize
, &format
);
700 sprintf( msg
, "error setting sampling rate..." );
704 format
.mSampleRate
= m_sampling_rate
;
705 format
.mFormatID
= kAudioFormatLinearPCM
;
706 err
= AudioDeviceSetProperty( m_device_handle
, NULL
, 0, TRUE
,
707 kAudioDevicePropertyStreamFormat
,
711 sprintf( msg
, "error setting sampling rate '%d'", m_sampling_rate
);
715 // register callback handler
716 err
= AudioDeviceAddIOProc( m_device_handle
, callback_handler_input
, this );
719 sprintf( msg
, "error setting callback" );
729 // print out the error
741 //-----------------------------------------------------------------------------
744 //-----------------------------------------------------------------------------
745 BOOL__
DigitalIn::start()
750 // check if initialized
753 sprintf( msg
, "error: start(): DigitalIn not initialized..." );
757 // check if started already
758 if( m_capture_start
)
760 sprintf( msg
, "error: start(): DigitalIn already started..." );
765 //err = AudioDeviceStart( m_device_handle, callback_handler_input );
768 // sprintf( msg, "error starting audio device..." );
776 m_capture_start
= TRUE
;
781 // print out the error
790 //-----------------------------------------------------------------------------
791 // name: capture_stop()
793 //-----------------------------------------------------------------------------
794 BOOL__
DigitalIn::stop()
799 // check to see if started
800 if( !m_capture_start
)
802 sprintf( msg
, "error: stop(): DigitalIn not started..." );
806 err
= AudioDeviceStop( m_device_handle
, callback_handler_input
);
809 sprintf( msg
, "error stopping audio device..." );
814 m_capture_start
= FALSE
;
817 // print out the error
826 //-----------------------------------------------------------------------------
829 //-----------------------------------------------------------------------------
830 void DigitalIn::cleanup()
833 if( m_capture_start
)
841 SAFE_DELETE_ARRAY( m_in_buffers
);
850 //-----------------------------------------------------------------------------
853 //-----------------------------------------------------------------------------
854 BOOL__
DigitalIn::tick_in( SAMPLE
* s
)
856 if( !prepare_tick_in() )
859 *s
= INTERNAL_TO_SAMPLE( *m_data_ptr_in
++ );
867 //-----------------------------------------------------------------------------
870 //-----------------------------------------------------------------------------
871 BOOL__
DigitalIn::tick_in( SAMPLE
* l
, SAMPLE
* r
)
873 if( !prepare_tick_in() )
876 *l
= INTERNAL_TO_SAMPLE( *m_data_ptr_in
++ );
877 *r
= INTERNAL_TO_SAMPLE( *m_data_ptr_in
++ );
885 //-----------------------------------------------------------------------------
888 //-----------------------------------------------------------------------------
889 BOOL__
DigitalIn::tick_in( SAMPLE
* sample
, DWORD__ n
)
891 if( !prepare_tick_in() )
894 if( !n
) n
= m_num_channels
;
896 *sample
++ = INTERNAL_TO_SAMPLE( *m_data_ptr_in
++ );
904 //-----------------------------------------------------------------------------
905 // name: prepare_tick_in()
907 //-----------------------------------------------------------------------------
908 inline BOOL__
DigitalIn::prepare_tick_in()
913 if( !m_capture_start
) if( !this->start() )
916 if( m_data_ptr_in
>= m_data_max_in
)
921 //m_in_buffers[m_curr_buffer_in].clear();
922 m_curr_buffer_in
= (m_curr_buffer_in
+ 1) % m_num_in_buffers
;
923 m_data_ptr_in
= m_in_buffers
[m_curr_buffer_in
].data();
924 m_data_max_in
= m_data_ptr_in
+ m_in_buffer_size
* m_num_channels
;
935 //-----------------------------------------------------------------------------
938 //-----------------------------------------------------------------------------
939 DWORD__
DigitalIn::capture( const AudioBufferList
* buffer_list
)
944 while( m_block
>= m_num_in_buffers
)
948 memcpy( m_in_buffers
[m_in2
].data(),
949 buffer_list
->mBuffers
[0].mData
,
950 buffer_list
->mBuffers
[0].mDataByteSize
);
952 m_in2
= (m_in2
+ 1) % m_num_in_buffers
;
970 //-----------------------------------------------------------------------------
971 // name: AudioBuffer__()
973 //-----------------------------------------------------------------------------
974 AudioBuffer__::AudioBuffer__( DWORD__ size
)
977 this->initialize( size
);
981 m_data
= m_ptr_curr
= m_ptr_end
= NULL
;
988 //-----------------------------------------------------------------------------
989 // name: initialize()
991 //-----------------------------------------------------------------------------
992 BOOL__
AudioBuffer__::initialize( DWORD__ size
)
995 m_data
= (SAMPLE
*)malloc( size
* sizeof(SAMPLE
) );
1001 memset( m_data
, 0, size
* sizeof(SAMPLE
) );
1004 m_ptr_curr
= m_data
;
1005 m_ptr_end
= m_data
+ size
;
1013 //-----------------------------------------------------------------------------
1016 //-----------------------------------------------------------------------------
1017 void AudioBuffer__::cleanup()
1026 m_ptr_curr
= m_ptr_end
= NULL
;
1032 //-----------------------------------------------------------------------------
1035 //-----------------------------------------------------------------------------
1036 DWORD__
AudioBuffer__::size()
1044 //-----------------------------------------------------------------------------
1047 //-----------------------------------------------------------------------------
1048 SAMPLE
* AudioBuffer__::data()
1056 //-----------------------------------------------------------------------------
1057 // name: AudioBuffer__In()
1059 //-----------------------------------------------------------------------------
1060 AudioBuffer__In::AudioBuffer__In( DWORD__ size
)
1061 : AudioBuffer__( size
)
1067 //-----------------------------------------------------------------------------
1068 // name: ~AudioBuffer__In()
1070 //-----------------------------------------------------------------------------
1071 AudioBuffer__In::~AudioBuffer__In()
1079 //-----------------------------------------------------------------------------
1082 //-----------------------------------------------------------------------------
1083 BOOL__
AudioBuffer__In::reset()
1085 m_ptr_curr
= m_data
;
1087 return TickIn::reset();
1093 //-----------------------------------------------------------------------------
1096 //-----------------------------------------------------------------------------
1097 BOOL__
AudioBuffer__In::tick_in( SAMPLE
* s
)
1110 //-----------------------------------------------------------------------------
1113 //-----------------------------------------------------------------------------
1114 BOOL__
AudioBuffer__In::tick_in( SAMPLE
* l
, SAMPLE
* r
)
1116 if( !m_data
|| m_ptr_curr
+ 2 >= m_ptr_end
)
1128 //-----------------------------------------------------------------------------
1131 //-----------------------------------------------------------------------------
1132 BOOL__
AudioBuffer__In::tick_in( SAMPLE
* in
, DWORD__ n
)
1134 if( !m_data
|| m_ptr_curr
+ n
>= m_ptr_end
)
1138 *in
++ = *m_ptr_curr
++;
1146 //-----------------------------------------------------------------------------
1147 // name: AudioBuffer__Out()
1149 //-----------------------------------------------------------------------------
1150 AudioBuffer__Out::AudioBuffer__Out( DWORD__ size
)
1151 : AudioBuffer__( size
)
1157 //-----------------------------------------------------------------------------
1158 // name: ~AudioBuffer__Out()
1160 //-----------------------------------------------------------------------------
1161 AudioBuffer__Out::~AudioBuffer__Out()
1169 //-----------------------------------------------------------------------------
1172 //-----------------------------------------------------------------------------
1173 BOOL__
AudioBuffer__Out::reset()
1175 m_ptr_curr
= m_data
;
1177 return TickOut::reset();
1183 //-----------------------------------------------------------------------------
1186 //-----------------------------------------------------------------------------
1187 BOOL__
AudioBuffer__Out::tick_out( SAMPLE s
)
1200 //-----------------------------------------------------------------------------
1203 //-----------------------------------------------------------------------------
1204 BOOL__
AudioBuffer__Out::tick_out( SAMPLE l
, SAMPLE r
)
1206 if( !m_data
|| m_ptr_curr
+ 2 >= m_ptr_end
)
1218 //-----------------------------------------------------------------------------
1221 //-----------------------------------------------------------------------------
1222 BOOL__
AudioBuffer__Out::tick_out( const SAMPLE
* out
, DWORD__ n
)
1224 if( !m_data
|| m_ptr_curr
+ n
>= m_ptr_end
)
1228 *m_ptr_curr
++ = *out
++;
1236 //-----------------------------------------------------------------------------
1237 // name: InternalBuffer()
1238 // desc: constructor
1239 //-----------------------------------------------------------------------------
1240 InternalBuffer::InternalBuffer()
1249 //-----------------------------------------------------------------------------
1250 // name: ~InternalBuffer()
1252 //-----------------------------------------------------------------------------
1253 InternalBuffer::~InternalBuffer()
1261 //-----------------------------------------------------------------------------
1262 // name: initialize()
1264 //-----------------------------------------------------------------------------
1265 BOOL__
InternalBuffer::initialize( DWORD__ buffer_size
)
1269 // allocate the buffer
1270 if( !(m_data
= (SAMPLE_INTERNAL
*)malloc(buffer_size
)) )
1273 // set the buffer size
1274 m_size
= buffer_size
;
1277 return this->clear();
1283 //-----------------------------------------------------------------------------
1286 //-----------------------------------------------------------------------------
1287 BOOL__
InternalBuffer::clear()
1293 memset( m_data
, 0, m_size
);
1301 //-----------------------------------------------------------------------------
1304 //-----------------------------------------------------------------------------
1305 void InternalBuffer::cleanup()
1318 //-----------------------------------------------------------------------------
1320 // desc: get the buffer
1321 //-----------------------------------------------------------------------------
1322 SAMPLE_INTERNAL
* InternalBuffer::data( )
1330 //-----------------------------------------------------------------------------
1333 //-----------------------------------------------------------------------------
1334 DWORD__
InternalBuffer::size() const
1342 //-----------------------------------------------------------------------------
1344 // desc: wait for the buffer to be ready
1345 //-----------------------------------------------------------------------------
1346 void InternalBuffer::synch()
1353 //-----------------------------------------------------------------------------
1355 // desc: signal the buffer to be used again
1356 //-----------------------------------------------------------------------------
1357 void InternalBuffer::signal()
1364 //-----------------------------------------------------------------------------
1367 //-----------------------------------------------------------------------------
1368 void InternalBuffer::reset()