melder_audiofiles.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef _melder_audiofiles_h_
  2. #define _melder_audiofiles_h_
  3. /* melder_audiofiles.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  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. #pragma mark - AUDIO FILES
  21. /* Audio file types. */
  22. #define Melder_AIFF 1
  23. #define Melder_AIFC 2
  24. #define Melder_WAV 3
  25. #define Melder_NEXT_SUN 4
  26. #define Melder_NIST 5
  27. #define Melder_FLAC 6
  28. #define Melder_MP3 7
  29. #define Melder_NUMBER_OF_AUDIO_FILE_TYPES 7
  30. conststring32 Melder_audioFileTypeString (int audioFileType); // "AIFF", "AIFC", "WAV", "NeXT/Sun", "NIST", "FLAC", "MP3"
  31. /* Audio encodings. */
  32. #define Melder_LINEAR_8_SIGNED 1
  33. #define Melder_LINEAR_8_UNSIGNED 2
  34. #define Melder_LINEAR_16_BIG_ENDIAN 3
  35. #define Melder_LINEAR_16_LITTLE_ENDIAN 4
  36. #define Melder_LINEAR_24_BIG_ENDIAN 5
  37. #define Melder_LINEAR_24_LITTLE_ENDIAN 6
  38. #define Melder_LINEAR_32_BIG_ENDIAN 7
  39. #define Melder_LINEAR_32_LITTLE_ENDIAN 8
  40. #define Melder_MULAW 9
  41. #define Melder_ALAW 10
  42. #define Melder_SHORTEN 11
  43. #define Melder_POLYPHONE 12
  44. #define Melder_IEEE_FLOAT_32_BIG_ENDIAN 13
  45. #define Melder_IEEE_FLOAT_32_LITTLE_ENDIAN 14
  46. #define Melder_FLAC_COMPRESSION_16 15
  47. #define Melder_FLAC_COMPRESSION_24 16
  48. #define Melder_FLAC_COMPRESSION_32 17
  49. #define Melder_MPEG_COMPRESSION_16 18
  50. #define Melder_MPEG_COMPRESSION_24 19
  51. #define Melder_MPEG_COMPRESSION_32 20
  52. int Melder_defaultAudioFileEncoding (int audioFileType, int numberOfBitsPerSamplePoint); /* BIG_ENDIAN, BIG_ENDIAN, LITTLE_ENDIAN, BIG_ENDIAN, LITTLE_ENDIAN */
  53. void MelderFile_writeAudioFileHeader (MelderFile file, int audioFileType, integer sampleRate, integer numberOfSamples, int numberOfChannels, int numberOfBitsPerSamplePoint);
  54. void MelderFile_writeAudioFileTrailer (MelderFile file, int audioFileType, integer sampleRate, integer numberOfSamples, int numberOfChannels, int numberOfBitsPerSamplePoint);
  55. void MelderFile_writeAudioFile (MelderFile file, int audioFileType, const short *buffer, integer sampleRate, integer numberOfSamples, int numberOfChannels, int numberOfBitsPerSamplePoint);
  56. int MelderFile_checkSoundFile (MelderFile file, integer *numberOfChannels, int *encoding,
  57. double *sampleRate, integer *startOfData, integer *numberOfSamples);
  58. /* Returns information about a just opened audio file.
  59. * The return value is the audio file type, or 0 if it is not a sound file or in case of error.
  60. * The data start at 'startOfData' bytes from the start of the file.
  61. */
  62. int Melder_bytesPerSamplePoint (int encoding);
  63. void Melder_readAudioToFloat (FILE *f, int encoding, MAT buffer);
  64. /* Reads channels into buffer [ichannel], which are base-1.
  65. */
  66. void Melder_readAudioToShort (FILE *f, integer numberOfChannels, int encoding, short *buffer, integer numberOfSamples);
  67. /* If stereo, buffer will contain alternating left and right values.
  68. * Buffer is base-0.
  69. */
  70. void MelderFile_writeFloatToAudio (MelderFile file, constMAT buffer, int encoding, bool warnIfClipped);
  71. void MelderFile_writeShortToAudio (MelderFile file, integer numberOfChannels, int encoding, const short *buffer, integer numberOfSamples);
  72. /* End of file melder_audiofiles.h */
  73. #endif