Exemplo n.º 1
0
        public AudioFormat(int sampleRate, int channels, int sampleBits, bool planar = false)
        {
            SampleRate    = sampleRate;
            BitsPerSample = sampleBits == 24 ? 32 : sampleBits;
            ChannelLayout = GetDefaultChannelLayout(channels);
            switch (sampleBits)
            {
            case 8: SampleFormat = AVSampleFormat.UInt8; break;

            case 16: SampleFormat = AVSampleFormat.Int16; break;

            case 24: SampleFormat = AVSampleFormat.Int32; break;

            case 32: SampleFormat = AVSampleFormat.Float; break;

            case 64: SampleFormat = AVSampleFormat.Double; break;

            default: throw new ArgumentException($"不支持的采样位数:{sampleBits}");
            }
            if (planar)
            {
                SampleFormat = SampleFormat.ToPlanar();
            }
            ValidBitsPerSample = SampleFormat.EqualsType(AVSampleFormat.Int32) ? 24 : BitsPerSample;
        }
Exemplo n.º 2
0
 public AudioFormat ToPlanar()
 {
     return(new AudioFormat(SampleRate, ChannelLayout, SampleFormat.ToPlanar()));
 }