简体   繁体   中英

C# equivalent for Java's AudioFormat.isBigEndian and AudioFormat.Encoding.PCM_SIGNED

I am having hard time trying to port some Java code to C# for my simple project. The Java code makes use of format.isBigEndian and checks if the audio file data is signed or not. My C# project makes use of NAudio for handling audio files.

Here is the Java code

 public void LoadAudioStream(AudioInputStream inputStream) {
    AudioFormat format = inputStream.getFormat();
    sampleRate = (int) format.getSampleRate();
    bigEndian = format.isBigEndian();
    AudioFormat.Encoding encoding = format.getEncoding();
    if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED))
        dataIsSigned = true;
    else if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED))
        dataIsSigned = false;
}

and the C# code that I am working with..

     public void LoadAudioStream(WaveFileReader reader)
   {
       var format = reader.WaveFormat;
       sampleRate = format.SampleRate;
       //bigEndian = ??
       var encoding = format.Encoding;
       if (encoding.Equals( /*????*/))
       {
           dataIsSigned = true;
       }
       else if (encoding.Equals( /*?????*/))
       {
           dataIsSigned = false;
       }
   }

How can I check if the Audio file data is big-endian or not? and lastly is there a way to check if the AudioFormat is PCM signed or unsigned ?

PCM WAV files use little endian. The most common bit depth is 16 bit, and this will be signed (ie short or Int16 in C#).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM