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.

133 lines
3.8KB

  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. #include "types.h"
  21. struct Peak {
  22. float min;
  23. float max;
  24. float normalization_factor ( void ) const;
  25. };
  26. class Audio_File;
  27. class Peak_Writer;
  28. class Peaks
  29. {
  30. struct peakdata {
  31. nframes_t chunksize; /* should always be a power of 2 */
  32. Peak data[];
  33. };
  34. struct peakbuffer {
  35. size_t size; /* total allocation size */
  36. size_t len; /* number of peaks */
  37. nframes_t offset; /* starting sample */
  38. peakdata *buf;
  39. peakbuffer ( )
  40. {
  41. size = len = 0;
  42. }
  43. };
  44. static peakbuffer _peakbuf;
  45. Audio_File *_clip;
  46. mutable float _fpp;
  47. int read_peaks ( nframes_t s, nframes_t e, int npeaks, nframes_t chunksize ) const;
  48. int read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const;
  49. int read_source_peaks ( Peak *peaks, int npeaks, nframes_t chunksize ) const;
  50. int read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const;
  51. Peak_Writer *_peak_writer;
  52. public:
  53. static const int cache_minimum;
  54. static const int cache_levels;
  55. static const int cache_step;
  56. Peaks ( )
  57. {
  58. _clip = NULL;
  59. }
  60. Peaks ( Audio_File *c )
  61. {
  62. _clip = c;
  63. }
  64. Peak *peakbuf ( void ) const { return Peaks::_peakbuf.buf->data; }
  65. void clip ( Audio_File *c ) { _clip = c; }
  66. int fill_buffer ( float fpp, nframes_t s, nframes_t e ) const;
  67. void downsample ( Peak *peaks, int s, int e, float *mhi, float *mlo ) const;
  68. void read ( int X, float *hi, float *lo ) const;
  69. bool open ( void );
  70. // float normalization_factor( float fpp, nframes_t start, nframes_t end ) ;
  71. bool current ( nframes_t chunksize ) const;
  72. bool make_peaks ( void ) const;
  73. Peak & peak ( nframes_t start, nframes_t end ) const;
  74. Peak & operator[] ( int X ) const;
  75. };
  76. #include <stdio.h>
  77. class Peak_Writer
  78. {
  79. FILE *_fp;
  80. Peak *_peak;
  81. int _chunksize;
  82. int _channels;
  83. int _index;
  84. /* not permitted */
  85. Peak_Writer ( const Peak_Writer &rhs );
  86. const Peak_Writer &operator= ( const Peak_Writer &rhs );
  87. public:
  88. Peak_Writer ( const char *filename, nframes_t chunksize, int channels );
  89. ~Peak_Writer ( );
  90. void write ( sample_t *buf, nframes_t nframes );
  91. };