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