LongSound.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _LongSound_h_
  2. #define _LongSound_h_
  3. /* LongSound.h
  4. *
  5. * Copyright (C) 1992-2012,2015,2016,2017 Paul Boersma, 2007 Erez Volk (for FLAC, MP3)
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Sound.h"
  21. #include "Collection.h"
  22. #define COMPRESSED_MODE_READ_FLOAT 0
  23. #define COMPRESSED_MODE_READ_SHORT 1
  24. struct FLAC__StreamDecoder;
  25. struct FLAC__StreamEncoder;
  26. struct _MP3_FILE;
  27. Thing_define (LongSound, Sampled) {
  28. structMelderFile file;
  29. FILE *f;
  30. int audioFileType, encoding, numberOfBytesPerSamplePoint;
  31. integer numberOfChannels;
  32. double sampleRate;
  33. integer startOfData;
  34. double bufferLength;
  35. int16 *buffer; // this is always 16-bit, because will always play sounds in 16-bit, even those from 24-bit files
  36. integer imin, imax, nmax;
  37. struct FLAC__StreamDecoder *flacDecoder;
  38. struct _MP3_FILE *mp3f;
  39. int compressedMode;
  40. integer compressedSamplesLeft;
  41. double *compressedFloats [2];
  42. int16 *compressedShorts;
  43. void v_destroy () noexcept
  44. override;
  45. void v_info ()
  46. override;
  47. void v_copy (Daata data_to)
  48. override;
  49. bool v_writable ()
  50. override { return false; }
  51. int v_domainQuantity ()
  52. override { return MelderQuantity_TIME_SECONDS; }
  53. };
  54. autoLongSound LongSound_open (MelderFile file);
  55. autoSound LongSound_extractPart (LongSound me, double tmin, double tmax, bool preserveTimes);
  56. bool LongSound_haveWindow (LongSound me, double tmin, double tmax);
  57. /*
  58. * Returns 0 if error or if window exceeds buffer, otherwise 1;
  59. */
  60. void LongSound_getWindowExtrema (LongSound me, double tmin, double tmax, int channel, double *minimum, double *maximum);
  61. void LongSound_playPart (LongSound me, double tmin, double tmax,
  62. Sound_PlayCallback callback, Thing boss);
  63. void LongSound_savePartAsAudioFile (LongSound me, int audioFileType, double tmin, double tmax, MelderFile file, int numberOfBitsPerSamplePoint);
  64. void LongSound_saveChannelAsAudioFile (LongSound me, int audioFileType, int channel, MelderFile file);
  65. void LongSound_readAudioToFloat (LongSound me, MAT buffer, integer firstSample);
  66. void LongSound_readAudioToShort (LongSound me, int16 *buffer, integer firstSample, integer numberOfSamples);
  67. Collection_define (SoundAndLongSoundList, OrderedOf, Sampled) {
  68. };
  69. void LongSound_concatenate (SoundAndLongSoundList collection, MelderFile file, int audioFileType, int numberOfBitsPerSamplePoint);
  70. void LongSound_preferences ();
  71. integer LongSound_getBufferSizePref_seconds ();
  72. void LongSound_setBufferSizePref_seconds (integer size);
  73. /* End of file LongSound.h */
  74. #endif