diff --git a/.gitignore b/.gitignore index 48d4120..f0266d1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ */bin/ */obj/ -*.g.cs */.vs/ .vs/ *.dll diff --git a/FFTW.NET/BufferPool.cs b/FFTW.NET/BufferPool.cs index 928b5b7..2d463d2 100644 --- a/FFTW.NET/BufferPool.cs +++ b/FFTW.NET/BufferPool.cs @@ -83,7 +83,7 @@ internal static Container Get(BufferPool bufferPool, int minSize) if (item.Size >= minSize) { bufferPool._buffers.RemoveAt(i--); - if (bufferPool._buffers[i].Buffer.TryGetTarget(out buffer)) + if (item.Buffer.TryGetTarget(out buffer)) break; } } diff --git a/FFTW.NET/FFTW.NET.csproj b/FFTW.NET/FFTW.NET.csproj index 75f26f9..71238d7 100644 --- a/FFTW.NET/FFTW.NET.csproj +++ b/FFTW.NET/FFTW.NET.csproj @@ -1,6 +1,6 @@  - netstandard1.3 + netstandard2.1 True True ArgusMagnus @@ -13,11 +13,10 @@ Git https://github.com/ArgusMagnus/FFTW.NET FFTW FFTW.NET FFT - False - 1.0.1.0 - 1.0.1 - - Changed to .NETStandard library (1.3) -- Added FftwInterop.Version property which returns the version of the used FFTW libs + True + 1.0.2.0 + 1.0.2 + Fixed https://github.com/ArgusMagnus/FFTW.NET/issues/6 diff --git a/FFTW.NET/FftwInterop.g.cs b/FFTW.NET/FftwInterop.g.cs new file mode 100644 index 0000000..fe7e765 --- /dev/null +++ b/FFTW.NET/FftwInterop.g.cs @@ -0,0 +1,513 @@ +#region Copyright and License + +/* +This file is part of FFTW.NET, a wrapper around the FFTW library +for the .NET framework. +Copyright (C) 2017 Tobias Meyer + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +*/ + +#endregion + +// AUTOGENERATED FILE +// DO NOT MODIFY +using System; +using System.Runtime.InteropServices; + +namespace FFTW.NET +{ + /// + /// Provides access to FFTW C functions. + /// For a documentation of this functions see + /// http://www.fftw.org/fftw3_doc/index.html + /// + public static partial class FftwInterop + { + #region fftw_init_threads + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_init_threads")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_init_threads_x86(); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_init_threads")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_init_threads_x64(); + + public static bool fftw_init_threads() + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_init_threads_x64(); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_init_threads_x86(); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_plan_with_nthreads + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_plan_with_nthreads")] + private static extern void fftw_plan_with_nthreads_x86( + int nthreads); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_plan_with_nthreads")] + private static extern void fftw_plan_with_nthreads_x64( + int nthreads); + + public static void fftw_plan_with_nthreads( + int nthreads) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_plan_with_nthreads_x64(nthreads); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_plan_with_nthreads_x86(nthreads); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_plan_dft + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft")] + private static extern IntPtr fftw_plan_dft_x86( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + DftDirection direction, + PlannerFlags flags); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft")] + private static extern IntPtr fftw_plan_dft_x64( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + DftDirection direction, + PlannerFlags flags); + + public static IntPtr fftw_plan_dft( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + DftDirection direction, + PlannerFlags flags) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_plan_dft_x64(rank, n, arrIn, arrOut, direction, flags); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_plan_dft_x86(rank, n, arrIn, arrOut, direction, flags); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_plan_dft_r2c + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft_r2c")] + private static extern IntPtr fftw_plan_dft_r2c_x86( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft_r2c")] + private static extern IntPtr fftw_plan_dft_r2c_x64( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags); + + public static IntPtr fftw_plan_dft_r2c( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_plan_dft_r2c_x64(rank, n, arrIn, arrOut, flags); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_plan_dft_r2c_x86(rank, n, arrIn, arrOut, flags); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_plan_dft_c2r + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft_c2r")] + private static extern IntPtr fftw_plan_dft_c2r_x86( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_plan_dft_c2r")] + private static extern IntPtr fftw_plan_dft_c2r_x64( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags); + + public static IntPtr fftw_plan_dft_c2r( + int rank, + [MarshalAs(UnmanagedType.LPArray)] int[] n, + IntPtr arrIn, + IntPtr arrOut, + PlannerFlags flags) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_plan_dft_c2r_x64(rank, n, arrIn, arrOut, flags); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_plan_dft_c2r_x86(rank, n, arrIn, arrOut, flags); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_destroy_plan + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_destroy_plan")] + private static extern void fftw_destroy_plan_x86( + IntPtr plan); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_destroy_plan")] + private static extern void fftw_destroy_plan_x64( + IntPtr plan); + + public static void fftw_destroy_plan( + IntPtr plan) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_destroy_plan_x64(plan); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_destroy_plan_x86(plan); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_execute + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_execute")] + private static extern void fftw_execute_x86( + IntPtr plan); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_execute")] + private static extern void fftw_execute_x64( + IntPtr plan); + + public static void fftw_execute( + IntPtr plan) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_execute_x64(plan); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_execute_x86(plan); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_export_wisdom_to_filename + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_export_wisdom_to_filename")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_export_wisdom_to_filename_x86( + [MarshalAs(UnmanagedType.LPStr)] string filename); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_export_wisdom_to_filename")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_export_wisdom_to_filename_x64( + [MarshalAs(UnmanagedType.LPStr)] string filename); + + public static bool fftw_export_wisdom_to_filename( + [MarshalAs(UnmanagedType.LPStr)] string filename) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_export_wisdom_to_filename_x64(filename); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_export_wisdom_to_filename_x86(filename); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_import_wisdom_from_filename + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_import_wisdom_from_filename")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_import_wisdom_from_filename_x86( + [MarshalAs(UnmanagedType.LPStr)] string filename); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_import_wisdom_from_filename")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_import_wisdom_from_filename_x64( + [MarshalAs(UnmanagedType.LPStr)] string filename); + + public static bool fftw_import_wisdom_from_filename( + [MarshalAs(UnmanagedType.LPStr)] string filename) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_import_wisdom_from_filename_x64(filename); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_import_wisdom_from_filename_x86(filename); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_import_wisdom_from_string + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_import_wisdom_from_string")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_import_wisdom_from_string_x86( + [MarshalAs(UnmanagedType.LPStr)] string wisdom); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, + EntryPoint = "fftw_import_wisdom_from_string")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool fftw_import_wisdom_from_string_x64( + [MarshalAs(UnmanagedType.LPStr)] string wisdom); + + public static bool fftw_import_wisdom_from_string( + [MarshalAs(UnmanagedType.LPStr)] string wisdom) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_import_wisdom_from_string_x64(wisdom); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_import_wisdom_from_string_x86(wisdom); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_export_wisdom + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_export_wisdom")] + private static extern void fftw_export_wisdom_x86( + [MarshalAs(UnmanagedType.FunctionPtr)] WriteCharHandler writeChar, + IntPtr data); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_export_wisdom")] + private static extern void fftw_export_wisdom_x64( + [MarshalAs(UnmanagedType.FunctionPtr)] WriteCharHandler writeChar, + IntPtr data); + + public static void fftw_export_wisdom( + [MarshalAs(UnmanagedType.FunctionPtr)] WriteCharHandler writeChar, + IntPtr data) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_export_wisdom_x64(writeChar, data); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_export_wisdom_x86(writeChar, data); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_forget_wisdom + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_forget_wisdom")] + private static extern void fftw_forget_wisdom_x86(); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_forget_wisdom")] + private static extern void fftw_forget_wisdom_x64(); + + public static void fftw_forget_wisdom() + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_forget_wisdom_x64(); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_forget_wisdom_x86(); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_malloc + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_malloc")] + private static extern IntPtr fftw_malloc_x86( + IntPtr size); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_malloc")] + private static extern IntPtr fftw_malloc_x64( + IntPtr size); + + public static IntPtr fftw_malloc( + IntPtr size) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_malloc_x64(size); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_malloc_x86(size); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + + #region fftw_free + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_free")] + private static extern void fftw_free_x86( + IntPtr ptr); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_free")] + private static extern void fftw_free_x64( + IntPtr ptr); + + public static void fftw_free( + IntPtr ptr) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + fftw_free_x64(ptr); + } + else if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + fftw_free_x86(ptr); + } + else + { + throw new PlatformNotSupportedException(); + } + } + + #endregion + + #region fftw_alignment_of + + [DllImport("libfftw3-3-x86", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_alignment_of")] + private static extern int fftw_alignment_of_x86( + IntPtr ptr); + + [DllImport("libfftw3-3-x64", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fftw_alignment_of")] + private static extern int fftw_alignment_of_x64( + IntPtr ptr); + + public static int fftw_alignment_of( + IntPtr ptr) + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return fftw_alignment_of_x64(ptr); + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return fftw_alignment_of_x86(ptr); + } + + throw new PlatformNotSupportedException(); + } + + #endregion + } +} \ No newline at end of file