Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.3KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #pragma once
  19. #include <stdlib.h>
  20. typedef unsigned long nframes_t;
  21. struct Peak {
  22. float min;
  23. float max;
  24. };
  25. class Audio_File;
  26. class Peaks
  27. {
  28. struct peakdata {
  29. int chunksize; /* should always be a power of 2 */
  30. Peak data[];
  31. };
  32. struct peakbuffer {
  33. size_t size; /* total allocation size */
  34. size_t len; /* number of peaks */
  35. nframes_t offset; /* starting sample */
  36. peakdata *buf;
  37. peakbuffer ( )
  38. {
  39. size = len = 0;
  40. }
  41. };
  42. static peakbuffer peakbuf;
  43. Audio_File *_clip;
  44. int _channel;
  45. peakdata *_peaks;
  46. size_t _len;
  47. mutable float _fpp;
  48. void read_peaks ( int s, int e, int npeaks, int chunksize ) const;
  49. int clip_read_peaks ( Peak *peaks, int npeaks, int chunksize ) const;
  50. const char *peakname ( const char *filename ) const;
  51. Peak & peak ( nframes_t start, nframes_t end ) const;
  52. // Peaks ( );
  53. public:
  54. Peaks ( )
  55. {
  56. _peaks = new peakdata;
  57. _peaks->chunksize = 0;
  58. _len = 0;
  59. _clip = NULL;
  60. _channel = 0;
  61. }
  62. Peaks ( Audio_File *c )
  63. {
  64. _peaks = new peakdata;
  65. _peaks->chunksize = 0;
  66. _len = 0;
  67. _clip = c;
  68. _channel = 0;
  69. }
  70. void clip ( Audio_File *c ) { _clip = c; }
  71. void channel ( int v ) { _channel = v; }
  72. void fill_buffer ( float fpp, int s, int e ) const;
  73. void downsample ( Peak *peaks, int s, int e, float *mhi, float *mlo ) const;
  74. void read ( int X, float *hi, float *lo ) const;
  75. bool open ( void );
  76. float normalization_factor( float fpp, nframes_t start, nframes_t end ) const;
  77. bool current ( void ) const;
  78. bool make_peaks ( int chunksize );
  79. Peak & operator[] ( int X ) const;
  80. };