code_junkie

Creating sine or square wave in C#

Nov 11th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. int sampleRate = 8000;
  2. short[] buffer = new short[8000];
  3. double amplitude = 0.25 * short.MaxValue;
  4. double frequency = 1000;
  5. for (int n = 0; n < buffer.Length; n++)
  6. {
  7. buffer[n] = (short)(amplitude * Math.Sin((2 * Math.PI * n * frequency) / sampleRate));
  8. }
  9.  
  10. d= 40000; //fundamental freq of sine/sample rate
  11.  
  12. for (int n = 0; n < d; n++)
  13. {
  14. buffer[n] = (short)(amplitude * Math.Sin((2 * Math.PI * n * ) / d);
  15. }
Add Comment
Please, Sign In to add comment