Example #1
0
 internal static extern int mmioDescend(IntPtr hMIO,
                                        [MarshalAs(UnmanagedType.LPStruct)] NativeMethods.MMCKINFO lpck,
                                        [MarshalAs(UnmanagedType.LPStruct)] NativeMethods.MMCKINFO lcpkParent,
                                        int flags);
Example #2
0
 internal static extern int mmioAscend(IntPtr hMIO, NativeMethods.MMCKINFO lpck, int flags);
Example #3
0
        private unsafe void ValidateSoundFile(string fileName)
        {
            NativeMethods.MMCKINFO     ckRIFF     = new NativeMethods.MMCKINFO();
            NativeMethods.MMCKINFO     ck         = new NativeMethods.MMCKINFO();
            NativeMethods.WAVEFORMATEX waveFormat = null;
            int dw;

            IntPtr hMIO = UnsafeNativeMethods.mmioOpen(fileName, IntPtr.Zero, NativeMethods.MMIO_READ | NativeMethods.MMIO_ALLOCBUF);

            if (hMIO == IntPtr.Zero)
            {
                throw new FileNotFoundException(SR.GetString(SR.SoundAPIFileDoesNotExist), this.soundLocation);
            }

            try {
                ckRIFF.fccType = mmioFOURCC('W', 'A', 'V', 'E');
                if (UnsafeNativeMethods.mmioDescend(hMIO, ckRIFF, null, NativeMethods.MMIO_FINDRIFF) != 0)
                {
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveFile, this.soundLocation));
                }

                while (UnsafeNativeMethods.mmioDescend(hMIO, ck, ckRIFF, 0) == 0)
                {
                    if (ck.dwDataOffset + ck.cksize > ckRIFF.dwDataOffset + ckRIFF.cksize)
                    {
                        throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveHeader));
                    }

                    if (ck.ckID == mmioFOURCC('f', 'm', 't', ' '))
                    {
                        if (waveFormat == null)
                        {
                            dw = ck.cksize;
                            if (dw < Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX)))
                            {
                                dw = Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX));
                            }

                            waveFormat = new NativeMethods.WAVEFORMATEX();
                            byte[] data = new byte[dw];
                            if (UnsafeNativeMethods.mmioRead(hMIO, data, dw) != dw)
                                throw new InvalidOperationException(SR.GetString(SR.SoundAPIReadError, this.soundLocation));
                            fixed(byte *pdata = data)
                            {
                                Marshal.PtrToStructure((IntPtr)pdata, waveFormat);
                            }
                        }
                        else
                        {
                            //
                            // multiple formats?
                            //
                        }
                    }
                    UnsafeNativeMethods.mmioAscend(hMIO, ck, 0);
                }

                if (waveFormat == null)
                {
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveHeader));
                }

                if (waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_PCM &&
                    waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_ADPCM &&
                    waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_IEEE_FLOAT)
                {
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIFormatNotSupported));
                }
            } finally {
                if (hMIO != IntPtr.Zero)
                {
                    UnsafeNativeMethods.mmioClose(hMIO, 0);
                }
            }
        }
        private unsafe void ValidateSoundFile(string fileName)
        {
            NativeMethods.MMCKINFO     lpck      = new NativeMethods.MMCKINFO();
            NativeMethods.MMCKINFO     mmckinfo2 = new NativeMethods.MMCKINFO();
            NativeMethods.WAVEFORMATEX structure = null;
            IntPtr hMIO = UnsafeNativeMethods.mmioOpen(fileName, IntPtr.Zero, 0x10000);

            if (hMIO == IntPtr.Zero)
            {
                throw new FileNotFoundException(SR.GetString("SoundAPIFileDoesNotExist"), this.soundLocation);
            }
            try
            {
                lpck.fccType = mmioFOURCC('W', 'A', 'V', 'E');
                if (UnsafeNativeMethods.mmioDescend(hMIO, lpck, null, 0x20) == 0)
                {
                    goto Label_0179;
                }
                throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveFile", new object[] { this.soundLocation }));
Label_008B:
                if ((mmckinfo2.dwDataOffset + mmckinfo2.cksize) > (lpck.dwDataOffset + lpck.cksize))
                {
                    throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
                }
                if ((mmckinfo2.ckID == mmioFOURCC('f', 'm', 't', ' ')) && (structure == null))
                {
                    int cksize = mmckinfo2.cksize;
                    if (cksize < Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX)))
                    {
                        cksize = Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX));
                    }
                    structure = new NativeMethods.WAVEFORMATEX();
                    byte[] wf = new byte[cksize];
                    if (UnsafeNativeMethods.mmioRead(hMIO, wf, cksize) != cksize)
                    {
                        throw new InvalidOperationException(SR.GetString("SoundAPIReadError", new object[] { this.soundLocation }));
                    }
                    try
                    {
                        fixed(byte *numRef = wf)
                        {
                            Marshal.PtrToStructure((IntPtr)numRef, structure);
                        }
                    }
                    finally
                    {
                        numRef = null;
                    }
                }
                UnsafeNativeMethods.mmioAscend(hMIO, mmckinfo2, 0);
