Exemplo n.º 1
0
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr intPtr = NativeMethods.LoadLibrary(driverFile);

            if (intPtr == IntPtr.Zero)
            {
                throw new ArgumentException("Failed to load driver file");
            }
            IntPtr procAddress = NativeMethods.GetProcAddress(intPtr, "DriverProc");

            if (procAddress == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr   hAcmDriver;
            MmResult mmResult = AcmInterop.acmDriverAdd(out hAcmDriver, intPtr, procAddress, 0, AcmDriverAddFlags.Function);

            if (mmResult != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(intPtr);
                throw new MmException(mmResult, "acmDriverAdd");
            }
            AcmDriver acmDriver = new AcmDriver(hAcmDriver);

            if (string.IsNullOrEmpty(acmDriver.details.longName))
            {
                acmDriver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                acmDriver.localDllHandle   = intPtr;
            }
            return(acmDriver);
        }
Exemplo n.º 2
0
 public void Open()
 {
     if (this.driverHandle == IntPtr.Zero)
     {
         MmException.Try(AcmInterop.acmDriverOpen(out this.driverHandle, this.DriverId, 0), "acmDriverOpen");
     }
 }
Exemplo n.º 3
0
 private AcmDriver(IntPtr hAcmDriver)
 {
     this.driverId = hAcmDriver;
     this.details  = default(AcmDriverDetails);
     this.details.structureSize = Marshal.SizeOf(this.details);
     MmException.Try(AcmInterop.acmDriverDetails(hAcmDriver, ref this.details, 0), "acmDriverDetails");
 }
Exemplo n.º 4
0
        public static WaveFormat SuggestPcmFormat(WaveFormat compressedFormat)
        {
            WaveFormat waveFormat = new WaveFormat(compressedFormat.SampleRate, 16, compressedFormat.Channels);

            MmException.Try(AcmInterop.acmFormatSuggest(IntPtr.Zero, compressedFormat, waveFormat, Marshal.SizeOf(waveFormat), AcmFormatSuggestFlags.FormatTag), "acmFormatSuggest");
            return(waveFormat);
        }
Exemplo n.º 5
0
 public void Close()
 {
     if (this.driverHandle != IntPtr.Zero)
     {
         MmException.Try(AcmInterop.acmDriverClose(this.driverHandle, 0), "acmDriverClose");
         this.driverHandle = IntPtr.Zero;
     }
 }
Exemplo n.º 6
0
 private void Prepare()
 {
     this.streamHeader.cbStruct            = Marshal.SizeOf(this.streamHeader);
     this.streamHeader.sourceBufferLength  = this.sourceBuffer.Length;
     this.streamHeader.sourceBufferPointer = this.hSourceBuffer.AddrOfPinnedObject();
     this.streamHeader.destBufferLength    = this.destBuffer.Length;
     this.streamHeader.destBufferPointer   = this.hDestBuffer.AddrOfPinnedObject();
     MmException.Try(AcmInterop.acmStreamPrepareHeader(this.streamHandle, this.streamHeader, 0), "acmStreamPrepareHeader");
 }
Exemplo n.º 7
0
        public AcmStream(IntPtr driverId, WaveFormat sourceFormat, WaveFilter waveFilter)
        {
            int num = Math.Max(16384, sourceFormat.AverageBytesPerSecond);

            this.sourceFormat = sourceFormat;
            num -= num % sourceFormat.BlockAlign;
            MmException.Try(AcmInterop.acmDriverOpen(out this.driverHandle, driverId, 0), "acmDriverOpen");
            MmException.Try(AcmInterop.acmStreamOpen(out this.streamHandle, this.driverHandle, sourceFormat, sourceFormat, waveFilter, IntPtr.Zero, IntPtr.Zero, AcmStreamOpenFlags.NonRealTime), "acmStreamOpen");
            this.streamHeader = new AcmStreamHeader(this.streamHandle, num, this.SourceToDest(num));
        }
