Ejemplo 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Suggests an appropriate PCM format that the compressed format can be converted
        /// to in one step
        /// </summary>
        /// <param name="compressedFormat">The compressed format</param>
        /// <returns>The PCM format</returns>
        // Token: 0x060007D0 RID: 2000 RVA: 0x00016DD0 File Offset: 0x00014FD0
        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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new ACM stream to convert one format to another. Note that
        /// not all conversions can be done in one step
        /// </summary>
        /// <param name="sourceFormat">The source audio format</param>
        /// <param name="destFormat">The destination audio format</param>
        public AcmStream(WaveFormat sourceFormat, WaveFormat destFormat)
        {
            try
            {
                streamHandle      = IntPtr.Zero;
                this.sourceFormat = sourceFormat;
                int sourceBufferSize = Math.Max(65536, sourceFormat.AverageBytesPerSecond);
                sourceBufferSize -= (sourceBufferSize % sourceFormat.BlockAlign);
                IntPtr sourceFormatPointer = WaveFormat.MarshalToPtr(sourceFormat);
                IntPtr destFormatPointer   = WaveFormat.MarshalToPtr(destFormat);

                try
                {
                    MmException.Try(AcmInterop.acmStreamOpen2(out streamHandle, IntPtr.Zero, sourceFormatPointer, destFormatPointer, null, IntPtr.Zero, IntPtr.Zero, AcmStreamOpenFlags.NonRealTime), "acmStreamOpen");
                }
                finally
                {
                    Marshal.FreeHGlobal(sourceFormatPointer);
                    Marshal.FreeHGlobal(destFormatPointer);
                }

                int destBufferSize = SourceToDest(sourceBufferSize);
                streamHeader = new AcmStreamHeader(streamHandle, sourceBufferSize, destBufferSize);
                driverHandle = IntPtr.Zero;
            }
            catch
            {
                // suppress the finalise and clean up resources
                Dispose();
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Frees resources associated with this ACM Stream
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Free other state (managed objects).
                if (streamHeader != null)
                {
                    streamHeader.Dispose();
                    streamHeader = null;
                }
            }

            // Free your own state (unmanaged objects).

            if (streamHandle != IntPtr.Zero)
            {
                MmResult result = AcmInterop.acmStreamClose(streamHandle, 0);
                streamHandle = IntPtr.Zero;
                if (result != MmResult.NoError)
                {
                    throw new MmException(result, "acmStreamClose");
                }
            }
            // Set large fields to null.
            if (driverHandle != IntPtr.Zero)
            {
                AcmInterop.acmDriverClose(driverHandle, 0);
                driverHandle = IntPtr.Zero;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new ACM Driver object
 /// </summary>
 /// <param name="hAcmDriver">Driver handle</param>
 private AcmDriver(IntPtr hAcmDriver)
 {
     driverId = hAcmDriver;
     details  = new AcmDriverDetails();
     details.structureSize = System.Runtime.InteropServices.Marshal.SizeOf(details);
     MmException.Try(AcmInterop.acmDriverDetails(hAcmDriver, ref details, 0), "acmDriverDetails");
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Opens this driver
 /// </summary>
 public void Open()
 {
     if (driverHandle == IntPtr.Zero)
     {
         MmException.Try(AcmInterop.acmDriverOpen(out driverHandle, DriverId, 0), "acmDriverOpen");
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new ACM stream to convert one format to another. Note that
        /// not all conversions can be done in one step
        /// </summary>
        /// <param name="sourceFormat">The source audio format</param>
        /// <param name="destFormat">The destination audio format</param>
        public AcmStream(WaveFormat sourceFormat, WaveFormat destFormat)
        {
            try
            {
                streamHandle      = IntPtr.Zero;
                this.sourceFormat = sourceFormat;
                int sourceBufferSize = Math.Max(16384, sourceFormat.AverageBytesPerSecond);
                sourceBufferSize -= (sourceBufferSize % sourceFormat.BlockAlign);
                MmException.Try(AcmInterop.acmStreamOpen(out streamHandle, IntPtr.Zero, sourceFormat, destFormat, null, 0, 0, AcmStreamOpenFlags.NonRealTime), "acmStreamOpen");

                // horrible stuff due to wierd Marshalling issues

                /*
                 * IntPtr sourceFormatPointer = WaveFormat.MarshalToPtr(sourceFormat);
                 * IntPtr destFormatPointer = WaveFormat.MarshalToPtr(destFormat);
                 * MmResult result = AcmInterop.acmStreamOpen2(out streamHandle, IntPtr.Zero, sourceFormatPointer, destFormatPointer, null, 0, 0, AcmStreamOpenFlags.NonRealTime);
                 * Marshal.FreeHGlobal(sourceFormatPointer);
                 * Marshal.FreeHGlobal(destFormatPointer);
                 * MmException.Try(result, "acmStreamOpen");*/

                streamHeader = new AcmStreamHeader(streamHandle, sourceBufferSize, SourceToDest(sourceBufferSize));
                driverHandle = IntPtr.Zero;
            }
            catch
            {
                // suppress the finalise and clean up resources
                Dispose();
                throw;
            }
        }
Ejemplo n.º 8
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");
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Attempts to add a new ACM driver from a file
        /// </summary>
        /// <param name="driverFile">Full path of the .acm or dll file containing the driver</param>
        /// <returns>Handle to the driver</returns>
        public static AcmDriver AddLocalDriver(string driverFile)
        {
            IntPtr handle = NativeMethods.LoadLibrary(driverFile);

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

            if (driverProc == IntPtr.Zero)
            {
                NativeMethods.FreeLibrary(handle);
                throw new ArgumentException("Failed to discover DriverProc");
            }
            IntPtr driverHandle;
            var    result = AcmInterop.acmDriverAdd(out driverHandle,
                                                    handle, driverProc, 0, AcmDriverAddFlags.Function);

            if (result != MmResult.NoError)
            {
                NativeMethods.FreeLibrary(handle);
                throw new MmException(result, "acmDriverAdd");
            }
            var driver = new AcmDriver(driverHandle);

            // long name seems to be missing when we use acmDriverAdd
            if (string.IsNullOrEmpty(driver.details.longName))
            {
                driver.details.longName = "Local driver: " + Path.GetFileName(driverFile);
                driver.localDllHandle   = handle;
            }
            return(driver);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Gets a list of the ACM Drivers installed
 /// </summary>
 public static IEnumerable <AcmDriver> EnumerateAcmDrivers()
 {
     drivers = new List <AcmDriver>();
     MmException.Try(
         AcmInterop.acmDriverEnum(new AcmInterop.AcmDriverEnumCallback(DriverEnumCallback), IntPtr.Zero, 0),
         "acmDriverEnum");
     return(drivers);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Closes this driver
 /// </summary>
 public void Close()
 {
     if (driverHandle != IntPtr.Zero)
     {
         MmException.Try(AcmInterop.acmDriverClose(driverHandle, 0), "acmDriverClose");
         driverHandle = IntPtr.Zero;
     }
 }
Ejemplo n.º 12
0
 // Token: 0x060007DA RID: 2010 RVA: 0x00016FCC File Offset: 0x000151CC
 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");
 }
Ejemplo n.º 13
0
 private void Prepare()
 {
     streamHeader.cbStruct            = 84;// 21 int sized params;
     streamHeader.sourceBufferLength  = sourceBuffer.Length;
     streamHeader.sourceBufferPointer = hSourceBuffer.AddrOfPinnedObject();
     streamHeader.destBufferLength    = destBuffer.Length;
     streamHeader.destBufferPointer   = hDestBuffer.AddrOfPinnedObject();
     MmException.Try(AcmInterop.acmStreamPrepareHeader(streamHandle, streamHeader, 0), "acmStreamPrepareHeader");
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a new ACM stream to convert one format to another, using a
        /// specified driver identified and wave filter
        /// </summary>
        /// <param name="driverId">the driver identifier</param>
        /// <param name="sourceFormat">the source format</param>
        /// <param name="waveFilter">the wave filter</param>
        // Token: 0x060007CD RID: 1997 RVA: 0x00016CE4 File Offset: 0x00014EE4
        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));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new ACM stream to convert one format to another, using a
        /// specified driver identified and wave filter
        /// </summary>
        /// <param name="driverId">the driver identifier</param>
        /// <param name="sourceFormat">the source format</param>
        /// <param name="waveFilter">the wave filter</param>
        public AcmStream(IntPtr driverId, WaveFormat sourceFormat, WaveFilter waveFilter)
        {
            int sourceBufferSize = Math.Max(16384, sourceFormat.AverageBytesPerSecond);

            this.sourceFormat = sourceFormat;
            sourceBufferSize -= (sourceBufferSize % sourceFormat.BlockAlign);
            MmException.Try(AcmInterop.acmDriverOpen(out driverHandle, driverId, 0), "acmDriverOpen");
            MmException.Try(AcmInterop.acmStreamOpen(out streamHandle, driverHandle,
                                                     sourceFormat, sourceFormat, waveFilter, IntPtr.Zero, IntPtr.Zero, AcmStreamOpenFlags.NonRealTime), "acmStreamOpen");
            streamHeader = new AcmStreamHeader(streamHandle, sourceBufferSize, SourceToDest(sourceBufferSize));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Returns the number of source bytes for a given number of destination bytes
        /// </summary>
        /// <param name="dest">Number of destination bytes</param>
        /// <returns>Number of source bytes</returns>
        public int DestToSource(int dest)
        {
            if (dest == 0) // zero is an invalid parameter to acmStreamSize
            {
                return(0);
            }
            int convertedBytes;

            MmException.Try(AcmInterop.acmStreamSize(streamHandle, dest, out convertedBytes, AcmStreamSizeFlags.Destination), "acmStreamSize");
            return(convertedBytes);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Returns the number of source bytes for a given number of destination bytes
        /// </summary>
        /// <param name="dest">Number of destination bytes</param>
        /// <returns>Number of source bytes</returns>
        // Token: 0x060007CF RID: 1999 RVA: 0x00016DA4 File Offset: 0x00014FA4
        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);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Removes a driver previously added using AddLocalDriver
        /// </summary>
        /// <param name="localDriver">Local driver to remove</param>
        public static void RemoveLocalDriver(AcmDriver localDriver)
        {
            if (localDriver.localDllHandle == IntPtr.Zero)
            {
                throw new ArgumentException("Please pass in the AcmDriver returned by the AddLocalDriver method");
            }
            var removeResult = AcmInterop.acmDriverRemove(localDriver.driverId, 0); // gets stored as a driver Id

            NativeMethods.FreeLibrary(localDriver.localDllHandle);
            MmException.Try(removeResult, "acmDriverRemove");
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns the number of output bytes for a given number of input bytes
        /// </summary>
        /// <param name="source">Number of input bytes</param>
        /// <returns>Number of output bytes</returns>
        public int SourceToDest(int source)
        {
            if (source == 0) // zero is an invalid parameter to acmStreamSize
            {
                return(0);
            }
            int convertedBytes;

            MmException.Try(AcmInterop.acmStreamSize(streamHandle, source, out convertedBytes, AcmStreamSizeFlags.Source), "acmStreamSize");
            return(convertedBytes);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Returns the number of output bytes for a given number of input bytes
        /// </summary>
        /// <param name="source">Number of input bytes</param>
        /// <returns>Number of output bytes</returns>
        // Token: 0x060007CE RID: 1998 RVA: 0x00016D74 File Offset: 0x00014F74
        public int SourceToDest(int source)
        {
            if (source == 0)
            {
                return(0);
            }
            int      result2;
            MmResult result = AcmInterop.acmStreamSize(this.streamHandle, source, out result2, AcmStreamSizeFlags.Source);

            MmException.Try(result, "acmStreamSize");
            return(result2);
        }
Ejemplo n.º 21
0
        // Token: 0x060007DB RID: 2011 RVA: 0x00017060 File Offset: 0x00015260
        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");
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Show Format Choose Dialog
        /// </summary>
        /// <param name="ownerWindowHandle">Owner window handle, can be null</param>
        /// <param name="windowTitle">Window title</param>
        /// <param name="enumFlags">Enumeration flags. None to get everything</param>
        /// <param name="enumFormat">Enumeration format. Only needed with certain enumeration flags</param>
        /// <param name="selectedFormat">The selected format</param>
        /// <param name="selectedFormatDescription">Textual description of the selected format</param>
        /// <param name="selectedFormatTagDescription">Textual description of the selected format tag</param>
        /// <returns>True if a format was selected</returns>
        public static bool ShowFormatChooseDialog(
            IntPtr ownerWindowHandle,
            string windowTitle,
            AcmFormatEnumFlags enumFlags,
            WaveFormat enumFormat,
            out WaveFormat selectedFormat,
            out string selectedFormatDescription,
            out string selectedFormatTagDescription)
        {
            AcmFormatChoose formatChoose = new AcmFormatChoose();

            formatChoose.structureSize     = Marshal.SizeOf(formatChoose);
            formatChoose.styleFlags        = AcmFormatChooseStyleFlags.None;
            formatChoose.ownerWindowHandle = ownerWindowHandle;
            int maxFormatSize = 200; // guess

            formatChoose.selectedWaveFormatPointer  = Marshal.AllocHGlobal(maxFormatSize);
            formatChoose.selectedWaveFormatByteSize = maxFormatSize;
            formatChoose.title                 = windowTitle;
            formatChoose.name                  = null;
            formatChoose.formatEnumFlags       = enumFlags;//AcmFormatEnumFlags.None;
            formatChoose.waveFormatEnumPointer = IntPtr.Zero;
            if (enumFormat != null)
            {
                IntPtr enumPointer = Marshal.AllocHGlobal(Marshal.SizeOf(enumFormat));
                Marshal.StructureToPtr(enumFormat, enumPointer, false);
                formatChoose.waveFormatEnumPointer = enumPointer;
            }
            formatChoose.instanceHandle = IntPtr.Zero;
            formatChoose.templateName   = null;

            MmResult result = AcmInterop.acmFormatChoose(ref formatChoose);

            selectedFormat               = null;
            selectedFormatDescription    = null;
            selectedFormatTagDescription = null;
            if (result == MmResult.NoError)
            {
                selectedFormat               = WaveFormat.MarshalFromPtr(formatChoose.selectedWaveFormatPointer);
                selectedFormatDescription    = formatChoose.formatDescription;
                selectedFormatTagDescription = formatChoose.formatTagDescription;
            }

            Marshal.FreeHGlobal(formatChoose.waveFormatEnumPointer);
            Marshal.FreeHGlobal(formatChoose.selectedWaveFormatPointer);
            if (result != MmResult.AcmCancelled && result != MmResult.NoError)
            {
                throw new MmException(result, "acmFormatChoose");
            }
            return(result == MmResult.NoError);
        }
Ejemplo n.º 23
0
        private void Unprepare()
        {
            streamHeader.sourceBufferLength  = sourceBuffer.Length;
            streamHeader.sourceBufferPointer = hSourceBuffer.AddrOfPinnedObject();
            streamHeader.destBufferLength    = destBuffer.Length;
            streamHeader.destBufferPointer   = hDestBuffer.AddrOfPinnedObject();

            MmResult result = AcmInterop.acmStreamUnprepareHeader(streamHandle, streamHeader, 0);

            if (result != MmResult.NoError)
            {
                //if (result == MmResult.AcmHeaderUnprepared)
                throw new MmException(result, "acmStreamUnprepareHeader");
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Suggests an appropriate PCM format that the compressed format can be converted
        /// to in one step
        /// </summary>
        /// <param name="compressedFormat">The compressed format</param>
        /// <returns>The PCM format</returns>
        public static WaveFormat SuggestPcmFormat(WaveFormat compressedFormat)
        {
            // create a PCM format
            WaveFormat suggestedFormat = new WaveFormat(compressedFormat.SampleRate, 16, compressedFormat.Channels);

            MmException.Try(AcmInterop.acmFormatSuggest(IntPtr.Zero, compressedFormat, suggestedFormat, Marshal.SizeOf(suggestedFormat), AcmFormatSuggestFlags.FormatTag), "acmFormatSuggest");

            /*IntPtr suggestedFormatPointer = WaveFormat.MarshalToPtr(suggestedFormat);
             * IntPtr compressedFormatPointer = WaveFormat.MarshalToPtr(compressedFormat);
             * MmResult result = AcmInterop.acmFormatSuggest2(IntPtr.Zero, compressedFormatPointer, suggestedFormatPointer, Marshal.SizeOf(suggestedFormat), AcmFormatSuggestFlags.FormatTag);
             * suggestedFormat = WaveFormat.MarshalFromPtr(suggestedFormatPointer);
             * Marshal.FreeHGlobal(suggestedFormatPointer);
             * Marshal.FreeHGlobal(compressedFormatPointer);
             * MmException.Try(result, "acmFormatSuggest");*/

            return(suggestedFormat);
        }
Ejemplo n.º 25
0
 // Token: 0x060007DD RID: 2013 RVA: 0x000170EC File Offset: 0x000152EC
 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);
 }
Ejemplo n.º 26
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 result = AcmInterop.acmFormatEnum(this.driverHandle, ref acmFormatDetails, new AcmInterop.AcmFormatEnumCallback(this.AcmFormatEnumCallback), IntPtr.Zero, AcmFormatEnumFlags.None);

            Marshal.FreeHGlobal(acmFormatDetails.waveFormatPointer);
            MmException.Try(result, "acmFormatEnum");
            return(this.tempFormatsList);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates a new ACM stream to convert one format to another. Note that
 /// not all conversions can be done in one step
 /// </summary>
 /// <param name="sourceFormat">The source audio format</param>
 /// <param name="destFormat">The destination audio format</param>
 // Token: 0x060007CC RID: 1996 RVA: 0x00016C38 File Offset: 0x00014E38
 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;
     }
 }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        public int Convert(int bytesToConvert, out int sourceBytesConverted)
        {
            Prepare();
            try
            {
                streamHeader.sourceBufferLength     = bytesToConvert;
                streamHeader.sourceBufferLengthUsed = bytesToConvert;
                AcmStreamConvertFlags flags = firstTime ? (AcmStreamConvertFlags.Start | AcmStreamConvertFlags.BlockAlign) : AcmStreamConvertFlags.BlockAlign;
                MmException.Try(AcmInterop.acmStreamConvert(streamHandle, streamHeader, flags), "acmStreamConvert");
                firstTime = false;
                System.Diagnostics.Debug.Assert(streamHeader.destBufferLength == destBuffer.Length, "Codecs should not change dest buffer length");
                sourceBytesConverted = streamHeader.sourceBufferLengthUsed;
            }
            finally
            {
                Unprepare();
            }

            return(streamHeader.destBufferLengthUsed);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets all the supported formats for a given format tag
        /// </summary>
        /// <param name="formatTag">Format tag</param>
        /// <returns>Supported formats</returns>
        public IEnumerable <AcmFormat> GetFormats(AcmFormatTag formatTag)
        {
            if (driverHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Driver must be opened first");
            }
            tempFormatsList = new List <AcmFormat>();
            AcmFormatDetails formatDetails = new AcmFormatDetails();

            formatDetails.structSize         = Marshal.SizeOf(formatDetails);
            formatDetails.waveFormatByteSize = MaxFormatSize;            // formatTag.FormatSize doesn't work;
            formatDetails.waveFormatPointer  = Marshal.AllocHGlobal(formatDetails.waveFormatByteSize);
            formatDetails.formatTag          = (int)formatTag.FormatTag; // (int)WaveFormatEncoding.Unknown
            MmResult result = AcmInterop.acmFormatEnum(driverHandle,
                                                       ref formatDetails, AcmFormatEnumCallback, IntPtr.Zero,
                                                       AcmFormatEnumFlags.None);

            Marshal.FreeHGlobal(formatDetails.waveFormatPointer);
            MmException.Try(result, "acmFormatEnum");
            return(tempFormatsList);
        }