[Stk] Stk examples on OSX 10.4.2

Daniel Bisig dbisig@ifi.unizh.ch
Thu, 20 Oct 2005 17:53:53 +0200


Hi Gary,

> The current release of STK was developed on 10.4.2 (also on a 1.67  
> MHz Powerbook).  Can you provide further information?  Are you  
> getting error messages?  Do the programs seem to be running fine  
> but you are simply not hearing anything?

in all these cases the programs run just fine but don't produce  
audible output. I managed to modify some of the examples in such a  
way, that I can hear something. One of the issues involved seems to  
be the number of channels I pass to the RtAudio constructor.

I send you my modified code for the rtsine example which now works  
fine on my machine at the end of this email. By applying similar  
modifications I also managed to get audible output from the grains  
example. I hope you can make some sense out of these changes.

Thanks and best regards

         Daniel

--------------------------

#include <iostream.h>
#include "RtAudio.h"
#include "SineWave.h"

StkFrames frames;
StkFrames frames2;

// Two-channel sawtooth wave generator.
int sawtooth(char *buffer, int bufferSize, void *data)
{
   SineWave* sine = (SineWave *) data;
   float tickValue;
   int i, j;
   double *my_buffer = (double *) buffer;

frames2 = sine->tick( frames );

   for(int i=0, bufIndex = 0; i<bufferSize; i++)
   {
       if(i < 10) cout << i << " frame1 " << frames[i] << " frame2 "  
<< frames2[i] << "\n";

        for(j=0; j<2; j++, bufIndex++)
       {
         my_buffer[bufIndex] = frames[i];
       }

   }

   return 0;
}

int main()
{
   int channels = 2;
   int sampleRate = 44100;
   int bufferSize = 256;  // 256 sample frames
   int nBuffers = 4;      // number of internal buffers used by device
   int device = 0;        // 0 indicates the default or first  
available device
   char input;
   RtAudio *audio = 0;

   // Open a stream during RtAudio instantiation
   try {
     audio = new RtAudio(device, channels, 0, 0, RTAUDIO_FLOAT64,
                         sampleRate, &bufferSize, nBuffers);
   }
   catch (RtError &error) {
     error.printMessage();
     exit(EXIT_FAILURE);
   }

   // Resize the StkFrames object appropriately.
   frames.resize( bufferSize, 1 );
   frames2.resize( bufferSize, 1 );

   SineWave sine;
   sine.setFrequency(440.0);

   try {
     // Set the stream callback function
     audio->setStreamCallback(&sawtooth, (void *)&sine);

     // Start the stream
     audio->startStream();
   }
   catch (RtError &error) {
     error.printMessage();
     goto cleanup;
   }

   std::cout << "\nPlaying ... press <enter> to quit.\n";
   std::cin.get(input);

   try {
     // Stop and close the stream
     audio->stopStream();
     audio->closeStream();
   }
   catch (RtError &error) {
     error.printMessage();
   }

cleanup:
   delete audio;

   return 0;
}