Beispiel #1
0
        public Mp3Writer(Stream stream, int sampleRate, int bitRate, int channels, LAMEPreset preset)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (channels != 1 && channels != 2)
            {
                throw new ArgumentException(string.Format("Unsupported number of channels {0}", channels), "channels");
            }

            if (bitRate != 16)
            {
                throw new ArgumentException(string.Format("Unsupported PCM sample size {0}", bitRate), "bitRate");
            }

            if (sampleRate < 8000 || sampleRate > 48000)
            {
                throw new ArgumentException(string.Format("Unsupported Sample Rate {0}", sampleRate), "sampleRate");
            }

            _stream                = stream;
            _sampleRate            = sampleRate;
            _bitRate               = bitRate;
            _channels              = channels;
            _blockAlign            = (short)(channels * (bitRate / 8));
            _averageBytesPerSecond = sampleRate * _blockAlign;
            _preset                = preset;

            _inBuffer  = new ArrayUnion(_averageBytesPerSecond);
            _outBuffer = new byte[sampleRate * 5 / 4 + 7200];

            this._lame = new LibMp3Lame();
            this._lame.InputSampleRate = _sampleRate;
            this._lame.NumChannels     = _channels;
            this._lame.SetPreset(_preset);

            this._lame.InitParams();

            if (_channels == 1)
            {
                _encode = EncodePcm16Mono;
            }
            else
            {
                _encode = EncodePcm16stereo;
            }
        }
Beispiel #2
0
 public BenchmarkTask(string name, EncodeAction encodeAction, DecodeAction decodeAction)
 {
     Name = name;
     EncodeAction = encodeAction;
     DecodeAction = decodeAction;
 }