1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| int Attack::tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *dataPointer )
{
SineWave *sine = (SineWave *) dataPointer;
register StkFloat *samples = (StkFloat *) outputBuffer;
for ( unsigned int i=0; i<nBufferFrames; i++ )
*samples++ = sine->tick();
return 1;
}
//--------------------------------------------------------------------------------------------------------
bool Attack::play()
{
SineWave sine;
//- Figure out how many bytes in an StkFloat and setup the RtAudio stream.
RtAudio::StreamParameters p;
p.deviceId = dac.getDefaultOutputDevice();
p.nChannels = 1;//_o_->channel;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
//-The bufferFrames argument is an API-dependent buffering parameter (see RtAudio for further information).
unsigned int bufferFrames = RT_BUFFER_SIZE;//defined in Stk.h.
//--1) OPEN STREAM
try {
dac.openStream( &p, //RtAudio::StreamParameters *outputParameters,
NULL, //RtAudio::StreamParameters *inputParameters,
format, // RtAudioFormat format, unsigned int sampleRate
(unsigned int)Stk::sampleRate(), //unsigned int *bufferFrames
&bufferFrames, //RtAudioCallback callback, void *userData
&Attack::tick, //RtAudio::StreamOptions *options
(void *)&sine
);
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
sine.setFrequency( _o_->frequency );
//--2) START STREAM
try {
dac.startStream();
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
cleanup:
dac.closeStream();
//delete dac;
//_o_->func_killFM(_o_->id);
} |
Partager