Exemplo n.º 1
0
        private void SetComment(StreamState os, Stream stream)
        {
            var opusTags = new OpusTags();
            opusTags.Add("ENCODER", "opusenc from libopus 1.0.1-21-gff16ab0");
            opusTags.AddOption(_options.BitRate);
            opusTags.AddOption(_options.BitRateEncoding);
            opusTags.AddOption("ignorelength", string.Empty);

            opusTags.Pad();

            var opComment = new Packet
            {
                PacketData = opusTags.GetPacked(),
                PacketDataLength = opusTags.GetPackedLength(),
                Bos = 0,
                Eos = 0,
                GranulePos = 0
            };
            os.AddWaveData(opComment);
            os.Flush(stream);
        }
Exemplo n.º 2
0
        private void SetHeader(StreamState os, Stream stream)
        {
            UInt16 preskip = 0;

            var header = new OpusHeader(_options.OutChannels.Value, _options.OutSamplingRate, preskip);
            var op = new Packet
            {
                PacketData = header.Packet,
                PacketDataLength = header.Packet.Length,
                Bos = 1,
                Eos = 0,
                GranulePos = 0
            };
            os.AddWaveData(op);
            os.Flush(stream);
        }
Exemplo n.º 3
0
        public void AddWaveData(byte[] waveData)
        {
            var soundBuffer = new byte[waveData.Length + _notEncodedBuffer2.Length];
            Array.Copy(_notEncodedBuffer2, soundBuffer, _notEncodedBuffer2.Length);
            Array.Copy(waveData, 0, soundBuffer, _notEncodedBuffer2.Length, waveData.Length);

            uint segmentCount = (uint)Math.Floor((decimal)soundBuffer.Length / _bytesPerSegment);
            uint segmentsEnd = segmentCount * _bytesPerSegment;
            uint notEncodedCount = (uint)soundBuffer.Length - segmentsEnd;
            _notEncodedBuffer2 = new byte[notEncodedCount];
            Array.Copy(_notEncodedBuffer2, 0, soundBuffer, segmentsEnd, notEncodedCount);

            var segment = new byte[_bytesPerSegment];
            GranulePos += segmentsEnd;
            for (uint i = 0; i < segmentCount; i++)
            {
                Array.Copy(soundBuffer, i * _bytesPerSegment, segment, 0, _bytesPerSegment);
                byte[] packet;
                int length = _encoder.Encode(segment, _bytesPerSegment, out packet);

                var opData = new Packet
                {
                    PacketData = packet,
                    PacketDataLength = length,
                    Bos = 0,
                    GranulePos = GranulePos,
                };
                AddWaveData(opData);
            }
        }
Exemplo n.º 4
0
 public void AddWaveData(Packet packet)
 {
     if (packet != null)
     {
         lock (_packets)
         {
             _packets.Add(packet);
             _totalBits += (uint)packet.PacketDataLength;
         }
     }
 }
Exemplo n.º 5
0
 public void Packetin(Packet packet)
 {
     _packets.Add(packet);
     _totalBits += (uint)packet.PacketData.Length;
 }
Exemplo n.º 6
0
 internal static extern int ogg_stream_packetin(ref IntPtr os, ref Packet op);