Exemplo n.º 8
0
        public static void RemoveLocalDriver(AcmDriver localDriver)
        {
            if (localDriver.localDllHandle == IntPtr.Zero)
            {
                throw new ArgumentException("Please pass in the AcmDriver returned by the AddLocalDriver method");
            }
            MmResult arg_3A_0 = AcmInterop.acmDriverRemove(localDriver.driverId, 0);

            NativeMethods.FreeLibrary(localDriver.localDllHandle);
            MmException.Try(arg_3A_0, "acmDriverRemove");
        }
Exemplo n.º 9
0
        public int DestToSource(int dest)
        {
            if (dest == 0)
            {
                return(0);
            }
            int result;

            MmException.Try(AcmInterop.acmStreamSize(this.streamHandle, dest, out result, AcmStreamSizeFlags.Destination), "acmStreamSize");
            return(result);
        }
Exemplo n.º 10
0
        public int SourceToDest(int source)
        {
            if (source == 0)
            {
                return(0);
            }
            int result;

            MmException.Try(AcmInterop.acmStreamSize(this.streamHandle, source, out result, AcmStreamSizeFlags.Source), "acmStreamSize");
            return(result);
        }
Exemplo n.º 11
0
        private void Unprepare()
        {
            this.streamHeader.sourceBufferLength  = this.sourceBuffer.Length;
            this.streamHeader.sourceBufferPointer = this.hSourceBuffer.AddrOfPinnedObject();
            this.streamHeader.destBufferLength    = this.destBuffer.Length;
            this.streamHeader.destBufferPointer   = this.hDestBuffer.AddrOfPinnedObject();
            MmResult mmResult = AcmInterop.acmStreamUnprepareHeader(this.streamHandle, this.streamHeader, 0);

            if (mmResult != MmResult.NoError)
            {
                throw new MmException(mmResult, "acmStreamUnprepareHeader");
            }
        }
Exemplo n.º 12
0
 public int Convert(int bytesToConvert, out int sourceBytesConverted)
 {
     this.Prepare();
     try
     {
         this.streamHeader.sourceBufferLength     = bytesToConvert;
         this.streamHeader.sourceBufferLengthUsed = bytesToConvert;
         AcmStreamConvertFlags streamConvertFlags = this.firstTime ? (AcmStreamConvertFlags.BlockAlign | AcmStreamConvertFlags.Start) : AcmStreamConvertFlags.BlockAlign;
         MmException.Try(AcmInterop.acmStreamConvert(this.streamHandle, this.streamHeader, streamConvertFlags), "acmStreamConvert");
         this.firstTime       = false;
         sourceBytesConverted = this.streamHeader.sourceBufferLengthUsed;
     }
     finally
     {
         this.Unprepare();
     }
     return(this.streamHeader.destBufferLengthUsed);
 }
Exemplo n.º 13
0
        public IEnumerable <AcmFormat> GetFormats(AcmFormatTag formatTag)
        {
            if (this.driverHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Driver must be opened first");
            }
            this.tempFormatsList = new List <AcmFormat>();
            AcmFormatDetails acmFormatDetails = default(AcmFormatDetails);

            acmFormatDetails.structSize         = Marshal.SizeOf(acmFormatDetails);
            acmFormatDetails.waveFormatByteSize = 1024;
            acmFormatDetails.waveFormatPointer  = Marshal.AllocHGlobal(acmFormatDetails.waveFormatByteSize);
            acmFormatDetails.formatTag          = (int)formatTag.FormatTag;
            MmResult arg_9C_0 = AcmInterop.acmFormatEnum(this.driverHandle, ref acmFormatDetails, new AcmInterop.AcmFormatEnumCallback(this.AcmFormatEnumCallback), IntPtr.Zero, AcmFormatEnumFlags.None);

            Marshal.FreeHGlobal(acmFormatDetails.waveFormatPointer);
            MmException.Try(arg_9C_0, "acmFormatEnum");
            return(this.tempFormatsList);
        }
