| 1 | #ifndef _LongSound_h_ |
| 2 | #define _LongSound_h_ |
| 3 | /* LongSound.h |
| 4 | * |
| 5 | * Copyright (C) 1992-2005,2007,2008,2010-2012,2015-2017,2019,2022,2023 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 | |
| 21 | #include "Sound.h" |
| 22 | #include "Collection.h" |
| 23 | |
| 24 | #define COMPRESSED_MODE_READ_FLOAT 0 |
| 25 | #define COMPRESSED_MODE_READ_SHORT 1 |
| 26 | |
| 27 | struct FLAC__StreamDecoder; |
| 28 | struct FLAC__StreamEncoder; |
| 29 | struct _MP3_FILE; |
| 30 | |
| 31 | Thing_define (LongSound, SampledXY) { |
| 32 | structMelderFile file; |
| 33 | FILE *f; |
| 34 | int audioFileType, encoding, numberOfBytesPerSamplePoint; |
| 35 | integer numberOfChannels; |
| 36 | double sampleRate; |
| 37 | integer startOfData; |
| 38 | double bufferLength; |
| 39 | |
| 40 | integer nmax; |
| 41 | autovector <int16> buffer; // this is always 16-bit, because we will always play sounds in 16-bit, even those from 24-bit files |
| 42 | integer imin, imax; |
| 43 | void invalidateBuffer () noexcept { our imin = 1; our imax = 0; } |
| 44 | |
| 45 | struct FLAC__StreamDecoder *flacDecoder; |
| 46 | struct _MP3_FILE *mp3f; |
| 47 | int compressedMode; |
| 48 | integer compressedSamplesLeft; |
| 49 | double *compressedFloats [2]; |
| 50 | int16 *compressedShorts; |
| 51 | |
| 52 | void v9_destroy () noexcept |
| 53 | override; |
| 54 | void v1_info () |
| 55 | override; |
| 56 | void v1_copy (Daata data_to) const |
| 57 | override; |
| 58 | bool v_writable () |
| 59 | override { return false; } |
| 60 | int v_domainQuantity () const |
| 61 | override { return MelderQuantity_TIME_SECONDS; } |
| 62 | }; |
| 63 | |
| 64 | autoLongSound LongSound_open (MelderFile file); |
| 65 | |
| 66 | autoSound LongSound_extractPart (LongSound me, double tmin, double tmax, bool preserveTimes); |
| 67 | |
| 68 | bool LongSound_haveWindow (LongSound me, double tmin, double tmax); |
| 69 | /* |
| 70 | * Returns 0 if error or if window exceeds buffer, otherwise 1; |
| 71 | */ |
| 72 | |
| 73 | void LongSound_getWindowExtrema (LongSound me, double tmin, double tmax, integer channel, double *minimum, double *maximum); |
| 74 | |
| 75 | void LongSound_playPart (LongSound me, double startTime, double endTime, Sound_PlayCallback playCallback, Thing playBoss); |
| 76 | |
| 77 | void LongSound_savePartAsAudioFile (LongSound me, int audioFileType, double tmin, double tmax, MelderFile file, int numberOfBitsPerSamplePoint); |
| 78 | void LongSound_saveChannelAsAudioFile (LongSound me, int audioFileType, integer channel, MelderFile file); |
| 79 | |
| 80 | void LongSound_readAudioToFloat (LongSound me, MAT buffer, integer firstSample); |
| 81 | void LongSound_readAudioToShort (LongSound me, int16 *buffer, integer firstSample, integer numberOfSamples); |
| 82 | |
| 83 | Collection_define (SoundAndLongSoundList, OrderedOf, SampledXY) { |
| 84 | }; |
| 85 | |
| 86 | void LongSound_concatenate (SoundAndLongSoundList collection, MelderFile file, int audioFileType, int numberOfBitsPerSamplePoint); |
| 87 | |
| 88 | void LongSound_preferences (); |
| 89 | integer LongSound_getBufferSizePref_seconds (); |
| 90 | void LongSound_setBufferSizePref_seconds (integer size); |
| 91 | |
| 92 | /* End of file LongSound.h */ |
| 93 | #endif |