You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
984B

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