32BitWaveFile

Sep 21, 2016 at 10:39 AM
I have a 32 Bit Wavefile. I read the byteArray

//RiffWave header and so on
byteArray = reader.ReadBytes(bytes);

and as discribied in the documentation i add audio, using the byteArray (quick andy dirty):

var audioStream = writer.AddAudioStream(channelCount: 2, samplesPerSecond: 44100, bitsPerSample: 32);
var audioByteRate = (audioStream.BitsPerSample / 8) * audioStream.ChannelCount * audioStream.SamplesPerSecond;
var audioBlockSize = (int)(audioByteRate / writer.FramesPerSecond);

while(...)
{
audioStream.WriteBlock(byteArray, 0, audioBlockSize);
List<byte> dummy = byteArray.ToList();
dummy.RemoveRange(0, audioBlockSize);
byteArray = dummy.ToArray();
}

But the tone is distorted.

What should i do?

Best regards
Coordinator
Sep 26, 2016 at 9:52 AM
Hi
I think you might translate the params of your WAV incorrectly. Notice that bitsPerSample argument refers to a sample of a single audio channel. I suppose 32 bits of your WAV denotes a bit count of combined stereo sample, i.e. 16 bits per channel.
Sep 26, 2016 at 11:12 AM
Hi, thank you for your answer.
No, my WAV is a 32bit-WAV with float (32 bit) instead of 16 bit-integer for each channel.


ByteArray = reader.ReadBytes(Bytes);
...
float[] asFloat = new float[Samps];
Buffer.BlockCopy(ByteArray, 0, asFloat, 0, Bytes); //static method
...
L = new List<float>();
R = new List<float>();

for (int i = 0; i < Samps; i++)
{
L.Add(asFloat[i++]);
R.Add(asFloat[i]);
}

I work with the Lists L and R. There are plausible floats.



The ByteArray is the native stream out of the WAV and this ByteArray i use in the while-loop.

var audioStream = writer.AddAudioStream(channelCount: 2, samplesPerSecond: 44100, bitsPerSample: 32);
var audioByteRate = (audioStream.BitsPerSample / 8) * audioStream.ChannelCount * audioStream.SamplesPerSecond;
var audioBlockSize = (int)(audioByteRate / writer.FramesPerSecond);
....
while(...)
{
audioStream.WriteBlock(ByteArray, 0, audioBlockSize);
List<byte> dummy = ByteArray.ToList();
dummy.RemoveRange(0, audioBlockSize);
ByteArray = dummy.ToArray();
}
Coordinator
Sep 26, 2016 at 12:09 PM
Edited Sep 26, 2016 at 12:10 PM
OK, I see.
SharpAvi is intended as a low-level library for AVI, so there are only a few video/audio formats out of the box. But there are means to add support for other formats on top of it.
PCM float differs from PCM integer (which is the default for audio streams in SharpAVI) in format number. Try to add the following after creating an audio stream:
audioStream.Format = 3;
Maybe, this is the only modification needed to support PCM float.
Sep 29, 2016 at 8:14 AM
Thank you :) This works.