@@ -237,18 +237,12 @@ public static void RFFT(Span<Complex> destination, Span<double> input)
237237 if ( destination . Length != input . Length / 2 + 1 )
238238 throw new ArgumentException ( "Destination length must be an equal to input length / 2 + 1" ) ;
239239
240- var temp = ArrayPool < Complex > . Shared . Rent ( input . Length ) ;
241- try
242- {
243- var buffer = temp . AsSpan ( 0 , input . Length ) ;
244- MakeComplex ( buffer , input ) ;
245- FFT ( buffer ) ;
246- buffer . Slice ( 0 , destination . Length ) . CopyTo ( destination ) ;
247- }
248- finally
249- {
250- ArrayPool < Complex > . Shared . Return ( temp ) ;
251- }
240+ Complex [ ] temp = ArrayPool < Complex > . Shared . Rent ( input . Length ) ;
241+ Span < Complex > buffer = temp . AsSpan ( 0 , input . Length ) ;
242+ MakeComplex ( buffer , input ) ;
243+ FFT ( buffer ) ;
244+ buffer . Slice ( 0 , destination . Length ) . CopyTo ( destination ) ;
245+ ArrayPool < Complex > . Shared . Return ( temp ) ;
252246 }
253247
254248 /// <summary>
@@ -286,24 +280,20 @@ public static void FFTmagnitude(Span<double> destination, Span<double> input)
286280 throw new ArgumentException ( "Input length must be an even power of 2" ) ;
287281
288282 var temp = ArrayPool < Complex > . Shared . Rent ( destination . Length ) ;
289- try
290- {
291- var buffer = temp . AsSpan ( 0 , destination . Length ) ;
292283
293- // first calculate the FFT
294- RFFT ( buffer , input ) ;
284+ var buffer = temp . AsSpan ( 0 , destination . Length ) ;
295285
296- // first point (DC component) is not doubled
297- destination [ 0 ] = buffer [ 0 ] . Magnitude / input . Length ;
286+ // first calculate the FFT
287+ RFFT ( buffer , input ) ;
298288
299- // subsequent points are doubled to account for combined positive and negative frequencies
300- for ( int i = 1 ; i < buffer . Length ; i ++ )
301- destination [ i ] = 2 * buffer [ i ] . Magnitude / input . Length ;
302- }
303- finally
304- {
305- ArrayPool < Complex > . Shared . Return ( temp ) ;
306- }
289+ // first point (DC component) is not doubled
290+ destination [ 0 ] = buffer [ 0 ] . Magnitude / input . Length ;
291+
292+ // subsequent points are doubled to account for combined positive and negative frequencies
293+ for ( int i = 1 ; i < buffer . Length ; i ++ )
294+ destination [ i ] = 2 * buffer [ i ] . Magnitude / input . Length ;
295+
296+ ArrayPool < Complex > . Shared . Return ( temp ) ;
307297 }
308298
309299 /// <summary>
0 commit comments