This project has moved. For the latest updates, please go here.

Audio Format IEEE 64 bits

Oct 19, 2012 at 7:40 PM

I think the NAudio library does not support the audio format IEEE 64bit, so here is my modest contribution by adding a class WaveToSampleProvider64 and a small change in the class SampleProviderConverters.

using System;

namespace NAudio.Wave.SampleProviders
{
    /// <summary>
    /// Helper class turning an already 64 bit floating point IWaveProvider
    /// into an ISampleProvider - hopefully not needed for most applications
    /// </summary>
    public class WaveToSampleProvider64 : SampleProviderConverterBase
    {
        /// <summary>
        /// Initializes a new instance of the WaveToSampleProvider class
        /// </summary>
        /// <param name="source">Source wave provider, must be IEEE float</param>
        public WaveToSampleProvider64(IWaveProvider source)
            : base(source)
        {
            if (source.WaveFormat.Encoding != WaveFormatEncoding.IeeeFloat)
            {
                throw new ArgumentException("Must be already floating point");
            }
        }

        /// <summary>
        /// Reads from this provider
        /// </summary>
        public override int Read(float[] buffer, int offset, int count)
        {
            int bytesNeeded = count * 8;
            EnsureSourceBuffer(bytesNeeded);
            int bytesRead = source.Read(sourceBuffer, 0, bytesNeeded);
            int samplesRead = bytesRead / 8;
            int outputIndex = offset;
            for (int n = 0; n < bytesRead; n+=8)
            {
		long sample64 = BitConverter.ToInt64(sourceBuffer, n);
                buffer[outputIndex++] = (float)BitConverter.Int64BitsToDouble(sample64);
            }
            return samplesRead;
        }
    }
}

and modify class SampleProviderConverters

else if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
{
	if (waveProvider.WaveFormat.BitsPerSample == 64)
		sampleProvider = new WaveToSampleProvider64(waveProvider);
	else
		sampleProvider = new WaveToSampleProvider(waveProvider);
}
else
{
    throw new ArgumentException("Unsupported source encoding");
}


Best Regards, Manu.N

Coordinator
Oct 21, 2012 at 8:17 AM

thanks for this. Have you tested them?

Oct 21, 2012 at 8:41 AM

Yes, of course, the audio is correct.

But may need to adjust the Length and Position property based.

Coordinator
Oct 21, 2012 at 4:11 PM

thanks, this is checked in

Oct 21, 2012 at 6:06 PM
Edited Oct 21, 2012 at 6:06 PM

Ok, :-)

I tested the length and position properties in your demo part.

The properties work correctly.