File: sineosc.cpp

package info (click to toggle)
stk 5.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,908 kB
  • sloc: cpp: 33,513; ansic: 3,216; sh: 2,900; tcl: 2,444; perl: 114; objc: 60; makefile: 54
file content (53 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// sineosc.cpp STK tutorial program

#include "FileLoop.h"
#include "FileWvOut.h"
#include <cstdlib>

using namespace stk;

int main()
{
  // Set the global sample rate before creating class instances.
  Stk::setSampleRate( 44100.0 );

  int nFrames = 100000;
  FileLoop input;
  FileWvOut output;

  try {
    // Load the sine wave file.
    input.openFile( "rawwaves/sinewave.raw", true );

    // Open a 16-bit, one-channel WAV formatted output file
    output.openFile( "hellosine.wav", 1, FileWrite::FILE_WAV, Stk::STK_SINT16 );
  }
  catch ( StkError & ) {
    exit( 1 );
  }

  input.setFrequency( 440.0 );

  // Option 1: Use StkFrames
  /*
  StkFrames frames( nFrames, 1 );
  try {
    output.tick( input.tick( frames ) );
  }
  catch ( StkError & ) {
    exit( 1 );
  }
  */

  // Option 2: Single-sample computations
  for ( int i=0; i<nFrames; i++ ) {
    try {
      output.tick( input.tick() );
    }
    catch ( StkError & ) {
      exit( 1 );
    }
  }

  return 0;
}