Advertisement
Vita94

WaveCutoff

Apr 23rd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. public bool WaveCutOff(string filePath, int[] channelValues)
  2.         {
  3.             byte[] bytes = File.ReadAllBytes(filePath);
  4.             int startOffset = DataOffset(bytes);
  5.             int dataLength = (bytes.Length - startOffset);
  6.             byte[] data = new byte[dataLength];
  7.  
  8.             int channel = 0;
  9.             int segmentCount = 0;
  10.             for(int i = 0; i < dataLength; i++)
  11.             {
  12.                 if (segmentCount >= 2)
  13.                 {
  14.                     channel++;
  15.                     segmentCount = 0;
  16.                 }
  17.                 if (channel >= channelValues.Length)
  18.                     channel = 0;
  19.  
  20.                /* if (channel == 0)
  21.                     data[i] = 255;
  22.                 else
  23.                     data[i] = 0;*/
  24.  
  25.                 data[i] = (byte)(Math.Abs(bytes[startOffset + i] - channelValues[channel]) % 255);
  26.                 segmentCount++;
  27.             }
  28.  
  29.             FileStream fstream = new FileStream(filePath + ".mod.wav", FileMode.Create);
  30.             BinaryWriter bpisac = new BinaryWriter(fstream);
  31.  
  32.             //write the header
  33.             for (int i = 0; i < startOffset; i++)
  34.                 bpisac.Write(bytes[i]);
  35.             //write the data
  36.             for (int i = 0; i < data.Length; i++)
  37.                 bpisac.Write(data[i]);
  38.  
  39.             fstream.Close();
  40.  
  41.             return true;
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement