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
 public static new void Try(MmResult result, string target)
 {
     if (result != MmResult.MMSYSERR_NOERROR)
     {
         throw new MmException(result, target);
     }
 }
Ejemplo n.º 3
0
        public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType)
        {
            List <MixerControl> list = new List <MixerControl>();

            if (mixerLine.ControlsCount > 0)
            {
                int num = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                MixerInterop.MIXERLINECONTROLS mIXERLINECONTROLS = default(MixerInterop.MIXERLINECONTROLS);
                IntPtr intPtr = Marshal.AllocHGlobal(num * mixerLine.ControlsCount);
                mIXERLINECONTROLS.cbStruct  = Marshal.SizeOf(mIXERLINECONTROLS);
                mIXERLINECONTROLS.dwLineID  = mixerLine.LineId;
                mIXERLINECONTROLS.cControls = mixerLine.ControlsCount;
                mIXERLINECONTROLS.pamxctrl  = intPtr;
                mIXERLINECONTROLS.cbmxctrl  = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                try
                {
                    MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mIXERLINECONTROLS, MixerFlags.Mixer | mixerHandleType);
                    if (mmResult != MmResult.NoError)
                    {
                        throw new MmException(mmResult, "mixerGetLineControls");
                    }
                    for (int i = 0; i < mIXERLINECONTROLS.cControls; i++)
                    {
                        MixerInterop.MIXERCONTROL mIXERCONTROL = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)(intPtr.ToInt64() + (long)(num * i)), typeof(MixerInterop.MIXERCONTROL));
                        MixerControl item = MixerControl.GetMixerControl(mixerHandle, mixerLine.LineId, mIXERCONTROL.dwControlID, mixerLine.Channels, mixerHandleType);
                        list.Add(item);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(intPtr);
                }
            }
            return(list);
        }
Ejemplo n.º 4
0
#pragma warning restore 618

        /// <summary>
        ///     Initializes a new instance of the <see cref="MmException" /> class.
        /// </summary>
        /// <param name="result">Errorcode.</param>
        /// <param name="function">Name of the function which returned the specified <paramref name="result" />.</param>
        public MmException(MmResult result, string function)
        {
            Result = result;
#pragma warning disable 618
            Target = function;
#pragma warning restore 618
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stop and reset the WaveOut device
        /// </summary>
        public void Stop()
        {
            if (m_PlaybackState != PlaybackState.Stopped)
            {
                return;
            }

            // in the call to waveOutReset with function callbacks
            // some drivers will block here until OnDone is called
            // for every buffer
            m_PlaybackState = PlaybackState.Stopped; // set this here to avoid a problem with some drivers whereby
            CallbackEvent?.WaitOne(DesiredLatency);

            MmResult result = default(MmResult);

            lock (WaveOutLock)
                result = WaveInterop.NativeMethods.waveOutReset(DeviceHandle);

            if (result != MmResult.NoError)
            {
                throw new MmException(result, nameof(WaveInterop.NativeMethods.waveOutReset));
            }

            CallbackEvent.Set(); // give the thread a kick, make sure we exit
        }
Ejemplo n.º 6
0
 public static new void Try(MmResult result, string target)
 {
     if (result != MmResult.MMSYSERR_NOERROR)
     {
         throw new MmException(result, target);
     }
 }
Ejemplo n.º 7
0
        public static void InitializeJoystick()
        {
            joystickCaps      = new JoystickCaps[JoystickCount];
            joystickAvailable = new bool[JoystickCount];
            joystickState     = new JoyInfoEx[JoystickCount];

            MmResult ret = MmResult.NoError;

            for (int i = 0; i < JoystickCount; i++)
            {
                switch (ret = joyGetDevCaps((JoystickID)i, out joystickCaps[i], JoystickCaps.Size))
                {
                case MmResult.NoError:
                    joystickAvailable[i]   = true;
                    joystickState[i].Size  = (uint)Marshal.SizeOf(typeof(JoyInfoEx));
                    joystickState[i].Flags = JoyInfoFlags.ReturnALL;
                    break;

                default:
                    Debug.WriteLine(ret, "Joystick" + i.ToString());
                    joystickAvailable[i] = false;
                    break;
                }
            }
        }
Ejemplo n.º 8
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.º 9
0
 /// <summary>
 /// Helper function to automatically raise an exception on failure
 /// </summary>
 /// <param name="result">The result of the API call</param>
 /// <param name="function">The API function name</param>
 public static void Try(MmResult result, string function)
 {
     if (result != MmResult.NoError)
     {
         throw new MmException(result, function);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets all the mixer controls
        /// </summary>
        /// <param name="mixerHandle"></param>
        /// <param name="mixerLine"></param>
        /// <param name="mixerHandleType"></param>
        /// <returns></returns>
        public static IList <MixerControl> GetMixerControls(IntPtr mixerHandle, MixerLine mixerLine, MixerFlags mixerHandleType)
        {
            List <MixerControl> controls = new List <MixerControl>();

            if (mixerLine.ControlsCount > 0)
            {
                int mixerControlSize = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));
                MixerInterop.MIXERLINECONTROLS mlc = new MixerInterop.MIXERLINECONTROLS();
                IntPtr pmc = Marshal.AllocHGlobal(mixerControlSize * mixerLine.ControlsCount);
                mlc.cbStruct  = Marshal.SizeOf(mlc);
                mlc.dwLineID  = mixerLine.LineId;
                mlc.cControls = mixerLine.ControlsCount;
                mlc.pamxctrl  = pmc;
                mlc.cbmxctrl  = Marshal.SizeOf(typeof(MixerInterop.MIXERCONTROL));

                MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.All | mixerHandleType);
                if (err != MmResult.NoError)
                {
                    Marshal.FreeHGlobal(pmc);
                    throw new MmException(err, "mixerGetLineControls");
                }
                for (int i = 0; i < mlc.cControls; i++)
                {
                    Int64 address = pmc.ToInt64() + mixerControlSize * i;

                    MixerInterop.MIXERCONTROL mc = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)address, typeof(MixerInterop.MIXERCONTROL));
                    MixerControl mixerControl    = GetMixerControl(mixerHandle, mixerLine.LineId, mc.dwControlID, mixerLine.Channels, mixerHandleType);

                    controls.Add(mixerControl);
                }
            }
            return(controls);
        }
