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.

55 lines
918B

  1. // rtsine.cpp STK tutorial program
  2. #include "SineWave.h"
  3. #include "RtWvOut.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. Stk::showWarnings( true );
  11. int nFrames = 100000;
  12. SineWave sine;
  13. RtWvOut *dac = 0;
  14. try {
  15. // Define and open the default realtime output device for one-channel playback
  16. dac = new RtWvOut( 1 );
  17. }
  18. catch ( StkError & ) {
  19. exit( 1 );
  20. }
  21. sine.setFrequency( 441.0 );
  22. // Option 1: Use StkFrames
  23. /*
  24. StkFrames frames( nFrames, 1 );
  25. try {
  26. dac->tick( sine.tick( frames ) );
  27. }
  28. catch ( StkError & ) {
  29. goto cleanup;
  30. }
  31. */
  32. // Option 2: Single-sample computations
  33. for ( int i=0; i<nFrames; i++ ) {
  34. try {
  35. dac->tick( sine.tick() );
  36. }
  37. catch ( StkError & ) {
  38. goto cleanup;
  39. }
  40. }
  41. cleanup:
  42. delete dac;
  43. return 0;
  44. }