Ejemplo n.º 1
0
 public void Close()
 {
     if (!closed)
     {
         try
         {
             uint EncodedSize = 0;
             if (m_InBufferPos > 0)
             {
                 if (Lame_encDll.EncodeChunk(m_hLameStream, m_InBuffer, 0, (uint)m_InBufferPos, m_OutBuffer, ref EncodedSize) == Lame_encDll.BE_ERR_SUCCESSFUL)
                 {
                     if (EncodedSize > 0)
                     {
                         //base.Write(m_OutBuffer, 0, (int)EncodedSize);
                     }
                 }
             }
             EncodedSize = 0;
             if (Lame_encDll.beDeinitStream(m_hLameStream, m_OutBuffer, ref EncodedSize) == Lame_encDll.BE_ERR_SUCCESSFUL)
             {
                 if (EncodedSize > 0)
                 {
                     //base.Write(m_OutBuffer, 0, (int)EncodedSize);
                 }
             }
         }
         finally
         {
             Lame_encDll.beCloseStream(m_hLameStream);
         }
     }
     closed = true;
     //base.Close();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Send to the compressor an array of bytes.
        /// </summary>
        /// <param name="buffer">Input buffer</param>
        /// <param name="index">Start position</param>
        /// <param name="count">Bytes to process. The optimal size, to avoid buffer copy, is a multiple of <see cref="yeti.mmedia.utils.AudioFileWriter.OptimalBufferSize"/></param>
        public void Write(byte[] buffer, int index, int count)
        {
            int  ToCopy      = 0;
            uint EncodedSize = 0;
            uint LameResult;

            while (count > 0)
            {
                if (m_InBufferPos > 0)
                {
                    ToCopy = Math.Min(count, m_InBuffer.Length - m_InBufferPos);
                    Buffer.BlockCopy(buffer, index, m_InBuffer, m_InBufferPos, ToCopy);
                    m_InBufferPos += ToCopy;
                    index         += ToCopy;
                    count         -= ToCopy;
                    if (m_InBufferPos >= m_InBuffer.Length)
                    {
                        m_InBufferPos = 0;
                        if ((LameResult = Lame_encDll.EncodeChunk(m_hLameStream, m_InBuffer, m_OutBuffer, ref EncodedSize)) == Lame_encDll.BE_ERR_SUCCESSFUL)
                        {
                            if (EncodedSize > 0)
                            {
                                DataAvailable = (int)EncodedSize;
                                //base.Write(m_OutBuffer, 0, (int)EncodedSize);
                            }
                        }
                        else
                        {
                            throw new ApplicationException(string.Format("Lame_encDll.EncodeChunk failed with the error code {0}", LameResult));
                        }
                    }
                }
                else
                {
                    if (count >= m_InBuffer.Length)
                    {
                        if ((LameResult = Lame_encDll.EncodeChunk(m_hLameStream, buffer, index, (uint)m_InBuffer.Length, m_OutBuffer, ref EncodedSize)) == Lame_encDll.BE_ERR_SUCCESSFUL)
                        {
                            if (EncodedSize > 0)
                            {
                                DataAvailable = (int)EncodedSize;
                                //base.Write(m_OutBuffer, 0, (int)EncodedSize);
                            }
                        }
                        else
                        {
                            throw new ApplicationException(string.Format("Lame_encDll.EncodeChunk failed with the error code {0}", LameResult));
                        }
                        count -= m_InBuffer.Length;
                        index += m_InBuffer.Length;
                    }
                    else
                    {
                        Buffer.BlockCopy(buffer, index, m_InBuffer, 0, count);
                        m_InBufferPos = count;
                        index        += count;
                        count         = 0;
                    }
                }
            }
        }