Hi,<br>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?<br>
<br>Well, here is the code. Perhaps it's only a very simple mistake and I am too blind to see it.<br>
<br>#include "SineWave.h"<br>#include "RtAudio.h"<br>#include "RtWvOut.h"<br>#include <cstdlib><br><br>using namespace stk;<br>using std::min;<br>// This tick() function handles sample computation only. It will be<br>
// called automatically when the system needs a new buffer of audio<br>// samples.<br>int tick_c( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *dataPointer )<br>
{<br> SineWave *sine = (SineWave *) dataPointer;<br> register StkFloat outs[2];<br> register StkFloat *samples = (StkFloat *) outputBuffer;<br> int i,nTicks = (int) nBufferFrames;<br> <br> for (i=0; i<nTicks; i++ ){<br>
for( int h=0;h<1;h++)<br> {<br> //*samples = 0; //if it's not outcomment I get an error when exiting the programm<br> outs[h] = sine->tick();<br> outs[h+1] = (sine->tick())*0; //Should mute the right speaker - but it doesn't<br>
*samples++ = outs[h];<br> *samples++ = outs[h+1];}<br> //samples++; //if it's not outcomment I get noise<br> }<br> return 0;<br>}//end callback function<br><br><br>int main()<br>{<br> // Set the global sample rate before creating class instances.<br>
Stk::setSampleRate( 48000.0 );//Standard: 44100<br> SineWave sine;<br> RtAudio dac;<br><br> RtAudio::StreamParameters parameters;<br> RtAudio::DeviceInfo devInfo;<br> devInfo = dac.getDeviceInfo(dac.getDefaultOutputDevice() );<br>
<br> // Figure out how many bytes in an StkFloat and setup the RtAudio stream.<br> parameters.deviceId = dac.getDefaultOutputDevice();<br> parameters.nChannels = 2; //outputchannel = 2<br> parameters.firstChannel = 0;<br>
RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;<br> sine.setFrequency(500);<br> <br> unsigned int bufferFrames = RT_BUFFER_SIZE;<br><br> try {<br> dac.openStream( &parameters, NULL, format, (unsigned int)Stk::sampleRate(), &bufferFrames, &tick_c, (void *)&sine ); <br>
}<br> catch ( RtError &error ) {<br> error.printMessage();<br> goto cleanup;<br> }<br> try {<br> dac.startStream();<br> }<br> catch ( RtError &error ) {<br> error.printMessage();<br> goto cleanup;<br>
}<br><br> // Block waiting here.<br> char keyhit;<br> std::cout << "\nPlaying ... press <enter> to quit.\n";<br> std::cin.get( keyhit );<br><br> // Shut down the output stream.<br> try {<br>
dac.closeStream();<br>
}<br> catch ( RtError &error ) {<br> error.printMessage();<br> }<br><br> cleanup:<br><br> return 0;<br>}<br>