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

WaveFormat.CreateCustomFormat() cannot be accessed with an instance reference

Feb 13, 2014 at 12:07 PM
Edited Feb 13, 2014 at 12:19 PM
I'm a bit confused as to why this is happening..

I need to create a custom WaveFormat due to AAC SBR samplerate doubling, but I'm getting the compile error below. It doesn't tell me which parameter is in question. Instead of parsing "goodframe" vars I've created local int's but still no luck.

Member 'NAudio.Wave.WaveFormat.CreateCustomFormat(NAudio.Wave.WaveFormatEncoding, int, int, int, int, int)' cannot be accessed with an instance reference; qualify it with a type name instead (CS0176)
private void InitializeADTSStream()
{
            ....
            ....
            int blockAlign = goodFrame.ChannelsOutput * (16 / 8);
            int sampleRate = goodFrame.SampleRateOutput;
            int channels = goodFrame.ChannelsOutput;
            int avgBytes = sampleRate * blockAlign;

            // WaveFormat outputWaveFormat is a global variable in the class
            outputWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, sampleRate, channels, avgBytes, blockAlign, 16);
}
Removing "outputWaveFormat = " before "WaveFormat.CreateCustomFormat" makes no difference.

NAudio source:
        public static WaveFormat CreateCustomFormat(WaveFormatEncoding tag, int sampleRate, int channels, int averageBytesPerSecond, int blockAlign, int bitsPerSample)
        {
            WaveFormat waveFormat = new WaveFormat();
            waveFormat.waveFormatTag = tag;
            waveFormat.channels = (short)channels;
            waveFormat.sampleRate = sampleRate;
            waveFormat.averageBytesPerSecond = averageBytesPerSecond;
            waveFormat.blockAlign = (short)blockAlign;
            waveFormat.bitsPerSample = (short)bitsPerSample;
            waveFormat.extraSize = 0;
            return waveFormat;
        }
Feb 13, 2014 at 12:22 PM
Edited Feb 13, 2014 at 12:26 PM
Nevermind, problem solved.

The WaveFormat in my class was conflicting with NAudio.Wave.WaveFormat

// Solution
outputWaveFormat = NAudio.Wave.WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, sampleRate, channels, avgBytes, blockAlign, 16);


You may delete this thread Mark