fft_helpers.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * fft_helpers.h - some functions around FFT analysis
  3. *
  4. * Copyright (c) 2008-2012 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef FFT_HELPERS_H
  25. #define FFT_HELPERS_H
  26. #include "export.h"
  27. #include <fftw3.h>
  28. const int FFT_BUFFER_SIZE = 2048;
  29. enum WINDOWS
  30. {
  31. KAISER=1,
  32. RECTANGLE,
  33. HANNING,
  34. HAMMING
  35. };
  36. /* returns biggest value from abs_spectrum[spec_size] array
  37. *
  38. * returns -1 on error
  39. */
  40. float EXPORT maximum( float * _abs_spectrum, unsigned int _spec_size );
  41. /* apply hanning or hamming window to channel
  42. *
  43. * returns -1 on error
  44. */
  45. int EXPORT hanming( float * _timebuffer, int _length, WINDOWS _type );
  46. /* compute absolute values of complex_buffer, save to absspec_buffer
  47. * take care that - compl_len is not bigger than complex_buffer!
  48. * - absspec buffer is big enough!
  49. *
  50. * returns 0 on success, else -1
  51. */
  52. int EXPORT absspec( fftwf_complex * _complex_buffer, float * _absspec_buffer,
  53. int _compl_length );
  54. /* build fewer subbands from many absolute spectrum values
  55. * take care that - compressedbands[] array num_new elements long
  56. * - num_old > num_new
  57. *
  58. * returns 0 on success, else -1
  59. */
  60. int EXPORT compressbands( float * _absspec_buffer, float * _compressedband,
  61. int _num_old, int _num_new, int _bottom, int _top );
  62. int EXPORT calc13octaveband31( float * _absspec_buffer, float * _subbands,
  63. int _num_spec, float _max_frequency );
  64. /* compute power of finite time sequence
  65. * take care num_values is length of timesignal[]
  66. *
  67. * returns power on success, else -1
  68. */
  69. float EXPORT signalpower(float *timesignal, int num_values);
  70. #endif