Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. public byte[] CalculateNewSound() {
  2.       ReadWavFile rwf = new ReadWavFile(pathWavFile);
  3.       byteArray = rwf.ReadWave();
  4.  
  5.       return byteArray;
  6. }
  7.  
  8. public void CalculateNewSoundshort() {
  9.             using (FileStream fs = new FileStream(pathWavFile, FileMode.Open, FileAccess.Read)) {
  10.                 using (BinaryReader br = new BinaryReader(fs)) {
  11.  
  12.                     shortArray = new short[fs.Length / 2];
  13.  
  14.                     for (int i = 0; i < fs.Length / 2; i++) {
  15.                         shortArray[i] = br.ReadInt16();
  16.                     }
  17.                 }
  18.             }
  19.         }
  20.  
  21.         public short[] Bit16Sound() {
  22.             int bytesPerSecond = (bitsPerSample * sampleRate * channel) / 16;
  23.             int actualByte = bytesPerSecond * delay;
  24.  
  25.             CalculateNewSoundshort();
  26.  
  27.             Int32 tempValue;
  28.  
  29.             int dataStart = zoekData();
  30.             int start16 = dataStart / 2;
  31.  
  32.             for (int i = start16; i < shortArray.Length; i++)
  33.             {
  34.                 if (i - start16 >= actualByte)
  35.                 {
  36.                     tempValue = (Int32)(((Int32)shortArray[i] + (Int32)shortArray[i - actualByte]) * (1.0 - demping));
  37.                     if (tempValue > 32767)
  38.                     {
  39.                         tempValue = 32767;
  40.                     }
  41.                     else if (tempValue < -32768)
  42.                     {
  43.                         tempValue = -32768;
  44.                     }
  45.                     shortArray[i] = (short)tempValue;
  46.                 }
  47.             }
  48.  
  49.             return shortArray;
  50.  
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement