Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int DataOffset(byte[] data)
- {
- int offset = 0;
- try
- {
- //finding the start of data
- while (true)
- {
- if (data[offset] == 'd' && data[offset + 1] == 'a' && data[offset + 2] == 't' && data[offset + 3] == 'a')
- break;
- offset++;
- }
- return offset + 4 + 4; //move to the offset of the start of the data two fields DATA and DataSize both 4 bytes
- }
- catch
- {
- return 0; // not found
- }
- }
- public bool WaveCutOff(string filePath, int[] channelValues)
- {
- byte[] bytes = File.ReadAllBytes(filePath);
- int startOffset = DataOffset(bytes);
- int dataLength = (bytes.Length - startOffset);
- byte[] data = new byte[dataLength];
- int channel = 0;
- int segmentCount = 0;
- for(int i = 0; i < dataLength; i++)
- {
- if (segmentCount >= 2)
- {
- channel++;
- segmentCount = 0;
- }
- if (channel >= channelValues.Length)
- channel = 0;
- /* if (channel == 0)
- data[i] = 255;
- else
- data[i] = 0;*/
- data[i] = (byte)(Math.Abs(bytes[startOffset + i] - channelValues[channel]) % 255);
- segmentCount++;
- }
- FileStream fstream = new FileStream(filePath + ".mod.wav", FileMode.Create);
- BinaryWriter bpisac = new BinaryWriter(fstream);
- //write the header
- for (int i = 0; i < startOffset; i++)
- bpisac.Write(bytes[i]);
- //write the data
- for (int i = 0; i < data.Length; i++)
- bpisac.Write(data[i]);
- fstream.Close();
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement