public static void InitMediaLib() { logger.Debug("MainForm::Init()"); SharpDX.MediaFoundation.MediaManager.Startup(); SharpDX.Configuration.EnableReleaseOnFinalizer = true; WinMM.timeBeginPeriod(1); }
//(UInt32 timer_id, UInt32 msg, UIntPtr user_ctx, UIntPtr reserve1, UIntPtr reserve2); public void Start() { if (Period <= 0) { throw new InvalidOperationException($"Invalid period value [{Period}]"); } Stop(); TimerID = WinMM.TimeSetEvent(Period, Resolution, new MMTimerCallback(TimerCallback), UIntPtr.Zero, EventType); }
private static void Main() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; // set timer resolution to 1ms to try and get the sleep accurate in the wait loop WinMM.TimeBeginPeriod(1); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }
} // Test static void Chk(int f) { if (0 == f) { return; } var sb = new StringBuilder(256); // MAXERRORLENGTH var s = 0 == WinMM.midiOutGetErrorText(f, sb, sb.Capacity) ? sb.ToString() : String.Format("MIDI Error {0}.", f); System.Diagnostics.Trace.WriteLine(s); }
public static void Deinitialize() { try { if (_gcHandle != null) { WinMM.PlaySound(null, (UIntPtr)0, 0); _gcHandle.Value.Free(); _gcHandle = null; } } catch (Exception e) { Log.Error("Error in deinitialize.", e); } }
public static void Deinitialize() { try { if (gcHandle != null) { WinMM.PlaySound((byte[])null, (UIntPtr)0, (uint)0); gcHandle.Value.Free(); gcHandle = null; } } catch (Exception e) { LOG.Error("Error in deinitialize.", e); } }
/// <devdoc> /// <para>Initializes a new instance of the UIMillisecondTimer. /> /// class.</para> /// </devdoc> public UIMillisecondTimer() { int result = WinMM.timeGetDevCaps(ref TimeCaps, Marshal.SizeOf(TimeCaps)); if (result != WinMM.TIMERR_NOERROR) { throw new Exception("毫秒定时器初始化失败"); } Version = UIGlobal.Version; interval = 50; SetEventCallback = DoSetEventCallback; }
public void Close() { lock (_disposeLock) { Mute(); if (this._hwih == IntPtr.Zero) { return; } WinMM.waveInClose(this._hwih); this.FreeHeaders(); _isMuted = true; this._hwih = IntPtr.Zero; } }
public void WM_KEYDOWN(IntPtr hWnd, IntPtr wParam, IntPtr lParam) { if (wParam == new IntPtr(0x20)) { WinMM.PlaySound(null, IntPtr.Zero, WinMM.PLAYSOUNDFLAGS.SND_ASYNC | WinMM.PLAYSOUNDFLAGS.SND_FILENAME | WinMM.PLAYSOUNDFLAGS.SND_NODEFAULT | WinMM.PLAYSOUNDFLAGS.SND_NOWAIT | WinMM.PLAYSOUNDFLAGS.SND_PURGE); _hMic32?.Toggle(); } }
static bool Play( string cliScript, Func <bool> IsTerminated) { if (cliScript.StartsWith("--play")) { cliScript = cliScript.Remove(0, "--play".Length).Trim(); } else if (cliScript.StartsWith("play")) { cliScript = cliScript.Remove(0, "play".Length).Trim(); } else { throw new ArgumentException(); } string md = cliScript; if (!File.Exists(md) && string.IsNullOrWhiteSpace(Path.GetExtension(md))) { if (File.Exists(Path.ChangeExtension(md, ".md"))) { md = Path.ChangeExtension(md, ".md"); } } var Model = File.Exists(md) ? System.Ai.Model.LoadFromFile(md, System.Ai.Cli.SIZE, out string fmt, out int dims) : BuildFromFragment(md); Console.Write($"Synthesizing: {Path.ChangeExtension(md, ".g.wav")}...\r\n"); Wav.Write(Path.ChangeExtension(md, ".g.wav"), Wav.Synthesize(Model.GetBuffer())); StartWinUI(() => { return(Model); }, Path.ChangeExtension(md, ".g.wav")); WinMM.PlaySound(Path.ChangeExtension(md, ".g.wav"), IntPtr.Zero, WinMM.PLAYSOUNDFLAGS.SND_ASYNC | WinMM.PLAYSOUNDFLAGS.SND_FILENAME | WinMM.PLAYSOUNDFLAGS.SND_NODEFAULT | WinMM.PLAYSOUNDFLAGS.SND_NOWAIT | WinMM.PLAYSOUNDFLAGS.SND_PURGE); return(false); }
static void Main() { MediaToolkitManager.Startup(); //DwmApi.DisableAero(true); Shcore.SetProcessPerMonitorDpiAwareness(); WinMM.timeBeginPeriod(1); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form2()); WinMM.timeEndPeriod(1); }
public static void Play() { SoundFlags flags = SoundFlags.SND_ASYNC | SoundFlags.SND_MEMORY; try { if (soundBuffer != null) { WinMM.PlaySound(gcHandle.Value.AddrOfPinnedObject(), (UIntPtr)0, (uint)flags); } else { WinMM.PlaySound((byte[])null, (UIntPtr)0, (uint)flags); } } catch (Exception e) { LOG.Error("Error in play.", e); } }
public static void Play() { if (soundBuffer != null) { //Thread playSoundThread = new Thread(delegate() { SoundFlags flags = SoundFlags.SND_ASYNC | SoundFlags.SND_MEMORY | SoundFlags.SND_NOWAIT | SoundFlags.SND_NOSTOP; try { WinMM.PlaySound(gcHandle.Value.AddrOfPinnedObject(), (UIntPtr)0, (uint)flags); } catch (Exception e) { LOG.Error("Error in play.", e); } //}); //playSoundThread.Name = "Play camera sound"; //playSoundThread.IsBackground = true; //playSoundThread.Start(); } }
static public void UpdateDevices() { var maxDevices = WinMM.joyGetNumDevs(); for (uint j = 0; j < maxDevices; j++) { var caps = new JOYCAPS(); var size = (uint)Marshal.SizeOf(caps); var joystickCaps = WinMM.joyGetDevCaps(j, out caps, size); if (joystickCaps == MMRESULT.MMSYSERR_NOERROR) { Controller c = null; foreach (Controller found in Devices) { if (found.DeviceId == j) { c = found; } } if (c == null) { c = new Controller { DeviceId = j, }; Devices.Add(c); } if (!(c.ManufacturerId == caps.Mid && c.ProductId == caps.Pid)) { c.ButtonsAvailable = (Buttons)(caps.NumButtons == 32 ? 0xFFFF_FFFFu : (1u << (int)caps.NumButtons) - 1u); c._registryKeyName = caps.RegKey; Trace.WriteLine($"HID #{j} changed from {c.ManufacturerId}/{c.ProductId} to {caps.Mid}/{caps.Pid} with {caps.NumButtons} buttons ({c.Name})"); c.ManufacturerId = caps.Mid; // vJoy 4660 c.ProductId = caps.Pid; // vJoy 48813 } } else if (joystickCaps != MMRESULT.JOYERR_PARMS) { Trace.WriteLine($"WinMM.joyGetDevCaps({j}, out caps, {size}) / {maxDevices} returned: {joystickCaps}"); } } }
/// <summary> /// /// </summary> /// <returns></returns> public static List <Joystick> GetJoysticks() { List <Joystick> ret = new List <Joystick>(); WinMM.JOYCAPS tmpJoyCaps = new WinMM.JOYCAPS(); for (uint i = 0; i < MAX_JOYSTICK_DEVICES; i++) { if (WinMM.joyGetDevCaps((UIntPtr)i, ref tmpJoyCaps, 404) == WinMM.JOYERR_NOERROR) // Get joystick info { WinMM.JOYINFO joyinfo = new WinMM.JOYINFO(); if (WinMM.joyGetPos(i, ref joyinfo) == WinMM.JOYERR_NOERROR) { ret.Add(new Joystick(i)); } } } return(ret); }
/// <summary> /// /// </summary> public Joystick(uint joyNum) { WinMM.JOYCAPS joyCaps = new WinMM.JOYCAPS(); if (WinMM.joyGetDevCaps((UIntPtr)joyNum, ref joyCaps, 404) != 0) //Get joystick info { throw new Exception("Joystick is not ready."); } ID = joyNum; Name = joyCaps.szPname; HasZ = (joyCaps.wCaps & WinMM.JOYCAPS_HASZ) != 0; HasR = (joyCaps.wCaps & WinMM.JOYCAPS_HASR) != 0; HasU = (joyCaps.wCaps & WinMM.JOYCAPS_HASU) != 0; HasV = (joyCaps.wCaps & WinMM.JOYCAPS_HASV) != 0; HasPOV = (joyCaps.wCaps & WinMM.JOYCAPS_HASPOV) != 0; IsPOV4DIR = (joyCaps.wCaps & WinMM.JOYCAPS_POV4DIR) != 0; IsPOVCTS = (joyCaps.wCaps & WinMM.JOYCAPS_POVCTS) != 0; NumberOfAxes = joyCaps.wNumAxes; NumberOfButtons = joyCaps.wNumButtons; }
public static class MidiTest { // version 3 - x68/x64 32/64-bit compatible public static void Test() { int moID = 0; // midi out device/port ID IntPtr moHdl = IntPtr.Zero; #if !true // SysEx via midiOutLongMsg works Chk(WinMM.midiOutOpen(out moHdl, moID, null, 0, 0)); // open midi out in non-stream mode #else // SysEx via midiOutLongMsg fails IntPtr instance = IntPtr.Zero; Chk(WinMM.midiStreamOpen(out moHdl, ref moID, 1, null, instance, 0)); // open midi out in stream mode #endif byte[] sx = { 0xF0, 0x7E, 0x7F, 0x09, 0x01, 0xF7 }; // GM On sysex int shdr = Marshal.SizeOf(typeof(MidiHdr)); // hdr size IntPtr x = Marshal.OffsetOf(typeof(MidiHdr), "data"); // ptr; size: 4/8, offset: 0 x = Marshal.OffsetOf(typeof(MidiHdr), "bufferLength"); // int; size: 4 , offset: 4/8 x = Marshal.OffsetOf(typeof(MidiHdr), "bytesRecorded"); // int; size: 4 , offset: 8/12 x = Marshal.OffsetOf(typeof(MidiHdr), "user"); // ptr; size: 4/8, offset: 12/16 x = Marshal.OffsetOf(typeof(MidiHdr), "flags"); // int; size: 4 , offset: 16/24; followed by 4 byte padding x = Marshal.OffsetOf(typeof(MidiHdr), "next"); // ptr; size: 4/8, offset: 20/32 x = Marshal.OffsetOf(typeof(MidiHdr), "reserved"); // ptr; size: 4/8, offset: 24/40 x = Marshal.OffsetOf(typeof(MidiHdr), "offset"); // int; size: 4 , offset: 28/48; followed by 4 byte padding x = Marshal.OffsetOf(typeof(MidiHdr), "reservedArray"); // ptr; size: 4/8 x 8 = 32/64, offset: 32/56 // total size: 64/120 var mhdr = new MidiHdr(); // allocate managed hdr mhdr.bufferLength = mhdr.bytesRecorded = sx.Length; // length of message bytes mhdr.data = Marshal.AllocHGlobal(mhdr.bufferLength); // allocate native message bytes Marshal.Copy(sx, 0, mhdr.data, mhdr.bufferLength); // copy message bytes from managed to native memory IntPtr nhdr = Marshal.AllocHGlobal(shdr); // allocate native hdr Marshal.StructureToPtr(mhdr, nhdr, false); // copy managed hdr to native hdr Chk(WinMM.midiOutPrepareHeader(moHdl, nhdr, shdr)); // prepare native hdr int r = WinMM.midiOutLongMsg(moHdl, nhdr, shdr); // send native message bytes Chk(r); // send native message bytes } // Test
private uint OnWaveOutGetDevCaps(uint udeviceid, ref WinMM.tagWAVEOUTCAPSW pwoc, uint cbwoc) { if (BypassLocalOverrides) { return WinMM.waveOutGetDevCaps(udeviceid, ref pwoc, cbwoc); } _log.Debug("WaveOutGetDevCaps"); uint deviceID = GetDeviceID(); uint result = WinMM.waveOutGetDevCaps(deviceID, ref pwoc, cbwoc); if (result != 0 && deviceID != WinMM.WAVE_MAPPER) { result = WinMM.waveOutGetDevCaps(WinMM.WAVE_MAPPER, ref pwoc, cbwoc); } return result; }
static bool Md( string cliScript, Func <bool> IsTerminated) { if (cliScript.StartsWith("--md")) { cliScript = cliScript.Remove(0, "--md".Length).Trim(); } else if (cliScript.StartsWith("md")) { cliScript = cliScript.Remove(0, "md".Length).Trim(); } else { throw new ArgumentException(); } string inWavFile = Path.GetFullPath(cliScript); if (!File.Exists(inWavFile) && string.IsNullOrWhiteSpace(Path.GetExtension(inWavFile))) { if (File.Exists(Path.ChangeExtension(inWavFile, ".wav"))) { inWavFile = Path.ChangeExtension(inWavFile, ".wav"); } } var inWav = Wav.Read(inWavFile); Set filter = new Set( "C3" ); Matrix Model = System.Ai.Mel.ShortTimeFourierTransform(inWav, filter, 0.01, -20, +20); SaveMidi( Model.GetBuffer(), "MIDI", Path.ChangeExtension(inWavFile, ".md")); Model = System.Ai.Model.LoadFromFile( Path.ChangeExtension(inWavFile, ".md"), System.Ai.Cli.SIZE, out string fmt, out CBOW.DIMS); Console.Write($"\r\nSynthesizing: {Path.ChangeExtension(inWavFile, ".g.wav")}...\r\n"); Wav.Write( Path.ChangeExtension(inWavFile, ".g.wav"), Wav.Synthesize(Model.GetBuffer()) ); StartWinUI( () => { return(Model); }, Path.ChangeExtension(inWavFile, ".g.wav") ); WinMM.PlaySound(Path.ChangeExtension(inWavFile, ".g.wav"), IntPtr.Zero, WinMM.PLAYSOUNDFLAGS.SND_ASYNC | WinMM.PLAYSOUNDFLAGS.SND_FILENAME | WinMM.PLAYSOUNDFLAGS.SND_NODEFAULT | WinMM.PLAYSOUNDFLAGS.SND_NOWAIT | WinMM.PLAYSOUNDFLAGS.SND_PURGE); return(false); }
private uint OnWaveOutOpen(ref IntPtr phwo, uint udeviceid, ref WinMM.tWAVEFORMATEX pwfx, uint dwcallback, uint dwcallbackinstance, uint fdwopen) { if (BypassLocalOverrides) { return WinMM.waveOutOpen(ref phwo, udeviceid, ref pwfx, dwcallback, dwcallbackinstance, fdwopen); } _log.Debug("WaveOutOpen"); uint deviceID = GetDeviceID(); uint result = WinMM.waveOutOpen(ref phwo, deviceID, ref pwfx, dwcallback, dwcallbackinstance, fdwopen); if (result != 0 && deviceID != WinMM.WAVE_MAPPER) { result = WinMM.waveOutOpen(ref phwo, WinMM.WAVE_MAPPER, ref pwfx, dwcallback, dwcallbackinstance, fdwopen); } return result; }