0
votes

I am using this section of code in my C# program which I found on this stackoverflow thread.

using (WaveFileReader reader = new WaveFileReader("myfile.wav"))
{
    Assert.AreEqual(16, reader.WaveFormat.BitsPerSample, "Only works with 16 bit audio");
    byte[] buffer = new byte[reader.Length];
    int read = reader.Read(buffer, 0, buffer.Length);
    short[] sampleBuffer = new short[read / 2];
    Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);
}

The code uses NAudio, so I have referenced the libary and added using NAudio.Wave; but I am receiving the error: The name 'Assert' does not exist in the current context.

How can i fix this?

This may have been better as a comment but I do not have enough reputation to do so

2

2 Answers

1
votes

Assert is a function from XUnit.

Add that reference. And add the using directive.

using Xunit;

1
votes

The Assert.AreEqual in that code is from NUnit, but taking a dependency on a unit testing framework is completely unnecessary in production code. If you want the check, just throw some kind of exception if it doesn't match. For example:

if (reader.WaveFormat.BitsPerSample != 16)
    throw new NotSupportedException("Only works with 16 bit audio");