Exemplo n.º 14
0
 public AcmStream(WaveFormat sourceFormat, WaveFormat destFormat)
 {
     try
     {
         this.streamHandle = IntPtr.Zero;
         this.sourceFormat = sourceFormat;
         int num = Math.Max(65536, sourceFormat.AverageBytesPerSecond);
         num -= num % sourceFormat.BlockAlign;
         MmException.Try(AcmInterop.acmStreamOpen(out this.streamHandle, IntPtr.Zero, sourceFormat, destFormat, null, IntPtr.Zero, IntPtr.Zero, AcmStreamOpenFlags.NonRealTime), "acmStreamOpen");
         int destBufferLength = this.SourceToDest(num);
         this.streamHeader = new AcmStreamHeader(this.streamHandle, num, destBufferLength);
         this.driverHandle = IntPtr.Zero;
     }
     catch
     {
         this.Dispose();
         throw;
     }
 }
Exemplo n.º 15
0
        public static bool ShowFormatChooseDialog(IntPtr ownerWindowHandle, string windowTitle, AcmFormatEnumFlags enumFlags, WaveFormat enumFormat, out WaveFormat selectedFormat, out string selectedFormatDescription, out string selectedFormatTagDescription)
        {
            AcmFormatChoose acmFormatChoose = default(AcmFormatChoose);

            acmFormatChoose.structureSize     = Marshal.SizeOf(acmFormatChoose);
            acmFormatChoose.styleFlags        = AcmFormatChooseStyleFlags.None;
            acmFormatChoose.ownerWindowHandle = ownerWindowHandle;
            int num = 200;

            acmFormatChoose.selectedWaveFormatPointer  = Marshal.AllocHGlobal(num);
            acmFormatChoose.selectedWaveFormatByteSize = num;
            acmFormatChoose.title                 = windowTitle;
            acmFormatChoose.name                  = null;
            acmFormatChoose.formatEnumFlags       = enumFlags;
            acmFormatChoose.waveFormatEnumPointer = IntPtr.Zero;
            if (enumFormat != null)
            {
                IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(enumFormat));
                Marshal.StructureToPtr(enumFormat, intPtr, false);
                acmFormatChoose.waveFormatEnumPointer = intPtr;
            }
            acmFormatChoose.instanceHandle = IntPtr.Zero;
            acmFormatChoose.templateName   = null;
            MmResult mmResult = AcmInterop.acmFormatChoose(ref acmFormatChoose);

            selectedFormat               = null;
            selectedFormatDescription    = null;
            selectedFormatTagDescription = null;
            if (mmResult == MmResult.NoError)
            {
                selectedFormat               = WaveFormat.MarshalFromPtr(acmFormatChoose.selectedWaveFormatPointer);
                selectedFormatDescription    = acmFormatChoose.formatDescription;
                selectedFormatTagDescription = acmFormatChoose.formatTagDescription;
            }
            Marshal.FreeHGlobal(acmFormatChoose.waveFormatEnumPointer);
            Marshal.FreeHGlobal(acmFormatChoose.selectedWaveFormatPointer);
            if (mmResult != MmResult.AcmCancelled && mmResult != MmResult.NoError)
            {
                throw new MmException(mmResult, "acmFormatChoose");
            }
            return(mmResult == MmResult.NoError);
        }
Exemplo n.º 16
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing && this.streamHeader != null)
     {
         this.streamHeader.Dispose();
         this.streamHeader = null;
     }
     if (this.streamHandle != IntPtr.Zero)
     {
         MmResult mmResult = AcmInterop.acmStreamClose(this.streamHandle, 0);
         this.streamHandle = IntPtr.Zero;
         if (mmResult != MmResult.NoError)
         {
             throw new MmException(mmResult, "acmStreamClose");
         }
     }
     if (this.driverHandle != IntPtr.Zero)
     {
         AcmInterop.acmDriverClose(this.driverHandle, 0);
         this.driverHandle = IntPtr.Zero;
     }
 }
Exemplo n.º 17
0
 public static IEnumerable <AcmDriver> EnumerateAcmDrivers()
 {
     AcmDriver.drivers = new List <AcmDriver>();
     MmException.Try(AcmInterop.acmDriverEnum(new AcmInterop.AcmDriverEnumCallback(AcmDriver.DriverEnumCallback), IntPtr.Zero, (AcmDriverEnumFlags)0), "acmDriverEnum");
     return(AcmDriver.drivers);
 }