示例#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);
        }
示例#2
0
 public static bool isAddressGood(int address)
 {
     if (RuntimeContextLLE.LLEActive)
     {
         return(MMIO.isAddressGood(address));
     }
     return(Memory.isAddressGood(address));
 }
示例#3
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;
        }
示例#4
0
        /// <summary>
        /// Write a sample to the file
        /// </summary>
        /// <param name="wh"></param>
        private void WriteSample(WAVEHDR wh)
        {
            int iBytes = MMIO.Write(m_OutputFile, wh.lpData, wh.dwBytesRecorded);

            if (iBytes < 0)
            {
                throw new Exception("Write Failed");
            }
            m_AudioLength += iBytes;
        }
示例#5
0
        private void WriteDataBlock()
        {
            MMCKINFO mmckinfoSubchunkIn = new MMCKINFO();

            mmckinfoSubchunkIn.ckid   = new FourCC("data");
            mmckinfoSubchunkIn.ckSize = m_AudioLength;
            MMIOError rc = MMIO.CreateChunk(m_OutputFile, mmckinfoSubchunkIn, 0);

            MMIO.ThrowExceptionForError(rc);
        }
示例#6
0
        private void WriteWaveHeader()
        {
            MMCKINFO mmckinfoParentIn = new MMCKINFO();

            mmckinfoParentIn.fccType = new FourCC("WAVE");
            mmckinfoParentIn.ckSize  = m_AudioLength + m_DataOffset - 8;
            MMIOError rc = MMIO.CreateChunk(m_OutputFile, mmckinfoParentIn, RiffChunkFlags.CreateRiff);

            MMIO.ThrowExceptionForError(rc);
        }
示例#7
0
        private void OpenWaveFile(string sFilename, MMIOFlags f)
        {
            MMIOINFO minfo = new MMIOINFO();

            m_OutputFile = MMIO.Open(sFilename, minfo, f);
            if (m_OutputFile == IntPtr.Zero)
            {
                MMIO.ThrowExceptionForError(minfo.wErrorRet);
            }
        }
示例#8
0
        /// <summary>
        /// Re-write the header, updating sizes
        /// </summary>
        private void WriteHeader()
        {
            int rc = MMIO.Seek(m_OutputFile, 0, MMIOSeekFlags.Set);

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

            WriteWaveHeader();
            WriteFormatBlock();
            WriteDataBlock();
        }
示例#9
0
        /// <summary>
        /// Start (or resume) recording.  Note that the file must be opened first.
        /// </summary>
        public void Record()
        {
            if (!m_Disposed)
            {
                MMIO.Seek(m_OutputFile, 0, MMIOSeekFlags.End);

                int mmr = waveIn.Start(m_hDevice);
                waveIn.ThrowExceptionForError(mmr);
            }
            else
            {
                throw new Exception("Instance is Disposed");
            }
        }
示例#10
0
 private bool isAddressGood(int address)
 {
     if (Memory.isAddressGood(address))
     {
         return(true);
     }
     if (interpretedAddresses.Contains(address))
     {
         return(true);
     }
     if (RuntimeContextLLE.MMIO != null)
     {
         return(MMIO.isAddressGood(address));
     }
     return(false);
 }
示例#11
0
        public void DoTests()
        {
            MMIOINFO mminfo  = new MMIOINFO();
            MMIOINFO mminfo2 = new MMIOINFO();

            IntPtr ipOutput;

            ipOutput = MMIO.Open(sFilename, mminfo, MMIOFlags.ReadWrite);

            int i = MMIO.Seek(ipOutput, 0, MMIOSeekFlags.Set);

            Debug.Assert(i >= 0);

            MMIOError mm = MMIO.Flush(ipOutput, MMIOFlushFlags.None);

            MMIO.ThrowExceptionForError(mm);

            mm = MMIO.GetInfo(ipOutput, mminfo, Marshal.SizeOf(typeof(MMIOINFO)));
            MMIO.ThrowExceptionForError(mm);

            Debug.Assert(mminfo.dwFlags == MMIOFlags.ReadWrite);

            mm = MMIO.SetInfo(ipOutput, mminfo, Marshal.SizeOf(typeof(MMIOINFO)));
            MMIO.ThrowExceptionForError(mm);

            IntPtr ipbuff = Marshal.AllocCoTaskMem(BUFSIZE);

            mm = MMIO.SetBuffer(ipOutput, ipbuff, BUFSIZE, 0);
            MMIO.ThrowExceptionForError(mm);

            mm = MMIO.GetInfo(ipOutput, mminfo2, Marshal.SizeOf(typeof(MMIOINFO)));
            MMIO.ThrowExceptionForError(mm);

            mm = MMIO.Advance(ipOutput, mminfo2, RWMode.Read);
            MMIO.ThrowExceptionForError(mm);

            Debug.Assert(mminfo2.lDiskOffset == BUFSIZE);

            mm = MMIO.Close(ipOutput, MMIOCloseFlags.None);
            MMIO.ThrowExceptionForError(mm);

            mm = MMIO.Rename(sFilename, sFilename2, null, 0);
            MMIO.ThrowExceptionForError(mm);
            mm = MMIO.Rename(sFilename2, sFilename, null, 0);
            MMIO.ThrowExceptionForError(mm);
        }