Ejemplo n.º 11
0
#pragma warning restore 618

        /// <summary>
        ///     Initializes a new instance of the <see cref="MmException" /> class.
        /// </summary>
        /// <param name="result">Errorcode.</param>
        /// <param name="function">Name of the function which returned the specified <paramref name="result" />.</param>
        public MmException(MmResult result, string function)
        {
            Result = result;
#pragma warning disable 618
            Target = function;
#pragma warning restore 618
        }
Ejemplo n.º 12
0
        private void OpenWaveInDevice()
        {
            this.CloseWaveInDevice();
            MmResult result = this.callbackInfo.WaveInOpen(out this.waveInHandle, this.DeviceNumber, this.WaveFormat, this.callback);

            MmException.Try(result, "waveInOpen");
            this.CreateBuffers();
        }
Ejemplo n.º 13
0
        private void OpenWaveInDevice()
        {
            this.CloseWaveInDevice();
            MmResult result = WaveInterop.waveInOpenWindow(out this.waveInHandle, (IntPtr)this.DeviceNumber, this.WaveFormat, this.callbackEvent.SafeWaitHandle.DangerousGetHandle(), IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackEvent);

            MmException.Try(result, "waveInOpen");
            this.CreateBuffers();
        }
Ejemplo n.º 14
0
        private void OpenWaveInDevice()
        {
            CloseWaveInDevice();
            MmResult result = callbackInfo.WaveInOpen(out waveInHandle, DeviceNumber, WaveFormat, callback);

            MmException.Try(result, "waveInOpen");
            CreateBuffers();
        }
