mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Version 4.3.0
This commit is contained in:
committed by
Stephen Sinclair
parent
2cbce2d8bd
commit
27d9b79dc7
@@ -8,12 +8,13 @@
|
||||
// This tick() function handles sample computation only. It will be
|
||||
// called automatically when the system needs a new buffer of audio
|
||||
// samples.
|
||||
int tick(char *buffer, int bufferSize, void *dataPointer)
|
||||
int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
|
||||
double streamTime, RtAudioStreamStatus status, void *dataPointer )
|
||||
{
|
||||
Granulate *grani = (Granulate *) dataPointer;
|
||||
register StkFloat *samples = (StkFloat *) buffer;
|
||||
register StkFloat *samples = (StkFloat *) outputBuffer;
|
||||
|
||||
for ( int i=0; i<bufferSize; i++ )
|
||||
for ( unsigned int i=0; i<nBufferFrames; i++ )
|
||||
*samples++ = grani->tick();
|
||||
|
||||
return 0;
|
||||
@@ -49,7 +50,7 @@ int main( int argc, char *argv[] )
|
||||
// Set the global sample rate before creating class instances.
|
||||
Stk::setSampleRate( 44100.0 );
|
||||
|
||||
RtAudio *dac = 0;
|
||||
RtAudio dac;
|
||||
Granulate grani;
|
||||
grani.setRandomFactor( random );
|
||||
grani.setStretch( stretch );
|
||||
@@ -63,22 +64,24 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
grani.setVoices( N );
|
||||
|
||||
// Figure out how many bytes in an StkFloat and setup the RtAudio object.
|
||||
// Figure out how many bytes in an StkFloat and setup the RtAudio stream.
|
||||
RtAudio::StreamParameters parameters;
|
||||
parameters.deviceId = dac.getDefaultOutputDevice();
|
||||
parameters.nChannels = 1;
|
||||
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
|
||||
int bufferSize = RT_BUFFER_SIZE;
|
||||
unsigned int bufferFrames = RT_BUFFER_SIZE;
|
||||
try {
|
||||
dac = new RtAudio(0, 1, 0, 0, format, (int)Stk::sampleRate(), &bufferSize, 4);
|
||||
dac.openStream( ¶meters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick, (void *)&grani );
|
||||
}
|
||||
catch (RtError& error) {
|
||||
catch ( RtError &error ) {
|
||||
error.printMessage();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
try {
|
||||
dac->setStreamCallback(&tick, (void *)&grani);
|
||||
dac->startStream();
|
||||
dac.startStream();
|
||||
}
|
||||
catch (RtError &error) {
|
||||
catch ( RtError &error ) {
|
||||
error.printMessage();
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -87,19 +90,17 @@ int main( int argc, char *argv[] )
|
||||
// Block waiting here.
|
||||
char keyhit;
|
||||
std::cout << "\nPlaying ... press <enter> to quit.\n";
|
||||
std::cin.get(keyhit);
|
||||
std::cin.get( keyhit );
|
||||
|
||||
// Shut down the callback and output stream.
|
||||
try {
|
||||
dac->cancelStreamCallback();
|
||||
dac->closeStream();
|
||||
dac.closeStream();
|
||||
}
|
||||
catch (RtError &error) {
|
||||
catch ( RtError &error ) {
|
||||
error.printMessage();
|
||||
}
|
||||
|
||||
cleanup:
|
||||
delete dac;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user