1 // sineosc.cpp STK tutorial program
2 
3 #include "FileLoop.h"
4 #include "FileWvOut.h"
5 #include <cstdlib>
6 
7 using namespace stk;
8 
9 int main()
10 {
11   // Set the global sample rate before creating class instances.
12   Stk::setSampleRate( 44100.0 );
13 
14   int nFrames = 100000;
15   FileLoop input;
16   FileWvOut output;
17 
18   try {
19     // Load the sine wave file.
20     input.openFile( "rawwaves/sinewave.raw", true );
21 
22     // Open a 16-bit, one-channel WAV formatted output file
23     output.openFile( "hellosine.wav", 1, FileWrite::FILE_WAV, Stk::STK_SINT16 );
24   }
25   catch ( StkError & ) {
26     exit( 1 );
27   }
28 
29   input.setFrequency( 440.0 );
30 
31   // Option 1: Use StkFrames
32   /*
33   StkFrames frames( nFrames, 1 );
34   try {
35     output.tick( input.tick( frames ) );
36   }
37   catch ( StkError & ) {
38     exit( 1 );
39   }
40   */
41 
42   // Option 2: Single-sample computations
43   for ( int i=0; i<nFrames; i++ ) {
44     try {
45       output.tick( input.tick() );
46     }
47     catch ( StkError & ) {
48       exit( 1 );
49     }
50   }
51 
52   return 0;
53 }
54