public void CheckWithLinq(int channelCount, int sourceLength, int windowLength, int position)
        {
            var random = new Random(57);
            var source = new double[channelCount][];

            for (var ch = 0; ch < channelCount; ch++)
            {
                source[ch] = Enumerable.Range(0, sourceLength).Select(t => random.NextDouble()).ToArray();
            }
            var window = WindowFunctions.Hann(windowLength);

            var expected = new double[channelCount][];

            for (var ch = 0; ch < channelCount; ch++)
            {
                expected[ch] = source[ch].Skip(position).Take(windowLength).ToArray();
                for (var t = 0; t < expected.Length; t++)
                {
                    expected[ch][t] *= window[t];
                }
            }

            var actual = Framing.GetFrame(source, window, position);

            for (var ch = 0; ch < channelCount; ch++)
            {
                for (var t = 0; t < actual.Length; t++)
                {
                    Assert.AreEqual(expected[ch][t], actual[ch][t], 1.0E-9);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Waits for an instance of the game window to spawn (searches window by name).
        /// Proceeds to wait until said window is visible to the end user.
        /// </summary>
        /// <param name="gameWindowName">The name of the game window to find the handle for.</param>
        private static async Task <IntPtr> FindWindowHandleByName(string gameWindowName)
        {
            // Provide our own interactive timeout.
            int attempts            = 0;
            int threadSleepTime     = 16;
            int timeoutMilliseconds = 1000;

            // Handle of the game window
            IntPtr windowHandle = (IntPtr)0;

            // Wait for Game Window to spawn.
            while (true)
            {
                // Increase attempts.
                attempts++;

                // Get the handle for the Sonic_Heroes Window
                windowHandle = WindowFunctions.FindWindow(null, gameWindowName);

                // If handle successfully acquired.
                if (windowHandle != (IntPtr)0)
                {
                    return(windowHandle);
                }

                // Check timeout
                if (attempts > timeoutMilliseconds / threadSleepTime)
                {
                    return((IntPtr)0);
                }

                // Sleep to reduce CPU load.
                await Task.Delay(threadSleepTime);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Class constructor. Instantiates both the overlay and DirectX Stuff.
        /// </summary>
        /// <param name="gameWindowName">
        ///     The name of the window to be overlayed.
        ///     The window may be the game window or another window elsewhere.
        /// </param>
        /// <param name="renderDelegate">
        ///     The user delegate which you may use for rendering to the external overlay
        ///     window with Direct2D.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        /// <returns>
        ///     1. True if the window has been found and overlay has been instantiated, else false.
        ///     2. An instance of self (ExternalWindowOverlay) with the overlay enabled and running.
        /// </returns>
        public static async Task <(bool success, D2DOverlay overlay)> CreateExternalWindowOverlay(string gameWindowName, D2DWindowRenderer.DelegateRenderDirect2D renderDelegate, int hookDelay)
        {
            // Apply hook delay
            await Task.Delay(hookDelay);

            // Create self.
            D2DOverlay externalWindowOverlay = new D2DOverlay();

            // Wait for and find the game window.
            IntPtr windowHandle = await FindWindowHandleByName(gameWindowName);

            // If the handle has been acquired.
            if (windowHandle != (IntPtr)0)
            {
                // Wait for the Window to show itself to screen before configuring.
                while (WindowFunctions.IsWindowVisible(windowHandle) == false)
                {
                    await Task.Delay(32);
                }

                // Enable the overlay.
                externalWindowOverlay.EnableOverlay(renderDelegate, windowHandle);

                // Returns true.
                return(true, externalWindowOverlay);
            }

            // Return false, window was not found.
            return(false, externalWindowOverlay);
        }
Beispiel #4
0
        /// <summary>
        /// Class constructor. Instantiates both the overlay and DirectX Stuff.
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="renderDelegate">
        ///     The user delegate which you may use for rendering to the external overlay
        ///     window with Direct2D.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        /// <returns>An instance of self (ExternalWindowOverlay) with the overlay enabled and running.</returns>
        public static async Task <D2DOverlay> CreateExternalWindowOverlay(D2DWindowRenderer.DelegateRenderDirect2D renderDelegate, int hookDelay)
        {
            // Apply hook delay
            await Task.Delay(hookDelay);

            // Game process
            System.Diagnostics.Process gameProcess = Bindings.TargetProcess.GetProcessFromReloadedProcess();

            // Try to get game window handle.
            while (gameProcess.MainWindowHandle == IntPtr.Zero)
            {
                await Task.Delay(32);
            }

            // Wait for the Window to show itself to screen before configuring.
            while (WindowFunctions.IsWindowVisible(gameProcess.MainWindowHandle) == false)
            {
                await Task.Delay(32);
            }

            // Create self.
            D2DOverlay externalWindowOverlay = new D2DOverlay();

            // Enable the overlay.
            externalWindowOverlay.EnableOverlay(renderDelegate, gameProcess.MainWindowHandle);

            // Return self
            return(externalWindowOverlay);
        }
        /// <summary>
        /// FFT 演算をおこないます。
        /// </summary>
        /// <param name="source">フーリエ変換をおこなうデータ配列 (要素数は 2 の累乗であること)</param>
        /// <param name="windowFunction">窓関数を指定する (デフォルトは矩形窓)</param>
        /// <returns>フーリエ変換後のデータ配列</returns>
        public static Complex[] FFT(this IEnumerable <Complex> source, WindowFunctions windowFunction)
        {
            var array = source != null?source.ToArray() : null;

            int length = array != null ? array.Length : 0;

            if (length <= 0)
            {
                return(null);
            }

            // 2 の累乗かどうかを確認する
            if ((length & (length - 1)) != 0)
            {
                return(null);
            }

            var data = array.Clone() as Complex[];
            var win  = GetWindowFunction(windowFunction, length);

            for (int i = 0; i < length; i++)
            {
                data[i] *= win[i];
            }

            return(FFTCalculation(data, false));
        }
        /// <summary>
        /// Called when [click].
        /// </summary>
        protected override void OnClick()
        {
            ArcMap.Application.CurrentTool = null;

            try
            {
                UID uid = new UIDClass();
                uid.Value = "{82B9951B-DD63-11D1-AA7F-00C04FA37860}";  // Select By Location Command

                ICommandItem commandItem = ArcMap.Application.Document.CommandBars.Find(uid, false, false);

                // open the Select By Location dialog (in case it isn't already open)
                if (commandItem != null)
                {
                    commandItem.Execute();
                }

                IntPtr selectwindow = this.FindSelectByLocationWindow();

                if (!selectwindow.Equals(IntPtr.Zero))
                {
                    WindowFunctions.BringWindowToTop(selectwindow);
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.StackTrace);
                throw;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Attaches a Windows Forms window to the overlay.
        /// </summary>
        public static void AttachWinForm(IntPtr yourFormHandle, IntPtr targetFormHandle)
        {
            // Set parent form.
            WindowFunctions.SetParent(yourFormHandle, targetFormHandle);

            // Bring the user's form to front.
            WindowFunctions.SetForegroundWindow(yourFormHandle);
        }
        /// <summary>
        /// Returns the coordinates of the edges of a specific window relative to the desktop the window is presented on.
        /// </summary>
        /// <param name="windowHandle">Handle to the window of which the window rectangle should be obtained.</param>
        /// <returns></returns>
        public static Structures.WinapiRectangle GetWindowRectangle(IntPtr windowHandle)
        {
            // Obtains the coordinates of the edges of the window.
            WindowFunctions.GetWindowRect(windowHandle, out Structures.WinapiRectangle gameWindowRectangle);

            // Return
            return(gameWindowRectangle);
        }
        /// <summary>
        /// Returns the coordinates of the edges of a specific window in terms of
        /// X from the left and Y from the top of the window.
        /// </summary>
        /// <param name="windowHandle">Handle to the window of which the client area rectangle should be obtained.</param>
        /// <returns></returns>
        public static Structures.WinapiRectangle GetClientAreaSize(IntPtr windowHandle)
        {
            // Obtains the size of the client area.
            WindowFunctions.GetClientRect(windowHandle, out Structures.WinapiRectangle clientAreaRectangle);

            // Return
            return(clientAreaRectangle);
        }
 public FilterWindow()
 {
     DataContext = this;
     WindowFunctions.Add(new RectangleWindowFunction());
     WindowFunctions.Add(new HanningWindowFunction());
     Filters.Add(new LowPassFilter());
     Filters.Add(new HighPassFilter());
     InitializeComponent();
 }
Beispiel #11
0
        protected virtual void VisitWindowFunction(IWindowFunctionBuilder expression)
        {
            var handler = default(SqlQueryWriterVisitorHandler);

            if (!WindowFunctions.TryGetValue(expression.Function, out handler))
            {
                throw new NotImplementedException();
            }
            handler(this, expression);
        }
Beispiel #12
0
        public void SqrtHann()
        {
            var hann = WindowFunctions.Hann(256);

            var sqrtHann = WindowFunctions.SqrtHann(256);

            for (var t = 0; t < 256; t++)
            {
                Assert.AreEqual(Math.Sqrt(hann[t]), sqrtHann[t], 1.0E-6);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Attaches a Windows Forms window to the overlay.
        /// </summary>
        /// <param name="yourForm">Your windows form.</param>
        public void AttachWinForm(Form yourForm)
        {
            // Define handle to your own Windows form.
            IntPtr yourFormHandle = yourForm.Handle;

            // Set parent form.
            WindowFunctions.SetParent(yourFormHandle, OverlayForm.Handle);

            // Bring the user's form to front.
            yourForm.BringToFront();
        }
Beispiel #14
0
        public void GoPoint(Point newpoint)
        {
            Control   cWnd;
            IntPtr    hWnd      = WindowFunctions.GetWindowAtPoint(newpoint, out cWnd);
            Rectangle WindowLoc = WindowFunctions.GetRectFromHwnd(hWnd);

            this.Location      = new Point(WindowLoc.Left, WindowLoc.Top);
            this.Size          = new Size(WindowLoc.Width, WindowLoc.Height);
            this.TrackedWindow = hWnd;
            //Console.WriteLine(this.Location.ToString() + " " + WindowFunctions.GetWindowText(hWnd));
            this.Invalidate();
        }
Beispiel #15
0
        /// <summary>
        /// Your own user code starts here.
        /// If this is your first time, do consider reading the notice above.
        /// It contains some very useful information.
        /// </summary>
        public static void Init()
        {
            /*
             *  Reloaded Mod Loader Sample: Universal Borderless Windowed
             *  Architectures supported: X86, X64
             *
             *  Waits until the game or process spawns off its initial border and then changes the
             *  window border style of the application to borderless using the Windows API.
             */

            /*
             *  We create our own thread and run it in the background because Reloaded-Loader explicitly waits
             *  for the mod's thread to return before continuing to load other mods and ultimately the game.
             *
             *  For anything we want to do in the background during initialization with Reloaded or you need to wait
             *  for the process/game for some reason, you are requires to start a background thread.
             */
            Thread setBorderlessThread = new Thread
                                         (
                () =>
            {
                // Loop infinitely until a window handle is found.
                while (GameProcess.Process.MainWindowHandle == IntPtr.Zero)
                {
                    // Sleep the thread for a sensible amount of time.
                    Thread.Sleep(2000);
                }

                // Get the window size.
                Point windowSize = WindowProperties.GetWindowSize(GameProcess.Process.MainWindowHandle);
                Structures.WinapiRectangle windowLocation = WindowProperties.GetWindowRectangle(GameProcess.Process.MainWindowHandle);

                // Get the game's Window Style.
                uint windowStyle = (uint)GetWindowLongPtr(GameProcess.Process.MainWindowHandle, GWL_STYLE);

                // Change the window style.
                windowStyle &= ~WS_BORDER;
                windowStyle &= ~WS_CAPTION;
                windowStyle &= ~WS_MAXIMIZEBOX;
                windowStyle &= ~WS_MINIMIZEBOX;

                // Set the window style.
                SetWindowLongPtr(GameProcess.Process.MainWindowHandle, GWL_STYLE, (IntPtr)windowStyle);

                // Set the window size.
                WindowFunctions.MoveWindow(GameProcess.Process.MainWindowHandle, windowLocation.LeftBorder,
                                           windowLocation.TopBorder, windowSize.X, windowSize.Y, true);
            }
                                         );

            setBorderlessThread.Start();
        }
Beispiel #16
0
        // Finish drawing/dragging
        private void pbxDisplay_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right) // Right click
            {
                // Summon a context menu
                SelectedRect = GetPhraseAtPoint(e.Location); // Find all selected phrases
                if (PhraseRects.FindAll(x => x.Selected == true).Count() < 1)
                {
                    return;                    // Don't display menu if nothing's selected
                }
                ctxPhrase.Show(MousePosition); // Display menu
            }
            else                               // Left click
            {
                if (Marking == true)           // We were drawing a bounding box
                {
                    // Create a phrase box
                    Rectangle TestRect = MouseStart.RectTo(MouseEnd);
                    if (TestRect.Width > 25 && TestRect.Height > 15)
                    {
                        ChangeState(State.translated);
                        PhraseRect NewPRect = new PhraseRect(TestRect, OCRResult, this, AsyncTranslation_callback);
                        PhraseRects.Add(NewPRect);
                    }
                    Marking = false;
                }
                else
                { // We were selecting/dragging
                    PhraseRect PRect = GetPhraseAtPoint(e.Location);
                    if (PRect != null)
                    {
                        PhraseRects.FindAll(x => x.Selected == true).ForEach(x => x.UpdateText(OCRResult, AsyncTranslation_callback));
                    }

                    PhraseRects.ForEach(x => x.Clicked = false);
                }

                if (!Dragging && !StartingDrag)
                {
                    // If the user wasn't holding shift, clear all other selections
                    if (!WindowFunctions.IsPressed((int)WindowFunctions.VirtualKeyStates.VK_LSHIFT))
                    {
                        PhraseRects.ForEach(x => { x.Clicked = false; x.Selected = false; });
                    }
                }
            }

            Dragging     = false;
            StartingDrag = false;
            pbxDisplay.Invalidate();
        }
        /// <summary>
        /// This variant of IsWindowActivated simply checks whether a specified window handle
        /// is currently focused rather than whether any window belonging to the current process
        /// is focused.
        /// </summary>
        /// <returns>Returns true if the specified handle has focus, else false.</returns>
        public static bool IsWindowActivated(IntPtr windowHandle)
        {
            // Obtain the active window handle.
            IntPtr activatedHandle = WindowFunctions.GetForegroundWindow();

            // Check if any window is active.
            if (activatedHandle == IntPtr.Zero)
            {
                return(false);
            }

            // Compare the process identifiers of active window and our process.
            return(activatedHandle == windowHandle);
        }
        /// <summary>
        /// Expands the Frame Border Effect to the whole form.
        /// Normally, without background rendering and a border, a window should technically
        /// be invisible. However, this unfortunately is not the case as compositing does not default
        /// apply to the client area of the window. Well, let's just make it apply and see the windows
        /// underneath, sounds good?
        /// </summary>
        private void ExtendFrameToClientArea()
        {
            // Instantiate a new instance of the margins class.
            Structures.WinapiRectangle formMargins = new Structures.WinapiRectangle
            {
                LeftBorder   = 0,
                TopBorder    = 0,
                RightBorder  = Width,
                BottomBorder = Height
            };

            // Extend the frame into client area.
            WindowFunctions.DwmExtendFrameIntoClientArea(Handle, ref formMargins);
        }
Beispiel #19
0
 private void TopClick(object sender, MouseEventArgs e)
 {
     if (e.Clicks == 2)
     {
         WindowFunctions.ToggleMaximize(_skinWindow.Parent);
     }
     else if (_skinWindow.Maximized)
     {
         _skinWindow.Parent.Activate();
     }
     else
     {
         ForceParentCommand(SystemCommands.DragMove);
     }
 }
Beispiel #20
0
        [DataRow(10, 30, -20)]  // Source is shorter than frame
        public void CheckWithNaiveImplementation(int sourceLength, int windowLength, int position)
        {
            var random = new Random(57);
            var source = Enumerable.Range(0, sourceLength).Select(t => random.NextDouble()).ToArray();
            var window = WindowFunctions.Hann(windowLength);

            var expected = GetFrame_Naive(source, window, position);

            var actual = Framing.GetFrame(source, window, position);

            for (var t = 0; t < actual.Length; t++)
            {
                Assert.AreEqual(expected[t], actual[t], 1.0E-9);
            }
        }
Beispiel #21
0
        public void Hann()
        {
            var hann = WindowFunctions.Hann(256);

            Assert.AreEqual(256, hann.Length);

            Assert.AreEqual(0.0, hann.First(), 1.0E-6);
            Assert.AreEqual(0.0, hann.Last(), 0.001);

            Assert.AreEqual(1.0, hann[128], 1.0E-6);

            Assert.AreEqual(0.5, hann[64], 1.0E-6);
            Assert.AreEqual(0.5, hann[192], 1.0E-6);

            Assert.AreEqual(0.0, hann.Min(), 1.0E-6);
            Assert.AreEqual(1.0, hann.Max(), 1.0E-6);
            Assert.AreEqual(0.5, hann.Average(), 1.0E-6);
        }
        /// <summary>
        /// FFT 演算をおこないます。
        /// </summary>
        /// <param name="source">フーリエ変換をおこなうデータ配列 (要素数は 2 の累乗であること)</param>
        /// <param name="windowFunction">窓関数を指定する (デフォルトは矩形窓)</param>
        /// <returns>フーリエ変換後のデータ配列</returns>
        public static Complex[] FFT(this Complex[] source, WindowFunctions windowFunction)
        {
            int length = source != null ? source.Length : 0;
            if (length <= 0)
                return null;

            // 2 の累乗かどうかを確認する
            if ((length & (length - 1)) != 0)
                return null;

            var data = source.Clone() as Complex[];
            var win = GetWindowFunction(windowFunction, length);
            for (int i = 0; i < length; i++)
            {
                data[i] *= win[i];
            }

            return FFTCalculation(data, false);
        }
Beispiel #23
0
        [DataRow(10, 30, -20)]  // Source is shorter than frame
        public void CheckWithNaiveImplementation(int destinationLength, int windowLength, int position)
        {
            var random      = new Random(57);
            var destination = Enumerable.Range(0, destinationLength).Select(t => random.NextDouble()).ToArray();
            var frame       = Enumerable.Range(0, windowLength).Select(t => (Complex)random.NextDouble()).ToArray();
            var window      = WindowFunctions.Hann(windowLength);

            var expected = destination.ToArray();

            OverlapAdd_Naive(expected, frame, window, position);

            var actual = destination.ToArray();

            Framing.OverlapAdd(actual, frame, window, position);

            for (var t = 0; t < actual.Length; t++)
            {
                Assert.AreEqual(expected[t], actual[t], 1.0E-9);
            }
        }
        /// <summary>
        /// Returns the coordinates of the edges of the client area of a specific window
        /// relative to the desktop the window is presented on.
        /// </summary>
        /// <param name="windowHandle">Handle to the window of which the client area rectangle should be obtained.</param>
        /// <returns></returns>
        public static Structures.WinapiRectangle GetClientRectangle(IntPtr windowHandle)
        {
            // Obtains the coordinates of the edges of the window.
            WindowFunctions.GetClientRect(windowHandle, out Structures.WinapiRectangle clientAreaRectangle);

            // Get the coordinates of the top left point on the screen in client's area.
            Structures.WinapiPoint topLeftClientCoordinate = new Structures.WinapiPoint();
            WindowFunctions.ClientToScreen(windowHandle, ref topLeftClientCoordinate);

            // Calculate each edge.
            Structures.WinapiRectangle clientArea = new Structures.WinapiRectangle();
            clientArea.LeftBorder = topLeftClientCoordinate.x;
            clientArea.TopBorder  = topLeftClientCoordinate.y;

            clientArea.RightBorder  = topLeftClientCoordinate.x + clientAreaRectangle.RightBorder;
            clientArea.BottomBorder = topLeftClientCoordinate.y + clientAreaRectangle.BottomBorder;

            // Return
            return(clientArea);
        }
Beispiel #25
0
        /// <summary>
        /// Class constructor. Instantiates both the overlay and DirectX Stuff.
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="gameWindowHandle">
        ///     The handle of the game window to be overlayed.
        ///     The handle may be obtained via ReloadedProcess.GetProcessFromReloadedProcess().MainWindowHandle.
        /// </param>
        /// <param name="renderDelegate">
        ///     The user delegate which you may use for rendering to the external overlay
        ///     window with Direct2D.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        /// <returns>An instance of self (ExternalWindowOverlay) with the overlay enabled and running.</returns>
        public static async Task <D2DOverlay> CreateExternalWindowOverlay(IntPtr gameWindowHandle, D2DWindowRenderer.DelegateRenderDirect2D renderDelegate, int hookDelay)
        {
            // Apply hook delay
            await Task.Delay(hookDelay);

            // Wait for the Window to show itself to screen before configuring.
            while (WindowFunctions.IsWindowVisible(gameWindowHandle) == false)
            {
                await Task.Delay(32);
            }

            // Create self.
            D2DOverlay externalWindowOverlay = new D2DOverlay();

            // Enable the overlay.
            externalWindowOverlay.EnableOverlay(renderDelegate, gameWindowHandle);

            // Return self
            return(externalWindowOverlay);
        }
        /// <summary>
        /// Checks whether the current application is activated.
        /// The method compares the current active foreground window to the
        /// window thread of the current caller.
        ///
        /// The function is not specific
        /// to any technology and works for both child windows and the current window,
        /// also independently of the thread which owns a specific window.
        /// </summary>
        /// <returns>Returns true if the current application has focus/is foreground/is activated. Else false.</returns>
        public static bool IsWindowActivated()
        {
            // Obtain the active window handle.
            IntPtr activatedHandle = WindowFunctions.GetForegroundWindow();

            // Check if any window is active.
            if (activatedHandle == IntPtr.Zero)
            {
                return(false);
            }

            // Retrieve unique identifier for this process.
            int currentProcessIdentifier = System.Diagnostics.Process.GetCurrentProcess().Id;

            // Retrieve the process identifier for the active window.
            WindowFunctions.GetWindowThreadProcessId(activatedHandle, out int activeProcessIdentifier);

            // Compare the process identifiers of active window and our process.
            return(activeProcessIdentifier == currentProcessIdentifier);
        }
        /* GenerateWindow: generate the taper window, if `scaling_psd` = false then set `psd_scale` = 1 */
        private void GenerateWindow(WindowType win_type, bool scaling_psd)
        {
            string          win_name = win_type.ToString();
            WindowFunctions wf       = new WindowFunctions();
            MethodInfo      method   = wf.function(win_name);

            window    = new double[n_epoch];
            psd_scale = 0;
            for (int i = 0; i < n_epoch; i++)
            {
                window[i]  = Convert.ToDouble(method.Invoke(wf, new object[] { i, n_epoch }));
                psd_scale += window[i] * window[i];
            }

            psd_scale = 1 / (psd_scale * Rate);

            if (!scaling_psd)
            {
                psd_scale = 1.0;
            }
        }
Beispiel #28
0
        /// <summary>
        /// A crashfix for running Heroes at extreme resolutions, patches the resolution the rasters are created at.
        /// </summary>
        /// <returns></returns>
        private static int TObjCameraInitHook(int *thisPointer, int cameraLimit)
        {
            int resolutionXBackup = *_resolutionX;
            int resolutionYBackup = *_resolutionY;
            int greaterResolution = resolutionXBackup > resolutionYBackup ? resolutionXBackup : resolutionYBackup;

            // Get the window size.
            Structures.WinapiRectangle windowLocation = WindowProperties.GetWindowRectangle(GameProcess.Process.MainWindowHandle);

            // Set the window size.
            WindowFunctions.MoveWindow(GameProcess.Process.MainWindowHandle, windowLocation.LeftBorder,
                                       windowLocation.TopBorder, greaterResolution, (int)(greaterResolution / OriginalAspectRatio), false);

            int result = _someTitlecardCreateHook.OriginalFunction(thisPointer, cameraLimit);

            // Re-set the window size.
            WindowFunctions.MoveWindow(GameProcess.Process.MainWindowHandle, windowLocation.LeftBorder,
                                       windowLocation.TopBorder, resolutionXBackup, resolutionYBackup, false);

            return(result);
        }
        public void CheckWithLinq(int sourceLength, int windowLength, int position)
        {
            var random = new Random(57);
            var source = Enumerable.Range(0, sourceLength).Select(t => random.NextDouble()).ToArray();
            var window = WindowFunctions.Hann(windowLength);

            var expected = source.Skip(position).Take(windowLength).Select(value => (Complex)value).ToArray();

            for (var t = 0; t < expected.Length; t++)
            {
                expected[t] *= window[t];
            }

            var actual = Framing.GetFrameComplex(source, window, position);

            for (var t = 0; t < actual.Length; t++)
            {
                Assert.AreEqual(expected[t].Real, actual[t].Real, 1.0E-9);
                Assert.AreEqual(expected[t].Imaginary, actual[t].Imaginary, 1.0E-9);
            }
        }
        /// <summary>
        /// 窓関数を取得します。
        /// </summary>
        /// <param name="windowFunction">窓関数を選択する</param>
        /// <param name="length">データ数を指定する</param>
        /// <param name="attenuation">(カイザー窓関数選択時のみ)減衰量を指定する</param>
        /// <returns>窓関数値配列</returns>
        public static double[] GetWindowFunction(WindowFunctions windowFunction, int length, double attenuation)
        {
            double[] win = null;

            switch (windowFunction)
            {
            default:
            case WindowFunctions.Rectangle:
                win = RectangleWindowFunction(length);
                break;

            case WindowFunctions.Hanning:
                win = HanningWindowFunction(length, false);         // 本当は周期的な窓関数として取得するべきだが
                break;

            case WindowFunctions.Kaiser:
                win = KaiserWindowFunction(length, attenuation);
                break;
            }

            return(win);
        }
Beispiel #31
0
        // Takes a screenshot of the SnapRegion and returns it
        private Image Snap()
        {
            bool VfwWasVisible = vfw.Visible;

            if (VfwWasVisible)
            {
                vfw.Visible = false; // Hide viewfinder if appropriate
            }
            this.Visible = false;    // Hide self (nobody wants to translate Babel)

            try
            {
                if ((int)TrackingWindow != 0)
                {
                    // Put this into a general function later
                    Rectangle WindowLoc = WindowFunctions.GetRectFromHwnd(TrackingWindow);
                    vfw.Location = new Point(WindowLoc.Left, WindowLoc.Top);
                    vfw.Size     = new Size(WindowLoc.Width, WindowLoc.Height);
                    vfw.Flicker();
                }

                Image result = GDI32.Grab(SnapRegion);

                if (VfwWasVisible)
                {
                    vfw.Visible = true; // Reshow viewfinder if appropriate
                }
                this.Visible = true;    // Show self again
                this.Focus();           // Return focus to the main form

                DebugLog.Log("Took snap");

                return(result);
            } catch (Exception ex)
            {
                DebugLog.Log(ex.Message);
                return(null);
            }
        }
 /// <summary>
 /// 窓関数を取得します。
 /// </summary>
 /// <param name="windowFunction">窓関数を選択する</param>
 /// <param name="length">データ数を指定する</param>
 /// <returns>窓関数値配列</returns>
 public static double[] GetWindowFunction(WindowFunctions windowFunction, int length)
 {
     return GetWindowFunction(windowFunction, length, 0);
 }
        /// <summary>
        /// 窓関数を取得します。
        /// </summary>
        /// <param name="windowFunction">窓関数を選択する</param>
        /// <param name="length">データ数を指定する</param>
        /// <param name="attenuation">(カイザー窓関数選択時のみ)減衰量を指定する</param>
        /// <returns>窓関数値配列</returns>
        public static double[] GetWindowFunction(WindowFunctions windowFunction, int length, double attenuation)
        {
            double[] win = null;

            switch (windowFunction)
            {
                default:
                case WindowFunctions.Rectangle:
                    win = RectangleWindowFunction(length);
                    break;

                case WindowFunctions.Hanning:
                    win = HanningWindowFunction(length, false);     // 本当は周期的な窓関数として取得するべきだが
                    break;

                case WindowFunctions.Kaiser:
                    win = KaiserWindowFunction(length, attenuation);
                    break;
            }

            return win;
        }
 /// <summary>
 /// FFT 演算をおこないます。
 /// </summary>
 /// <param name="source">フーリエ変換をおこなうデータ配列 (要素数は 2 の累乗であること)</param>
 /// <param name="windowFunction">窓関数を選択する</param>
 /// <returns>フーリエ変換後のデータ配列</returns>
 public static Complex[] FFT(this double[] source, WindowFunctions windowFunction)
 {
     return FFT(source.Select(i => new Complex(i)).ToArray(), windowFunction);
 }