[Stk] Re : STK Problem
Chris B
largowhinch at googlemail.com
Fri Jun 4 02:10:27 PDT 2010
Hi,
I am still experiencing the same problems. I have understood the general
principle, writing an array 2 spaces wide an computing the 2 samples this
way, but I still can't get something simple as monophonic sound for testing
purpose. And I also can't get different signals on both speakers. I also
have a question about the code from Gregoire Davy, what is the meaning of
the pPan function? I can't find a declaration in the STK Class overview. I
am asuming that mySound is the data pointer?
Well, here is the code. Perhaps it's only a very simple mistake and I am too
blind to see it.
#include "SineWave.h"
#include "RtAudio.h"
#include "RtWvOut.h"
#include <cstdlib>
using namespace stk;
using std::min;
// This tick() function handles sample computation only. It will be
// called automatically when the system needs a new buffer of audio
// samples.
int tick_c( void *outputBuffer, void *inputBuffer, unsigned int
nBufferFrames, double streamTime, RtAudioStreamStatus status, void
*dataPointer )
{
SineWave *sine = (SineWave *) dataPointer;
register StkFloat outs[2];
register StkFloat *samples = (StkFloat *) outputBuffer;
int i,nTicks = (int) nBufferFrames;
for (i=0; i<nTicks; i++ ){
for( int h=0;h<1;h++)
{
//*samples = 0; //if it's not outcomment I get an error when exiting
the programm
outs[h] = sine->tick();
outs[h+1] = (sine->tick())*0; //Should mute the right speaker - but
it doesn't
*samples++ = outs[h];
*samples++ = outs[h+1];}
//samples++; //if it's not outcomment I get noise
}
return 0;
}//end callback function
int main()
{
// Set the global sample rate before creating class instances.
Stk::setSampleRate( 48000.0 );//Standard: 44100
SineWave sine;
RtAudio dac;
RtAudio::StreamParameters parameters;
RtAudio::DeviceInfo devInfo;
devInfo = dac.getDeviceInfo(dac.getDefaultOutputDevice() );
// Figure out how many bytes in an StkFloat and setup the RtAudio stream.
parameters.deviceId = dac.getDefaultOutputDevice();
parameters.nChannels = 2; //outputchannel = 2
parameters.firstChannel = 0;
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 :
RTAUDIO_FLOAT32;
sine.setFrequency(500);
unsigned int bufferFrames = RT_BUFFER_SIZE;
try {
dac.openStream( ¶meters, NULL, format, (unsigned
int)Stk::sampleRate(), &bufferFrames, &tick_c, (void *)&sine );
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
try {
dac.startStream();
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
// Block waiting here.
char keyhit;
std::cout << "\nPlaying ... press <enter> to quit.\n";
std::cin.get( keyhit );
// Shut down the output stream.
try {
dac.closeStream();
}
catch ( RtError &error ) {
error.printMessage();
}
cleanup:
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20100604/fb24ea78/attachment.html
More information about the Stk
mailing list