Example #1
0
        private void WriteFormatBlock()
        {
            MMCKINFO mmckinfoParentIn = new MMCKINFO();

            // Get format info
            mmckinfoParentIn.ckid   = new FourCC("fmt ");
            mmckinfoParentIn.ckSize = FORMATBLOCKSIZE;
            MMIOError rc = MMIO.CreateChunk(m_OutputFile, mmckinfoParentIn, RiffChunkFlags.None);

            MMIO.ThrowExceptionForError(rc);

            IntPtr ip = Marshal.AllocCoTaskMem(FORMATBLOCKSIZE);

            try
            {
                Marshal.StructureToPtr(m_wfe, ip, false);

                int iBytes = MMIO.Write(m_OutputFile, ip, FORMATBLOCKSIZE);
                if (iBytes < 0)
                {
                    throw new Exception("mmioWrite failed");
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(ip);
            }

            rc = MMIO.Ascend(m_OutputFile, mmckinfoParentIn, 0);
            MMIO.ThrowExceptionForError(rc);
        }
Example #2
0
        /// <summary>
        /// Read the WaveFormatEx from the input file and find the place to start
        /// writing data.
        /// </summary>
        private void LoadWFE()
        {
            MMCKINFO mmckinfoParentIn   = new MMCKINFO();
            MMCKINFO mmckinfoSubchunkIn = new MMCKINFO();

            int mm = MMIO.Seek(m_OutputFile, 0, MMIOSeekFlags.Set);

            if (mm < 0)
            {
                throw new Exception("seek failure");
            }

            // Check if this is a wave file
            mmckinfoParentIn.fccType = new FourCC("WAVE");
            MMIOError rc = MMIO.Descend(m_OutputFile, mmckinfoParentIn, null, RiffChunkFlags.FindRiff);

            MMIO.ThrowExceptionForError(rc);

            // Get format info
            mmckinfoSubchunkIn.ckid = new FourCC("fmt ");
            rc = MMIO.Descend(m_OutputFile, mmckinfoSubchunkIn, mmckinfoParentIn, RiffChunkFlags.FindChunk);
            MMIO.ThrowExceptionForError(rc);

            // Read the data format from the file (WaveFormatEx)
            IntPtr ip = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(WaveFormatEx)));

            try
            {
                rc = MMIO.Read(m_OutputFile, ip, mmckinfoSubchunkIn.ckSize);
                if (rc < 0)
                {
                    throw new Exception("Read failed");
                }

                m_wfe = new WaveFormatEx();
                Marshal.PtrToStructure(ip, m_wfe);
            }
            finally
            {
                Marshal.FreeCoTaskMem(ip);
            }

            rc = MMIO.Ascend(m_OutputFile, mmckinfoSubchunkIn, 0);
            MMIO.ThrowExceptionForError(rc);

            // Find the data subchunk
            mmckinfoSubchunkIn.ckid = new FourCC("data");
            rc = MMIO.Descend(m_OutputFile, mmckinfoSubchunkIn, mmckinfoParentIn, RiffChunkFlags.FindChunk);
            MMIO.ThrowExceptionForError(rc);

            // Here is where data gets written
            m_DataOffset = MMIO.Seek(m_OutputFile, 0, MMIOSeekFlags.Cur);

            // Get the length of the audio
            m_AudioLength = mmckinfoSubchunkIn.ckSize;
        }