Guest User

Untitled

a guest
Mar 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. audioFile.Read(buffer, 0, numSamples);
  2.  
  3. using System;
  4. using NAudio.Wave;
  5.  
  6. namespace NAudioTest
  7. {
  8. class TestPlayer
  9. {
  10. static void Main(string[] args)
  11. {
  12. string infileName = "c:\temp\pink.wav";
  13. string outfileName = "c:\temp\pink_out.wav";
  14.  
  15. // load the file
  16. var audioFile = new AudioFileReader(infileName);
  17.  
  18. // play the file
  19. var outputDevice = new WaveOutEvent();
  20. outputDevice.Init(audioFile);
  21. outputDevice.Play();
  22. //Since Play only means "start playing" and isn't blocking, we can wait in a loop until playback finishes....
  23. while (outputDevice.PlaybackState == PlaybackState.Playing) { System.Threading.Thread.Sleep(1000); }
  24.  
  25. // edit the samples in file
  26. int fs = audioFile.WaveFormat.SampleRate;
  27. int numSamples = (int)audioFile.Length / sizeof(float); // length is the number of bytes - 4 bytes in a float
  28.  
  29. float[] buffer = new float[numSamples];
  30. audioFile.Read(buffer, 0, numSamples);
  31.  
  32. float volume = 0.5f;
  33. for (int n = 0; n < numSamples; n++) { buffer[n] *= volume; }
  34.  
  35. // write edited samples to new file
  36. var writer = new WaveFileWriter(outfileName,audioFile.WaveFormat);
  37. writer.WriteSamples(buffer,0,numSamples);
  38. }
  39. }
Add Comment
Please, Sign In to add comment