Advertisement
ada1711

Untitled

Oct 27th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. using NAudio.Wave;
  2. using NAudio.Wave.SampleProviders;
  3.  
  4. //star wars
  5. int[] melody = { 440, 440, 440, 349, 523, 440, 349, 523, 440, 0, 659, 659, 659, 698, 523, 415, 349, 523, 440, 0, 880, 880, 440, 440, 880, 831, 784, 698, 740, 0, 622, 659, 415, 440, 523, 0, 440, 523, 440, 0 };
  6.  
  7. int[] durationTime = { 500, 500, 500, 350, 150, 500, 350, 150, 650, 500, 500, 500, 500, 350, 150, 500, 350, 150, 650, 500, 500, 500, 350, 150, 500, 350, 150, 650, 150, 500, 150, 500, 150, 1000, 500, 350, 150, 500, 350, 150, 650 };
  8.  
  9. using (var waveOut = new WaveOutEvent())
  10. {
  11. for (int i = 0; i < melody.Length; i++)
  12. {
  13. if (melody[i] != 0)
  14. {
  15. var sineWave = new SignalGenerator()
  16. {
  17. Gain = 0.2,
  18. Frequency = melody[i],
  19. Type = SignalGeneratorType.Sin
  20. }.Take(TimeSpan.FromMilliseconds(durationTime[i]));
  21.  
  22. waveOut.Init(sineWave);
  23. waveOut.Play();
  24. while (waveOut.PlaybackState == PlaybackState.Playing)
  25. {
  26. Thread.Sleep(10);
  27. }
  28. }
  29. else
  30. {
  31. Thread.Sleep(durationTime[i]);
  32. }
  33. }
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. //Mario Bros
  42. int[] melody = { 659, 659, 0, 659, 0, 523, 659, 0, 784, 0, 392, 0, 523, 0, 392, 0, 330, 0, 440, 494, 0, 466, 0, 440, 0, 392, 659, 0, 784, 780, 0, 784, 0, 659, 0, 523, 587, 0, 494, 0, 523, 0, 392, 0, 330, 0, 440, 494, 0, 466, 0, 440, 0 };
  43.  
  44. int[] durationTime = { 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 400, 200, 200, 200, 400, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 400, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 };
  45.  
  46. using (var waveOut = new WaveOutEvent())
  47. {
  48. for (int i = 0; i < melody.Length; i++)
  49. {
  50. if (melody[i] != 0)
  51. {
  52. var sineWave = new SignalGenerator()
  53. {
  54. Gain = 0.2,
  55. Frequency = melody[i],
  56. Type = SignalGeneratorType.Sin
  57. }.Take(TimeSpan.FromMilliseconds(durationTime[i]));
  58.  
  59. waveOut.Init(sineWave);
  60. waveOut.Play();
  61. while (waveOut.PlaybackState == PlaybackState.Playing)
  62. {
  63. Thread.Sleep(10);
  64. }
  65. }
  66. else
  67. {
  68. Thread.Sleep(durationTime[i]);
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement