Beispiel #1
0
        internal static AcmDriverInfo FromDriverDetails(ACMDRIVERDETAILS details, int driverId)
        {
            AcmDriverInfo info = new AcmDriverInfo();

            info.DriverId    = driverId;
            info.Flags       = details.fdwSupport;
            info.ShortName   = details.szShortName;
            info.LongName    = details.szLongName;
            info.Description = details.szFeatures;
            info._formats    = new List <AcmFormatInfo>();
            IntPtr hDrv;

            AcmNativeMethods.acmDriverOpen(out hDrv, driverId, 0);
            ACMFORMATTAGDETAILS afdt = new ACMFORMATTAGDETAILS();

            afdt.cbStruct = Marshal.SizeOf(afdt);
            IntPtr pafd = Marshal.AllocHGlobal(afdt.cbStruct);

            Marshal.StructureToPtr(afdt, pafd, false);
            AcmNativeMethods.acmFormatTagEnum(hDrv, /*ref afdt*/ pafd, info.AcmFormatTagEnumCB, (int)hDrv, 0);
            Marshal.FreeHGlobal(pafd);
            AcmNativeMethods.acmDriverClose(hDrv, 0);
            return(info);
        }
Beispiel #2
0
        protected override bool InitializeForWriting(Stream underlyingStream, WaveFormat2 wfIn, WaveFormat2 wfOut, bool fAppend)
        {
            base.InitializeForWriting(underlyingStream, wfIn, wfOut, fAppend);
            MMResult mmr;

            int driverId = 0;

            foreach (AcmDriverInfo drvInfo in ACMSupport.SupportedDrivers)
            {
                foreach (AcmFormatInfo fmtInfo in drvInfo.Formats)
                {
                    if (fmtInfo.Format == wfOut)
                    {
                        driverId = fmtInfo.DriverId;
                        break;
                    }
                }
            }

            foreach (AcmDriverInfo drvInfo in ACMSupport.SupportedDrivers)
            {
                foreach (AcmFormatInfo fmtInfo in drvInfo.Formats)
                {
                    if (fmtInfo.DriverId == driverId && fmtInfo.Format.FormatTag == wfIn.FormatTag)
                    {
                        wfIn.CopyFrom(fmtInfo.Format);
                        break;
                    }
                }
            }

            byte[] fmtIn  = wfIn.GetBytes();
            byte[] fmtOut = wfOut.GetBytes();

            IntPtr hDrv = IntPtr.Zero;

            if (driverId != 0)
            {
                AcmNativeMethods.acmDriverOpen(out hDrv, driverId, 0);
            }
            mmr           = AcmNativeMethods.acmStreamOpen(out hStreamComp, hDrv, fmtIn, fmtOut, IntPtr.Zero, 0, 0, AcmStreamOpenFlags.CALLBACK_NULL | AcmStreamOpenFlags.NONREALTIME);
            hdr1          = new ACMSTREAMHEADER();
            hdr1.cbStruct = Marshal.SizeOf(hdr1);
            hdr2          = new ACMSTREAMHEADER();
            hdr2.cbStruct = Marshal.SizeOf(hdr2);

            int cbIn = (wfIn.AvgBytesPerSec * DefaultBufferSizeInSeconds / wfIn.BlockAlign + 1) * wfIn.BlockAlign;

            inBuffer1 = new byte[cbIn];
            inBuffer2 = new byte[cbIn];
            int cbOut = wfOut.BlockAlign * wfOut.AvgBytesPerSec * DefaultBufferSizeInSeconds;

            mmr         = AcmNativeMethods.acmStreamSize(hStreamComp, cbIn, out cbOut, AcmStreamSizeFlags.DESTINATION);
            outBuffer1  = new byte[cbOut];
            outBuffer2  = new byte[cbOut];
            hinBuffer1  = GCHandle.Alloc(inBuffer1, GCHandleType.Pinned);
            houtBuffer1 = GCHandle.Alloc(outBuffer1, GCHandleType.Pinned);
            hinBuffer2  = GCHandle.Alloc(inBuffer2, GCHandleType.Pinned);
            houtBuffer2 = GCHandle.Alloc(outBuffer2, GCHandleType.Pinned);

            hdr1.pbSrc       = hinBuffer1.AddrOfPinnedObject();
            hdr1.pbDst       = houtBuffer1.AddrOfPinnedObject();
            hdr1.cbSrcLength = cbIn;
            hdr1.cbDstLength = cbOut;

            hdr2.pbSrc       = hinBuffer2.AddrOfPinnedObject();
            hdr2.pbDst       = houtBuffer2.AddrOfPinnedObject();
            hdr2.cbSrcLength = cbIn;
            hdr2.cbDstLength = cbOut;

            ptrBuffer1 = ptrBuffer1 = 0;

            firstBlock = true;

            mmr = AcmNativeMethods.acmStreamPrepareHeader(hStreamComp, ref hdr1, 0);
            mmr = AcmNativeMethods.acmStreamPrepareHeader(hStreamComp, ref hdr2, 0);

            return(true);
        }