I wrote a class for reading WAV files in C# but I cant get it to work.

npsiegfried 1 Reputation point
2022-08-27T13:47:19.68+00:00

The error is 'does not contain a contructor that takes one argument'.

I tried WavReader reader = new WavReader(@"")

Here is the class I wrote...

using System;
using System.IO;

namespace WAV2MP3  
{  
    public class WavReader  
    {  
        private Int32 chunkID;  
        private Int32 chunkSize;  
        private Int32 format;  
        private Int32 subchunk1ID;  
        private Int32 subchunk1Size;  
        private Int16 audioFormat;  
        private Int16 numberOfChannels;  
        private Int32 sampleRate;  
        private Int32 byteRate;  
        private Int16 blockAlign;  
        private Int16 bitsPerSample;  
        private Int32 subchunk2ID;  
        private Int32 subchunk2Size;  
        private Int32 data;  
  
        public void New(string fileName)  
        {  
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);  
            BinaryReader br = new BinaryReader(fs);  
  
            chunkID = br.ReadInt32();  
            chunkSize = br.ReadInt32();  
            format = br.ReadInt32();  
            subchunk1ID = br.ReadInt32();  
            subchunk1Size = br.ReadInt32();  
            audioFormat = br.ReadInt16();  
            numberOfChannels = br.ReadInt16();  
            sampleRate = br.ReadInt32();  
            byteRate = br.ReadInt32();  
            blockAlign = br.ReadInt16();  
            bitsPerSample = br.ReadInt16();  
            subchunk2ID = br.ReadInt32();  
            subchunk2Size = br.ReadInt32();  
            data = br.ReadInt32();  
  
            br.Close();  
            fs.Close();  
        }  
  
        public Int32 ChunkID  
        {  
            get { return chunkID; }  
        }  
  
        public Int32 ChunkSize  
        {  
            get { return chunkSize; }  
        }  
  
        public Int32 Format  
        {  
            get { return format; }  
        }  
  
        public Int32 Subchunk1ID  
        {  
            get { return subchunk1ID; }  
        }  
  
        public Int32 Subchunk1Size  
        {  
            get { return subchunk1Size; }  
        }  
  
        public Int16 AudioFormat  
        {  
            get { return audioFormat; }  
        }  
  
        public Int16 NumberOfChannels  
        {  
            get { return numberOfChannels; }  
        }  
  
        public Int32 SampleRate  
        {  
            get { return sampleRate; }  
        }  
  
        public Int32 ByteRate  
        {  
            get { return byteRate; }  
        }  
  
        public Int16 BlockAlign  
        {  
            get { return blockAlign; }  
        }  
  
        public Int16 BitsPerSample  
        {  
            get { return bitsPerSample; }  
        }  
  
        public Int32 Subchunk2ID  
        {  
            get { return subchunk2ID; }  
        }  
  
        public Int32 Subchunk2Size  
        {  
            get { return subchunk2Size; }  
        }  
  
        public Int32 Data // same as subchunk2Size  
        {  
            get { return subchunk2Size; }  
        }  
    }  
}  

  
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-08-27T14:14:17.71+00:00

    Try replacing public void New(string fileName) with public WavReader(string fileName).

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.