Ejemplo n.º 15
0
        public static void SetVolume(IntPtr waveOut, float left, float right)
        {
            uint     tmp    = (uint)(left * 0xFFFF) + ((uint)(right * 0xFFFF) << 16);
            MmResult result = waveOutSetVolume(waveOut, tmp);

            MmException.Try(result,
                            "waveOutSetVolume");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets a specified Mixer Control
        /// </summary>
        /// <param name="mixerHandle">Mixer Handle</param>
        /// <param name="nLineId">Line ID</param>
        /// <param name="controlId">Control ID</param>
        /// <param name="nChannels">Number of Channels</param>
        /// <param name="mixerFlags">Flags to use (indicates the meaning of mixerHandle)</param>
        /// <returns></returns>
        public static MixerControl GetMixerControl(IntPtr mixerHandle, int nLineId, int controlId, int nChannels,
                                                   MixerFlags mixerFlags)
        {
            var mlc = new MixerInterop.MIXERLINECONTROLS();
            var mc  = new MixerInterop.MIXERCONTROL();

            // set up the pointer to a structure
            IntPtr pMixerControl = Marshal.AllocCoTaskMem(Marshal.SizeOf(mc));

            //Marshal.StructureToPtr(mc, pMixerControl, false);

            mlc.cbStruct    = Marshal.SizeOf(mlc);
            mlc.cControls   = 1;
            mlc.dwControlID = controlId;
            mlc.cbmxctrl    = Marshal.SizeOf(mc);
            mlc.pamxctrl    = pMixerControl;
            mlc.dwLineID    = nLineId;
            MmResult err = MixerInterop.mixerGetLineControls(mixerHandle, ref mlc, MixerFlags.OneById | mixerFlags);

            if (err != MmResult.NoError)
            {
                Marshal.FreeCoTaskMem(pMixerControl);
                throw new MmException(err, "mixerGetLineControls");
            }

            // retrieve the structure from the pointer
            mc = Marshal.PtrToStructure <MixerInterop.MIXERCONTROL>(mlc.pamxctrl);
            Marshal.FreeCoTaskMem(pMixerControl);

            if (IsControlBoolean(mc.dwControlType))
            {
                return(new BooleanMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }

            if (IsControlSigned(mc.dwControlType))
            {
                return(new SignedMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }

            if (IsControlUnsigned(mc.dwControlType))
            {
                return(new UnsignedMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }

            if (IsControlListText(mc.dwControlType))
            {
                return(new ListTextMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }

            if (IsControlCustom(mc.dwControlType))
            {
                return(new CustomMixerControl(mc, mixerHandle, mixerFlags, nChannels));
            }

            throw new InvalidOperationException($"Unknown mixer control type {mc.dwControlType}");
        }
Ejemplo n.º 17
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");
        }
Ejemplo n.º 18
0
        public static float GetVolume(IntPtr waveOut)
        {
            uint     volume = 0;
            MmResult result = MMInterops.waveOutGetVolume(waveOut, out volume);

            if (result != MmResult.MMSYSERR_NOERROR)
            {
                MmException.Try(result, "waveOutGetVolume");
            }
            return(CSCore.Utils.CSMath.IntToWaveOutVolume(volume));
        }
Ejemplo n.º 19
0
        public static void SetVolume(IntPtr waveOut, float left, float right)
        {
            uint     tmp    = CSCore.Utils.CSMath.FloatToWaveOutVolume(left, right);
            MmResult result = MMInterops.waveOutSetVolume(waveOut, tmp);

            if (result != MmResult.MMSYSERR_NOERROR)
            {
                MmException.Try(MMInterops.waveOutSetVolume(waveOut, tmp),
                                "waveOutSetVolume");
            }
        }
Ejemplo n.º 20
0
        public static float GetVolume(IntPtr waveOut)
        {
            uint     volume;
            MmResult result = waveOutGetVolume(waveOut, out volume);

            MmException.Try(result, "waveOutGetVolume");
            HightLowConverterUInt32 u = new HightLowConverterUInt32(volume);
            uint left  = u.High;
            uint right = u.Low;

            return((float)(((right + left) / 2.0) * (1.0 / 0xFFFF)));
        }
Ejemplo n.º 21
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.º 22
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.º 23
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.º 24
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.º 25
0
        private unsafe void Unprepare()
        {
            streamHeader.sourceBufferLength  = sourceBuffer.Length;
            streamHeader.sourceBufferPointer = (IntPtr)hSourceBuffer.Pointer;
            streamHeader.destBufferLength    = destBuffer.Length;
            streamHeader.destBufferPointer   = (IntPtr)hDestBuffer.Pointer;

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

            if (result != MmResult.NoError)
            {
                //if (result == MmResult.AcmHeaderUnprepared)
                throw new MmException(result, "acmStreamUnprepareHeader");
            }
        }
Ejemplo n.º 26
0
        public void SendBuffer(byte[] byteBuffer)
        {
            MidiInterop.MIDIHDR midihdr = default(MidiInterop.MIDIHDR);
            midihdr.lpData = Marshal.AllocHGlobal(byteBuffer.Length);
            Marshal.Copy(byteBuffer, 0, midihdr.lpData, byteBuffer.Length);
            midihdr.dwBufferLength  = byteBuffer.Length;
            midihdr.dwBytesRecorded = byteBuffer.Length;
            int uSize = Marshal.SizeOf(midihdr);

            MidiInterop.midiOutPrepareHeader(this.hMidiOut, ref midihdr, uSize);
            MmResult mmResult = MidiInterop.midiOutLongMsg(this.hMidiOut, ref midihdr, uSize);

            if (mmResult != MmResult.NoError)
            {
                MidiInterop.midiOutUnprepareHeader(this.hMidiOut, ref midihdr, uSize);
            }
            Marshal.FreeHGlobal(midihdr.lpData);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Gets a specified Mixer Control
        /// </summary>
        /// <param name="mixerHandle">Mixer Handle</param>
        /// <param name="nLineID">Line ID</param>
        /// <param name="controlId">Control ID</param>
        /// <param name="nChannels">Number of Channels</param>
        /// <param name="mixerFlags">Flags to use (indicates the meaning of mixerHandle)</param>
        /// <returns></returns>
        // Token: 0x060005CC RID: 1484 RVA: 0x00012DC8 File Offset: 0x00010FC8
        public static MixerControl GetMixerControl(IntPtr mixerHandle, int nLineID, int controlId, int nChannels, MixerFlags mixerFlags)
        {
            MixerInterop.MIXERLINECONTROLS mixerlinecontrols = default(MixerInterop.MIXERLINECONTROLS);
            MixerInterop.MIXERCONTROL      mixercontrol      = default(MixerInterop.MIXERCONTROL);
            IntPtr intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(mixercontrol));

            mixerlinecontrols.cbStruct    = Marshal.SizeOf(mixerlinecontrols);
            mixerlinecontrols.cControls   = 1;
            mixerlinecontrols.dwControlID = controlId;
            mixerlinecontrols.cbmxctrl    = Marshal.SizeOf(mixercontrol);
            mixerlinecontrols.pamxctrl    = intPtr;
            mixerlinecontrols.dwLineID    = nLineID;
            MmResult mmResult = MixerInterop.mixerGetLineControls(mixerHandle, ref mixerlinecontrols, MixerFlags.ListText | mixerFlags);

            if (mmResult != MmResult.NoError)
            {
                Marshal.FreeCoTaskMem(intPtr);
                throw new MmException(mmResult, "mixerGetLineControls");
            }
            mixercontrol = (MixerInterop.MIXERCONTROL)Marshal.PtrToStructure(mixerlinecontrols.pamxctrl, typeof(MixerInterop.MIXERCONTROL));
            Marshal.FreeCoTaskMem(intPtr);
            if (MixerControl.IsControlBoolean(mixercontrol.dwControlType))
            {
                return(new BooleanMixerControl(mixercontrol, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlSigned(mixercontrol.dwControlType))
            {
                return(new SignedMixerControl(mixercontrol, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlUnsigned(mixercontrol.dwControlType))
            {
                return(new UnsignedMixerControl(mixercontrol, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlListText(mixercontrol.dwControlType))
            {
                return(new ListTextMixerControl(mixercontrol, mixerHandle, mixerFlags, nChannels));
            }
            if (MixerControl.IsControlCustom(mixercontrol.dwControlType))
            {
                return(new CustomMixerControl(mixercontrol, mixerHandle, mixerFlags, nChannels));
            }
            throw new InvalidOperationException(string.Format("Unknown mixer control type {0}", mixercontrol.dwControlType));
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
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.º 30
0
        /// <summary>
        /// Resume playing after a pause from the same position
        /// </summary>
        public void Resume()
        {
            if (Thread.CurrentThread.ManagedThreadId != waveOutThread.ManagedThreadId)
            {
                lock (actionQueue)
                {
                    actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.Resume, null));
                    workAvailable.Set();
                }
                return;
            }

            MmResult result = WaveInterop.waveOutRestart(hWaveOut);

            if (result != MmResult.NoError)
            {
                throw new MmException(result, "waveOutRestart");
            }
            playbackState = PlaybackState.Playing;
        }
Ejemplo n.º 31
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);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Stop and reset the WaveOut device
        /// </summary>
        public void Stop()
        {
            if (Thread.CurrentThread.ManagedThreadId != waveOutThread.ManagedThreadId)
            {
                lock (actionQueue)
                {
                    actionQueue.Enqueue(new WaveOutAction(WaveOutFunction.Stop, null));
                    workAvailable.Set();
                }
                return;
            }

            playbackState = PlaybackState.Stopped;
            buffersQueued = false;
            MmResult result = WaveInterop.waveOutReset(hWaveOut);

            if (result != MmResult.NoError)
            {
                throw new MmException(result, "waveOutReset");
            }
        }
Ejemplo n.º 33
0
 public static extern MmResult waveInGetErrorText(MmResult mmrError, StringBuilder pszText, int cchText);
Ejemplo n.º 34
0
 public AcmException(MmResult result, string function)
     : base(result, function)
 {
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Helper function to automatically raise an exception on failure
 /// </summary>
 /// <param name="result">The result of the API call</param>
 /// <param name="function">The API function name</param>
 public static void Try(MmResult result, string function)
 {
     if (result != MmResult.NoError)
         throw new MmException(result, function);
 }
Ejemplo n.º 36
0
 private static string ErrorMessage(MmResult result, string function)
 {
     return String.Format("{0} calling {1}", result, function);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Creates a new MmException
 /// </summary>
 /// <param name="result">The result returned by the Windows API call</param>
 /// <param name="function">The name of the Windows API that failed</param>
 public MmException(MmResult result, string function)
     : base(MmException.ErrorMessage(result, function))
 {
     this.result = result;
     this.function = function;
 }
Ejemplo n.º 38
0
 public MmException(MmResult result, string function)
 {
     Result = result;
     Target = function;
 }