Label_0179:
                if (UnsafeNativeMethods.mmioDescend(hMIO, mmckinfo2, lpck, 0) == 0)
                {
                    goto Label_008B;
                }
                if (structure == null)
                {
                    throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
                }
                if (((structure.wFormatTag != 1) && (structure.wFormatTag != 2)) && (structure.wFormatTag != 3))
                {
                    throw new InvalidOperationException(SR.GetString("SoundAPIFormatNotSupported"));
                }
            }
            finally
            {
                if (hMIO != IntPtr.Zero)
                {
                    UnsafeNativeMethods.mmioClose(hMIO, 0);
                }
            }
        }
        private unsafe void ValidateSoundFile(string fileName) {
            NativeMethods.MMCKINFO ckRIFF = new NativeMethods.MMCKINFO();
            NativeMethods.MMCKINFO ck = new NativeMethods.MMCKINFO();
            NativeMethods.WAVEFORMATEX waveFormat = null;
            int dw;

            IntPtr hMIO = UnsafeNativeMethods.mmioOpen(fileName, IntPtr.Zero, NativeMethods.MMIO_READ | NativeMethods.MMIO_ALLOCBUF);

            if (hMIO == IntPtr.Zero)
                throw new FileNotFoundException(SR.GetString(SR.SoundAPIFileDoesNotExist), this.soundLocation);

            try {
                ckRIFF.fccType = mmioFOURCC('W', 'A','V','E');
                if (UnsafeNativeMethods.mmioDescend(hMIO, ckRIFF, null, NativeMethods.MMIO_FINDRIFF) != 0)
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveFile, this.soundLocation));

                while (UnsafeNativeMethods.mmioDescend(hMIO, ck, ckRIFF, 0) == 0) {
                    if (ck.dwDataOffset + ck.cksize > ckRIFF.dwDataOffset + ckRIFF.cksize)
                        throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveHeader));

                    if (ck.ckID == mmioFOURCC('f','m','t',' ')) {
                            if (waveFormat == null) {
                                dw = ck.cksize;
                                if (dw < Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX)))
                                    dw =  Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX));

                                waveFormat = new NativeMethods.WAVEFORMATEX();
                                byte[] data = new byte[dw];
                                if (UnsafeNativeMethods.mmioRead(hMIO, data, dw) != dw)
                                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIReadError, this.soundLocation));
                                fixed(byte* pdata = data) {
                                    Marshal.PtrToStructure((IntPtr) pdata, waveFormat);
                                }
                            } else {
                                //
                                // multiple formats?
                                //
                            }
                    }
                    UnsafeNativeMethods.mmioAscend(hMIO, ck, 0);
                }

                if (waveFormat == null)
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIInvalidWaveHeader));

                if (waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_PCM &&
                    waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_ADPCM &&
                    waveFormat.wFormatTag != NativeMethods.WAVE_FORMAT_IEEE_FLOAT)
                    throw new InvalidOperationException(SR.GetString(SR.SoundAPIFormatNotSupported));

            } finally {
                    if (hMIO != IntPtr.Zero)
                        UnsafeNativeMethods.mmioClose(hMIO, 0);
            }
        }
 private unsafe void ValidateSoundFile(string fileName)
 {
     NativeMethods.MMCKINFO lpck = new NativeMethods.MMCKINFO();
     NativeMethods.MMCKINFO mmckinfo2 = new NativeMethods.MMCKINFO();
     NativeMethods.WAVEFORMATEX structure = null;
     IntPtr hMIO = UnsafeNativeMethods.mmioOpen(fileName, IntPtr.Zero, 0x10000);
     if (hMIO == IntPtr.Zero)
     {
         throw new FileNotFoundException(SR.GetString("SoundAPIFileDoesNotExist"), this.soundLocation);
     }
     try
     {
         lpck.fccType = mmioFOURCC('W', 'A', 'V', 'E');
         if (UnsafeNativeMethods.mmioDescend(hMIO, lpck, null, 0x20) == 0)
         {
             goto Label_0179;
         }
         throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveFile", new object[] { this.soundLocation }));
     Label_008B:
         if ((mmckinfo2.dwDataOffset + mmckinfo2.cksize) > (lpck.dwDataOffset + lpck.cksize))
         {
             throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
         }
         if ((mmckinfo2.ckID == mmioFOURCC('f', 'm', 't', ' ')) && (structure == null))
         {
             int cksize = mmckinfo2.cksize;
             if (cksize < Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX)))
             {
                 cksize = Marshal.SizeOf(typeof(NativeMethods.WAVEFORMATEX));
             }
             structure = new NativeMethods.WAVEFORMATEX();
             byte[] wf = new byte[cksize];
             if (UnsafeNativeMethods.mmioRead(hMIO, wf, cksize) != cksize)
             {
                 throw new InvalidOperationException(SR.GetString("SoundAPIReadError", new object[] { this.soundLocation }));
             }
             try
             {
                 fixed (byte* numRef = wf)
                 {
                     Marshal.PtrToStructure((IntPtr) numRef, structure);
                 }
             }
             finally
             {
                 numRef = null;
             }
         }
         UnsafeNativeMethods.mmioAscend(hMIO, mmckinfo2, 0);
     Label_0179:
         if (UnsafeNativeMethods.mmioDescend(hMIO, mmckinfo2, lpck, 0) == 0)
         {
             goto Label_008B;
         }
         if (structure == null)
         {
             throw new InvalidOperationException(SR.GetString("SoundAPIInvalidWaveHeader"));
         }
         if (((structure.wFormatTag != 1) && (structure.wFormatTag != 2)) && (structure.wFormatTag != 3))
         {
             throw new InvalidOperationException(SR.GetString("SoundAPIFormatNotSupported"));
         }
     }
     finally
     {
         if (hMIO != IntPtr.Zero)
         {
             UnsafeNativeMethods.mmioClose(hMIO, 0);
         }
     }
 }