示例#12
0
        /// <summary>
        /// Close the file
        /// </summary>
        public void Close()
        {
            if (!m_Disposed)
            {
                m_Closing = true;
                if (m_hDevice != IntPtr.Zero)
                {
                    waveIn.Reset(m_hDevice); // Does an implicit Stop
                    m_ProcReady.WaitOne();   // Wait for the thread to exit
                }

                // No point in hanging on to the buffers.  The next file
                // we open may use different attributes.
                if (m_Buffers != null)
                {
                    for (int x = 0; x < RECORDINGBUFFERS; x++)
                    {
                        m_Buffers[x].Release(m_hDevice);
                    }

                    m_Buffers = null;
                }

                if (m_hDevice != IntPtr.Zero)
                {
                    waveIn.Close(m_hDevice);
                    m_hDevice = IntPtr.Zero;
                }

                if (m_OutputFile != IntPtr.Zero)
                {
                    WriteHeader();

                    MMIO.Flush(m_OutputFile, MMIOFlushFlags.None);
                    MMIO.Close(m_OutputFile, MMIOCloseFlags.None);
                    m_OutputFile = IntPtr.Zero;
                }

                m_AudioLength = 0;
            }
            else
            {
                throw new Exception("Instance is Disposed");
            }
        }
示例#13
0
        public void UpdateVertexBuffer(MMIO.Node<NodeContent> node)
        {
            var gray = new SharpDX.Vector4(0.5f, 0.5f, 0.5f, 0.5f);
            var white = new SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            var red = new SharpDX.Vector4(1.0f, 0, 0, 1.0f);

            var vertices = node.TraversePair()
                .Select(x =>
                {
                    if (x.Item2.Content.IsSelected.Value)
                    {
                        return new { line = x, color = red };
                    }
                    else if (x.Item2.Content.KeyFrame.Value == Transform.Identity)
                    {
                        return new { line = x, color = gray };
                    }
                    else
                    {
                        return new { line = x, color = white };
                    }
                })
                .SelectMany(x => new SharpDX.Vector4[] {
                    new SharpDX.Vector4(x.line.Item1.Content.WorldTransform.Translation, 1.0f), x.color
                    , new SharpDX.Vector4(x.line.Item2.Content.WorldTransform.Translation, 1.0f), x.color
                })
                .SelectMany(x => new Single[] { x.X, x.Y, x.Z, x.W })
                .ToArray()
                ;

            if (!vertices.Any()) return;

            // ToDO: Meshごとにシェーダーを見るべし
            // ToDo: 解放されている?
            var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(float)) * vertices.Length);
            Marshal.Copy(vertices, 0, ptr, vertices.Length);

            VertexBufferUpdate = VertexBufferUpdateCommand.Create(VertexBuffer, ptr);
        }
示例#14
0
 Transform VmdBoneFrameToKeyFrame(MMIO.Mmd.VmdBoneFrame vmd, Single scale)
 {
     return new Transform(
         new SharpDX.Vector3(vmd.Position.X, vmd.Position.Y, vmd.Position.Z) * scale
         , new SharpDX.Quaternion(vmd.Rotation.X, vmd.Rotation.Y, vmd.Rotation.Z, vmd.Rotation.W));
 }
示例#15
0
        public Node<NodeContent> BuildBvh(MMIO.Bvh.Node bvh, Node<NodeContent> parent, Single scale, Axis flipAxis, bool yRotate)
        {
            var node = NodeContent.CreateNode(bvh.Name, SharpDX.Vector3.Zero, bvh.Offset.ToSharpDX(flipAxis) * scale);
            node.Content.WorldPosition.Value = parent.Content.WorldPosition.Value + node.Content.LocalPosition.Value;
            parent.Add(node);

            foreach (var child in bvh.Children)
            {
                BuildBvh(child, node, scale, flipAxis, yRotate);
            }

            return node;
        }