Ejemplo n.º 1
0
        public AudioDecoder(DecoderSettings settings, string path, Stream IO)
        {
            m_settings = settings;

            _path = path;

            m_stream   = (IO != null) ? IO : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
            m_StreamIO = new StreamIO(m_stream);

            int errorCode = 0;

            pAPEDecompress = MACLibDll.c_APEDecompress_CreateEx(m_StreamIO.CIO, out errorCode);
            if (pAPEDecompress == null)
            {
                throw new Exception("Unable to initialize the decoder: " + errorCode);
            }

            pcm = new AudioPCMConfig(
                MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_BITS_PER_SAMPLE, 0, 0).ToInt32(),
                MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_CHANNELS, 0, 0).ToInt32(),
                MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_SAMPLE_RATE, 0, 0).ToInt32(),
                (AudioPCMConfig.SpeakerConfig) 0);
            _samplesBuffer = new byte[16384 * pcm.BlockAlign];
            _sampleCount   = MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_DECOMPRESS_TOTAL_BLOCKS, 0, 0).ToInt64();
            _sampleOffset  = 0;
        }
Ejemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (m_StreamIO != null)
                {
                    m_StreamIO.Dispose();
                    m_StreamIO = null;
                }
                if (m_stream != null)
                {
                    m_stream.Dispose();
                    m_stream = null;
                }
                if (_samplesBuffer != null)
                {
                    _samplesBuffer = null;
                }
            }

            if (pAPEDecompress != null)
            {
                MACLibDll.c_APEDecompress_Destroy(pAPEDecompress);
            }
            pAPEDecompress = IntPtr.Zero;
        }
Ejemplo n.º 3
0
        public AudioEncoder(EncoderSettings settings, string path, Stream output = null)
        {
            m_settings = settings;

            m_path             = path;
            m_stream           = output;
            m_settings         = settings;
            m_streamGiven      = output != null;
            m_initialized      = false;
            m_finalSampleCount = 0;
            m_samplesWritten   = 0;

            if (m_settings.PCM.ChannelCount != 1 && m_settings.PCM.ChannelCount != 2)
            {
                throw new Exception("Only stereo and mono audio formats are allowed.");
            }
            if (m_settings.PCM.BitsPerSample != 16 && m_settings.PCM.BitsPerSample != 24)
            {
                throw new Exception("bits per sample must be 16 or 24");
            }

            int nRetVal;

            pAPECompress = MACLibDll.c_APECompress_Create(out nRetVal);
            if (pAPECompress == null)
            {
                throw new Exception("Unable to open APE compressor.");
            }
        }
Ejemplo n.º 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                m_stream    = null;
                _readBuffer = null;
            }

            MACLibDll.c_APECIO_Destroy(m_hCIO);
            m_hCIO = IntPtr.Zero;
        }
Ejemplo n.º 5
0
        public StreamIO(Stream stream)
        {
            m_stream = stream;

            // We keep the references to those callbacks to
            // prevent them from being garbage collected.
            m_read_bytes  = ReadCallback;
            m_write_bytes = WriteCallback;
            m_get_pos     = TellCallback;
            m_get_size    = GetSizeCallback;
            m_seek        = SeekRelativeCallback;

            m_hCIO = MACLibDll.c_APECIO_Create(null, m_read_bytes, m_write_bytes, m_seek, m_get_pos, m_get_size);
        }