JoelSjogren

Untitled

Sep 4th, 2017
357
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // filename "wf.cpp" (simple wave-form generator)
  2.  
  3. #include <iostream>
  4. #include <cmath>
  5. #include <stdint.h>
  6.  
  7. int main()
  8. {
  9.  
  10. const double R=8000; // sample rate (samples per second)
  11. const double C=261.625565; // frequency of middle-C (hertz)
  12. const double F=R/256; // bytebeat frequency of 1*t due to 8-bit truncation (hertz)
  13. const double V=127; // a volume constant
  14.  
  15. for ( int t=0; ; t++ )
  16. {
  17. uint8_t temp = (sin(t*2*M_PI/R*C)+1)*V; // pure middle C sine wave
  18. // uint8_t temp = t/F*C; // middle C saw wave (bytebeat style)
  19. // uint8_t temp = (t*5&t>>7)|(t*3&t>>10); // viznut bytebeat composition
  20. std::cout<<temp;
  21. }
  22.  
  23. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment