| 1 | /* LongSound.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2008,2010-2019,2021-2025 Paul Boersma, 2007 Erez Volk (for FLAC and MP3) |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * pb 2002/05/28 |
| 21 | * pb 2002/07/16 GPL |
| 22 | * pb 2003/09/12 changed 5 to Melder_NUMBER_OF_AUDIO_FILE_TYPES |
| 23 | * pb 2004/05/14 support for reading 24-bit and 32-bit audio files |
| 24 | * pb 2004/11/24 made buffer length settable |
| 25 | * pb 2006/12/10 MelderInfo |
| 26 | * pb 2006/12/13 support for IEEE float 32-bit audio files |
| 27 | * pb 2007/01/01 compatible with stereo sounds |
| 28 | * pb 2007/01/27 more compatible with stereo sounds |
| 29 | * pb 2007/03/17 domain quantity |
| 30 | * Erez Volk 2007/03 FLAC reading |
| 31 | * Erez Volk 2007/05/14 FLAC writing |
| 32 | * Erez Volk 2007/06/04 MP3 reading |
| 33 | * pb 2007/12/05 prefs |
| 34 | * pb 2008/01/19 double |
| 35 | * pb 2010/01/10 MP3 precision warning |
| 36 | * fb 2010/02/25 corrected a bug that could cause LongSound_playPart to crash with an assertion on error |
| 37 | * pb 2010/11/07 no longer do an assertion on thy resampledBuffer |
| 38 | * pb 2010/12/20 support for more than 2 channels |
| 39 | * pb 2011/06/02 C++ |
| 40 | * pb 2011/07/05 C++ |
| 41 | * pb 2014/06/16 more support for more than 2 channels |
| 42 | */ |
| 43 | |
| 44 | #include "LongSound.h"cxx . . $ `<file>/fon/LongSound.h`/ |
| 45 | #include "Preferences.h"cxx . . $ `<file>/sys/Preferences.h`/ |
| 46 | #define FLAC__NO_DLLcxx . . $ `fon/LongSound.cpp:46:9`! |
| 47 | #include "../external/flac/flac_FLAC_stream_decoder.h"cxx . . $ `<file>/external/flac/flac_FLAC_stream_decoder.h`/ |
| 48 | #include "../external/mp3/mp3.h"cxx . . $ `<file>/external/mp3/mp3.h`/ |
| 49 | |
| 50 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (LongSound, SampledXY, 0); |
| 51 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (SoundAndLongSoundList, Ordered, 0); |
| 52 | |
| 53 | #define MARGINcxx . . $ `fon/LongSound.cpp:53:9`! 0.01 |
| 54 | #define USE_MEMMOVEcxx . . $ `fon/LongSound.cpp:54:9`! 1 |
| 55 | |
| 56 | constexpr integercxx . . $ integer# minimumBufferDurationcxx . . $ minimumBufferDuration. = 10; // seconds |
| 57 | constexpr integercxx . . $ integer# defaultBufferDurationcxx . . $ defaultBufferDuration. = 600; // seconds |
| 58 | constexpr integercxx . . $ integer# maximumBufferDurationcxx . . $ maximumBufferDuration. = 10000; // seconds |
| 59 | |
| 60 | static integercxx . . $ integer# prefs_bufferLengthcxx . . $ prefs_bufferLength.; |
| 61 | |
| 62 | void LongSound_preferencescxx . . $ LongSound_preferences(49f6e7a06ebc5aa8). () { |
| 63 | Preferences_addIntegercxx . . $ Preferences_addInteger(dd1501ba114a3e1c). (U"LongSound.bufferLength2", & prefs_bufferLengthcxx . . $ prefs_bufferLength., defaultBufferDurationcxx . . $ defaultBufferDuration.); |
| 64 | } |
| 65 | |
| 66 | integercxx . . $ integer# LongSound_getBufferSizePref_secondscxx . . $ LongSound_getBufferSizePref_seconds(da6335ded91d79c2). () { |
| 67 | return prefs_bufferLengthcxx . . $ prefs_bufferLength.; |
| 68 | } |
| 69 | |
| 70 | void LongSound_setBufferSizePref_secondscxx . . $ LongSound_setBufferSizePref_seconds(1624ee8275b10bda). (const integercxx . . $ integer# size) { |
| 71 | prefs_bufferLengthcxx . . $ prefs_bufferLength. = Melder_clippedcxx . . $ Melder_clipped(5eb09607cedc971b). (minimumBufferDurationcxx . . $ minimumBufferDuration., size, maximumBufferDurationcxx . . $ maximumBufferDuration.); |
| 72 | } |
| 73 | |
| 74 | void structLongSoundcxx . . $ structLongSound# :: v9_destroycxx . . $ structLongSound#v9_destroy(ced63f7c635d850d). () noexcept { |
| 75 | /* |
| 76 | The play callback may contain a pointer to my buffer. |
| 77 | That pointer is about to dangle, so kill the playback. |
| 78 | */ |
| 79 | MelderAudio_stopPlayingcxx . . $ MelderAudio_stopPlaying(efaadfb7dc14930a). (MelderAudio_IMPLICITcxx . . $ `melder/melder_audio.h:57:9`!); |
| 80 | if (mp3fcxx . . $ structLongSound#mp3f.) |
| 81 | mp3f_deletecxx . . $ mp3f_delete(b5973ac325583f8). (mp3fcxx . . $ structLongSound#mp3f.); |
| 82 | if (flacDecodercxx . . $ structLongSound#flacDecoder.) { |
| 83 | FLAC__stream_decoder_finish (flacDecodercxx . . $ structLongSound#flacDecoder.); // closes f |
| 84 | FLAC__stream_decoder_delete (flacDecodercxx . . $ structLongSound#flacDecoder.); |
| 85 | } else if (fcxx . . $ structLongSound#f.) { |
| 86 | fclose (fcxx . . $ structLongSound#f.); |
| 87 | } |
| 88 | LongSound_Parentcxx . . $ LongSound_Parent# :: v9_destroycxx . . $ structSampledXY#v9_destroy(ced63f7c635d850d). (); |
| 89 | } |
| 90 | |
| 91 | void structLongSoundcxx . . $ structLongSound# :: v1_infocxx . . $ structLongSound#v1_info(49f6e7a06ebc5aa8). () { |
| 92 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 93 | static const conststring32cxx . . $ conststring32# encodingStrings [1+22] = { U"none", |
| 94 | U"linear 8 bit signed", U"linear 8 bit unsigned", |
| 95 | U"linear 16 bit big-endian", U"linear 16 bit little-endian", |
| 96 | U"linear 24 bit big-endian", U"linear 24 bit little-endian", |
| 97 | U"linear 32 bit big-endian", U"linear 32 bit little-endian", |
| 98 | U"mu-law", U"A-law", U"shorten", U"polyphone", |
| 99 | U"IEEE float 32 bit big-endian", U"IEEE float 32 bit little-endian", |
| 100 | U"IEEE float 64 bit big-endian", U"IEEE float 64 bit little-endian", |
| 101 | U"FLAC", U"FLAC", U"FLAC", U"MP3", U"MP3", U"MP3" }; |
| 102 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Duration: ", xmaxcxx . . $ structFunction#xmax. - xmincxx . . $ structFunction#xmin., U" seconds"); |
| 103 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"File name: ", MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& filecxx . . $ structLongSound#file.)); |
| 104 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"File type: ", audioFileTypecxx . . $ structLongSound#audioFileType. > Melder_NUMBER_OF_AUDIO_FILE_TYPEScxx . . $ `melder/melder_audiofiles.h:31:9`! ? U"unknown" : Melder_audioFileTypeStringcxx . . $ Melder_audioFileTypeString(e01d9eb94348e215). (audioFileTypecxx . . $ structLongSound#audioFileType.)); |
| 105 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of channels: ", numberOfChannelscxx . . $ structLongSound#numberOfChannels.); |
| 106 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Encoding: ", encodingcxx . . $ structLongSound#encoding. > 20 ? U"unknown" : encodingStrings [encodingcxx . . $ structLongSound#encoding.]); |
| 107 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Sampling frequency: ", sampleRatecxx . . $ structLongSound#sampleRate., U" Hz"); |
| 108 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Size: ", nxcxx . . $ structSampled#nx., U" samples"); |
| 109 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Start of sample data: ", startOfDatacxx . . $ structLongSound#startOfData., U" bytes from the start of the file"); |
| 110 | } |
| 111 | |
| 112 | static void _LongSound_FLAC_convertFloatscxx . . $ _LongSound_FLAC_convertFloats(cc9451a779405b1a). (LongSoundcxx . . $ LongSound# me, const int32cxx . . $ int32# *const samples[], const integercxx . . $ integer# bitsPerSample, const integercxx . . $ integer# numberOfSamples) { |
| 113 | double multiplier; |
| 114 | switch (bitsPerSample) { |
| 115 | case 8: multiplier = (1.0 / 128.0); break; |
| 116 | case 16: multiplier = (1.0 / 32768.0); break; |
| 117 | case 24: multiplier = (1.0 / 8388608.0); break; |
| 118 | case 32: multiplier = (1.0 / 32768.0 / 65536.0); break; |
| 119 | default: multiplier = 0.0; |
| 120 | } |
| 121 | for (integercxx . . $ integer# i = 0; i < 2; ++i) { |
| 122 | const int32cxx . . $ int32# *input = samples [i]; |
| 123 | double *output = mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [i]; |
| 124 | if (! output ) continue; |
| 125 | for (integercxx . . $ integer# j = 0; j < numberOfSamples; ++j) |
| 126 | output [j] = (double) input [j] * multiplier; |
| 127 | mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [i] += numberOfSamples; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static void _LongSound_FLAC_convertShortscxx . . $ _LongSound_FLAC_convertShorts(cc9451a779405b1a). (LongSoundcxx . . $ LongSound# me, const int32cxx . . $ int32# *const samples[], const integercxx . . $ integer# bitsPerSample, const integercxx . . $ integer# numberOfSamples) { |
| 132 | for (integercxx . . $ integer# channel = 0; channel < mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; ++ channel) { |
| 133 | int16cxx . . $ int16# *output = mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. + channel; |
| 134 | const int32cxx . . $ int32# *input = samples [channel]; |
| 135 | for (integercxx . . $ integer# j = 0; j < numberOfSamples; ++ j, output += mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.) { |
| 136 | int32cxx . . $ int32# sample = * (input ++); |
| 137 | switch (bitsPerSample) { |
| 138 | case 8: sample *= 256; break; |
| 139 | case 16: break; |
| 140 | case 24: sample /= 256; break; |
| 141 | case 32: sample /= 65536; break; |
| 142 | default: sample = 0; break; |
| 143 | } |
| 144 | *output = (int16cxx . . $ int16#) sample; |
| 145 | } |
| 146 | } |
| 147 | mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. += numberOfSamples * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 148 | } |
| 149 | |
| 150 | static FLAC__StreamDecoderWriteStatus _LongSound_FLAC_writecxx . . $ _LongSound_FLAC_write(8375096e9a6e9bab). (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32cxx . . $ FLAC__int32# *const buffer[], void *void_me) { |
| 151 | iamcxx . . $ `melder/melder.h:50:9`! (LongSound); |
| 152 | const FLAC__FrameHeader *header = & frame -> header; |
| 153 | integercxx . . $ integer# numberOfSamples = header -> blocksize; |
| 154 | const integercxx . . $ integer# bitsPerSample = header -> bits_per_sample; |
| 155 | (void) decoder; |
| 156 | if (numberOfSamples > mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft.) |
| 157 | numberOfSamples = mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft.; |
| 158 | if (numberOfSamples == 0) |
| 159 | return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
| 160 | if (mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. == COMPRESSED_MODE_READ_FLOATcxx . . $ `fon/LongSound.h:24:9`!) |
| 161 | _LongSound_FLAC_convertFloatscxx . . $ _LongSound_FLAC_convertFloats(cc9451a779405b1a). (me, buffer, bitsPerSample, numberOfSamples); |
| 162 | else |
| 163 | _LongSound_FLAC_convertShortscxx . . $ _LongSound_FLAC_convertShorts(cc9451a779405b1a). (me, buffer, bitsPerSample, numberOfSamples); |
| 164 | mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft. -= numberOfSamples; |
| 165 | return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
| 166 | } |
| 167 | |
| 168 | static void _LongSound_FLAC_errorcxx . . $ _LongSound_FLAC_error(56d9ba04c86f7e6d). (const FLAC__StreamDecoder * /* decoder */, FLAC__StreamDecoderErrorStatus /* status */, void * /* longSound */) { |
| 169 | } |
| 170 | |
| 171 | static void _LongSound_MP3_convertFloatscxx . . $ _LongSound_MP3_convertFloats(4469664a0eec239b). (LongSoundcxx . . $ LongSound# me, const MP3F_SAMPLEcxx . . $ MP3F_SAMPLE# *channels [MP3F_MAX_CHANNELScxx . . $ `external/mp3/mp3.h:37:9`!], const integercxx . . $ integer# numberOfSamples) { |
| 172 | for (integercxx . . $ integer# i = 0; i < 2; ++i) { |
| 173 | const MP3F_SAMPLEcxx . . $ MP3F_SAMPLE# *input = channels [i]; |
| 174 | double *output = mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [i]; |
| 175 | if (! output ) |
| 176 | continue; |
| 177 | for (integercxx . . $ integer# j = 0; j < numberOfSamples; ++j) |
| 178 | output [j] = mp3f_sample_to_floatcxx . . $ `external/mp3/mp3.h:60:9`! (input [j]); |
| 179 | mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [i] += numberOfSamples; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static void _LongSound_MP3_convertShortscxx . . $ _LongSound_MP3_convertShorts(4469664a0eec239b). (LongSoundcxx . . $ LongSound# me, const MP3F_SAMPLEcxx . . $ MP3F_SAMPLE# *channels [MP3F_MAX_CHANNELScxx . . $ `external/mp3/mp3.h:37:9`!], const integercxx . . $ integer# numberOfSamples) { |
| 184 | for (integercxx . . $ integer# i = 0; i < mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; ++ i) { |
| 185 | const MP3F_SAMPLEcxx . . $ MP3F_SAMPLE# *input = channels [i]; |
| 186 | int16cxx . . $ int16# *output = mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. + i; |
| 187 | for (integercxx . . $ integer# j = 0; j < numberOfSamples; ++j, output += mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.) { |
| 188 | const int sample = *input++; |
| 189 | *output = mp3f_sample_to_shortcxx . . $ mp3f_sample_to_short(60050ad348e56ea6). (sample); |
| 190 | } |
| 191 | } |
| 192 | mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. += numberOfSamples * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 193 | } |
| 194 | |
| 195 | static void _LongSound_MP3_convertcxx . . $ _LongSound_MP3_convert(241d5354e6f19867). (const MP3F_SAMPLEcxx . . $ MP3F_SAMPLE# *channels [MP3F_MAX_CHANNELScxx . . $ `external/mp3/mp3.h:37:9`!], integercxx . . $ integer# numberOfSamples, void *void_me) { |
| 196 | iamcxx . . $ `melder/melder.h:50:9`! (LongSound); |
| 197 | if (numberOfSamples > mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft.) |
| 198 | numberOfSamples = mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft.; |
| 199 | if (numberOfSamples == 0) |
| 200 | return; |
| 201 | if (mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. == COMPRESSED_MODE_READ_FLOATcxx . . $ `fon/LongSound.h:24:9`!) |
| 202 | _LongSound_MP3_convertFloatscxx . . $ _LongSound_MP3_convertFloats(4469664a0eec239b). (me, channels, numberOfSamples); |
| 203 | else |
| 204 | _LongSound_MP3_convertShortscxx . . $ _LongSound_MP3_convertShorts(4469664a0eec239b). (me, channels, numberOfSamples); |
| 205 | mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft. -= numberOfSamples; |
| 206 | } |
| 207 | |
| 208 | static void LongSound_initcxx . . $ LongSound_init(2fb67be231aca22e). (LongSoundcxx . . $ LongSound# me, constMelderFilecxx . . $ constMelderFile# file) { |
| 209 | MelderFile_copycxx . . $ MelderFile_copy(b298201f6d539a65). (file, & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file.); |
| 210 | MelderFile_opencxx . . $ MelderFile_open(c1cfd957ea3b2501). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file.); |
| 211 | mycxx . . $ `melder/melder.h:44:9`! fcxx . . $ structLongSound#f. = mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file.. filePointercxx . . $ structMelderFile#filePointer.; |
| 212 | mycxx . . $ `melder/melder.h:44:9`! audioFileTypecxx . . $ structLongSound#audioFileType. = MelderFile_checkSoundFilecxx . . $ MelderFile_checkSoundFile(61aa38baf9d22bef). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file., & mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., & mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding., & mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., & mycxx . . $ `melder/melder.h:44:9`! startOfDatacxx . . $ structLongSound#startOfData., & mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 213 | if (mycxx . . $ `melder/melder.h:44:9`! audioFileTypecxx . . $ structLongSound#audioFileType. == 0) |
| 214 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"File not recognized (LongSound only supports AIFF, AIFC, WAV, NeXT/Sun, NIST and FLAC)."); |
| 215 | if (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_SHORTENcxx . . $ `melder/melder_audiofiles.h:44:9`! || mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_POLYPHONEcxx . . $ `melder/melder_audiofiles.h:45:9`!) |
| 216 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"LongSound does not support sound files compressed with \"shorten\"."); |
| 217 | if (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. < 1) |
| 218 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Audio file contains 0 samples."); |
| 219 | mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. = 0.0; |
| 220 | mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. = 1.0 / mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; |
| 221 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 222 | mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. = 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 223 | mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. = 1.0; |
| 224 | mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. = mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; // TODO: rid numberOfChannels |
| 225 | mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. = mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 226 | mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. = 1.0; |
| 227 | mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. = 1.0; |
| 228 | mycxx . . $ `melder/melder.h:44:9`! numberOfBytesPerSamplePointcxx . . $ structLongSound#numberOfBytesPerSamplePoint. = Melder_bytesPerSamplePointcxx . . $ Melder_bytesPerSamplePoint(7864480464b09eea). (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding.); |
| 229 | mycxx . . $ `melder/melder.h:44:9`! bufferLengthcxx . . $ structLongSound#bufferLength. = prefs_bufferLengthcxx . . $ prefs_bufferLength.; |
| 230 | for (;;) { |
| 231 | mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax. = mycxx . . $ `melder/melder.h:44:9`! bufferLengthcxx . . $ structLongSound#bufferLength. * mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate. * (1 + 3 * MARGINcxx . . $ `fon/LongSound.cpp:53:9`!); |
| 232 | try { |
| 233 | mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <int16cxx . . $ int16#> (mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax. * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. + 1); |
| 234 | break; |
| 235 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 236 | mycxx . . $ `melder/melder.h:44:9`! bufferLengthcxx . . $ structLongSound#bufferLength. *= 0.5; // try 30, 15, or 7.5 seconds |
| 237 | if (mycxx . . $ `melder/melder.h:44:9`! bufferLengthcxx . . $ structLongSound#bufferLength. < 5.0) // too short to be good |
| 238 | throw; |
| 239 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); // delete out-of-memory message |
| 240 | } |
| 241 | } |
| 242 | mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. = 1; |
| 243 | mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. = 0; |
| 244 | mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder. = nullptr; |
| 245 | if (mycxx . . $ `melder/melder.h:44:9`! audioFileTypecxx . . $ structLongSound#audioFileType. == Melder_FLACcxx . . $ `melder/melder_audiofiles.h:29:9`!) { |
| 246 | mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder. = FLAC__stream_decoder_new (); |
| 247 | FLAC__stream_decoder_init_FILE (mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder., mycxx . . $ `melder/melder.h:44:9`! fcxx . . $ structLongSound#f., _LongSound_FLAC_writecxx . . $ _LongSound_FLAC_write(8375096e9a6e9bab)., nullptr, _LongSound_FLAC_errorcxx . . $ _LongSound_FLAC_error(56d9ba04c86f7e6d)., me); |
| 248 | } |
| 249 | mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f. = nullptr; |
| 250 | if (mycxx . . $ `melder/melder.h:44:9`! audioFileTypecxx . . $ structLongSound#audioFileType. == Melder_MP3cxx . . $ `melder/melder_audiofiles.h:30:9`!) { |
| 251 | mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f. = mp3f_newcxx . . $ mp3f_new(4ebb9e873e5fabfd). (); |
| 252 | mp3f_set_filecxx . . $ mp3f_set_file(9e493fed6a4921d4). (mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f., mycxx . . $ `melder/melder.h:44:9`! fcxx . . $ structLongSound#f.); |
| 253 | mp3f_set_callbackcxx . . $ mp3f_set_callback(663816e73508bfcf). (mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f., _LongSound_MP3_convertcxx . . $ _LongSound_MP3_convert(241d5354e6f19867)., me); |
| 254 | if (! mp3f_analyzecxx . . $ mp3f_analyze(2ffd7d1cadc1f948). (mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f.)) |
| 255 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Unable to analyze MP3 file."); |
| 256 | Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Time measurements in MP3 files can be off by several tens of milliseconds. " |
| 257 | U"Please convert to WAV file if you need time precision or annotation."); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void structLongSoundcxx . . $ structLongSound# :: v1_copycxx . . $ structLongSound#v1_copy(42659c2335f2eda7). (Daatacxx . . $ Daata# thee_Daata) const { |
| 262 | LongSoundcxx . . $ LongSound# thee = static_cast <LongSoundcxx . . $ LongSound#> (thee_Daata); |
| 263 | thycxx . . $ `melder/melder.h:45:9`! fcxx . . $ structLongSound#f. = nullptr; |
| 264 | thycxx . . $ `melder/melder.h:45:9`! buffercxx . . $ structLongSound#buffer..releaseToAmbiguousOwnercxx . . $ autovector#releaseToAmbiguousOwner(b4260375df4b1a56).(); // this may have been shallow-copied, so undangle and nullify |
| 265 | LongSound_initcxx . . $ LongSound_init(2fb67be231aca22e). (thee, & ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structLongSound#file.); // this recreates a new buffer |
| 266 | } |
| 267 | |
| 268 | autoLongSoundcxx . . $ autoLongSound# LongSound_opencxx . . $ LongSound_open(107087064625cb51). (MelderFilecxx . . $ MelderFile# file) { |
| 269 | try { |
| 270 | autoLongSoundcxx . . $ autoLongSound# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (LongSound); |
| 271 | LongSound_initcxx . . $ LongSound_init(2fb67be231aca22e). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), file); |
| 272 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 273 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 274 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"LongSound not created."); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | static void _LongSound_FLAC_processcxx . . $ _LongSound_FLAC_process(c5e569014be5f0ed). (LongSoundcxx . . $ LongSound# me, const integercxx . . $ integer# firstSample, const integercxx . . $ integer# numberOfSamples) { |
| 279 | mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft. = numberOfSamples - 1; |
| 280 | if (! FLAC__stream_decoder_seek_absolute (mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder., firstSample)) |
| 281 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot seek in FLAC file ", & mycxx . . $ `melder/melder.h:44:9`! file, U"."); |
| 282 | while (mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft. > 0) { |
| 283 | if (FLAC__stream_decoder_get_state (mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder.) == FLAC__STREAM_DECODER_END_OF_STREAM) |
| 284 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"FLAC file ", & mycxx . . $ `melder/melder.h:44:9`! file, U" too short."); |
| 285 | if (! FLAC__stream_decoder_process_single (mycxx . . $ `melder/melder.h:44:9`! flacDecodercxx . . $ structLongSound#flacDecoder.)) |
| 286 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error decoding FLAC file ", & mycxx . . $ `melder/melder.h:44:9`! file, U"."); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static void _LongSound_FILE_seekSamplecxx . . $ _LongSound_FILE_seekSample(8c51e0e3497b4534). (LongSoundcxx . . $ LongSound# me, const integercxx . . $ integer# firstSample) { |
| 291 | if (fseek (mycxx . . $ `melder/melder.h:44:9`! fcxx . . $ structLongSound#f., mycxx . . $ `melder/melder.h:44:9`! startOfDatacxx . . $ structLongSound#startOfData. + (firstSample - 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. * mycxx . . $ `melder/melder.h:44:9`! numberOfBytesPerSamplePointcxx . . $ structLongSound#numberOfBytesPerSamplePoint., SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!)) |
| 292 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot seek in file ", & mycxx . . $ `melder/melder.h:44:9`! file, U"."); |
| 293 | } |
| 294 | |
| 295 | static void _LongSound_FLAC_readAudioToShortcxx . . $ _LongSound_FLAC_readAudioToShort(f3ebc2e91f6ce9). (LongSoundcxx . . $ LongSound# me, int16cxx . . $ int16# *buffer, const integercxx . . $ integer# firstSample, const integercxx . . $ integer# numberOfSamples) { |
| 296 | mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. = COMPRESSED_MODE_READ_SHORTcxx . . $ `fon/LongSound.h:25:9`!; |
| 297 | mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. = buffer + 1; |
| 298 | _LongSound_FLAC_processcxx . . $ _LongSound_FLAC_process(c5e569014be5f0ed). (me, firstSample, numberOfSamples); |
| 299 | } |
| 300 | |
| 301 | static void _LongSound_MP3_processcxx . . $ _LongSound_MP3_process(c5e569014be5f0ed). (LongSoundcxx . . $ LongSound# me, const integercxx . . $ integer# firstSample, const integercxx . . $ integer# numberOfSamples) { |
| 302 | if (! mp3f_seekcxx . . $ mp3f_seek(843f2f4d3233e485). (mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f., firstSample)) |
| 303 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot seek in MP3 file ", & mycxx . . $ `melder/melder.h:44:9`! file, U"."); |
| 304 | mycxx . . $ `melder/melder.h:44:9`! compressedSamplesLeftcxx . . $ structLongSound#compressedSamplesLeft. = numberOfSamples; |
| 305 | if (! mp3f_readcxx . . $ mp3f_read(843f2f4d3233e485). (mycxx . . $ `melder/melder.h:44:9`! mp3fcxx . . $ structLongSound#mp3f., numberOfSamples)) |
| 306 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Error decoding MP3 file ", & mycxx . . $ `melder/melder.h:44:9`! file, U"."); |
| 307 | } |
| 308 | |
| 309 | static void _LongSound_MP3_readAudioToShortcxx . . $ _LongSound_MP3_readAudioToShort(f3ebc2e91f6ce9). (LongSoundcxx . . $ LongSound# me, int16cxx . . $ int16# *buffer, const integercxx . . $ integer# firstSample, const integercxx . . $ integer# numberOfSamples) { |
| 310 | mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. = COMPRESSED_MODE_READ_SHORTcxx . . $ `fon/LongSound.h:25:9`!; |
| 311 | mycxx . . $ `melder/melder.h:44:9`! compressedShortscxx . . $ structLongSound#compressedShorts. = buffer + 1; |
| 312 | _LongSound_MP3_processcxx . . $ _LongSound_MP3_process(c5e569014be5f0ed). (me, firstSample, numberOfSamples - 1); |
| 313 | } |
| 314 | |
| 315 | void LongSound_readAudioToFloatcxx . . $ LongSound_readAudioToFloat(d665ec187261507b). (LongSoundcxx . . $ LongSound# me, const MATcxx . . $ MAT# buffer, const integercxx . . $ integer# firstSample) { |
| 316 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (buffer.nrow == mycxx . . $ `melder/melder.h:44:9`! numberOfChannels); |
| 317 | if (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_FLAC_COMPRESSION_16cxx . . $ `melder/melder_audiofiles.h:50:9`!) { |
| 318 | mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. = COMPRESSED_MODE_READ_FLOATcxx . . $ `fon/LongSound.h:24:9`!; |
| 319 | for (int ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; ichan ++) { |
| 320 | mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [ichan - 1] = & buffer [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]; |
| 321 | } |
| 322 | _LongSound_FLAC_processcxx . . $ _LongSound_FLAC_process(c5e569014be5f0ed). (me, firstSample, buffer.ncolcxx . . $ matrix#ncol.); |
| 323 | } else if (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_MPEG_COMPRESSION_16cxx . . $ `melder/melder_audiofiles.h:53:9`!) { |
| 324 | mycxx . . $ `melder/melder.h:44:9`! compressedModecxx . . $ structLongSound#compressedMode. = COMPRESSED_MODE_READ_FLOATcxx . . $ `fon/LongSound.h:24:9`!; |
| 325 | for (int ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; ichan ++) { |
| 326 | mycxx . . $ `melder/melder.h:44:9`! compressedFloatscxx . . $ structLongSound#compressedFloats. [ichan - 1] = & buffer [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]; |
| 327 | } |
| 328 | _LongSound_MP3_processcxx . . $ _LongSound_MP3_process(c5e569014be5f0ed). (me, firstSample, buffer.ncolcxx . . $ matrix#ncol.); |
| 329 | } else { |
| 330 | _LongSound_FILE_seekSamplecxx . . $ _LongSound_FILE_seekSample(8c51e0e3497b4534). (me, firstSample); |
| 331 | Melder_readAudioToFloatcxx . . $ Melder_readAudioToFloat(cd19eb660e26204e). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file., mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding., buffer); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | void LongSound_readAudioToShortcxx . . $ LongSound_readAudioToShort(f3ebc2e91f6ce9). (LongSoundcxx . . $ LongSound# me, int16cxx . . $ int16# *buffer, const integercxx . . $ integer# firstSample, const integercxx . . $ integer# numberOfSamples) { |
| 336 | if (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_FLAC_COMPRESSION_16cxx . . $ `melder/melder_audiofiles.h:50:9`!) { |
| 337 | _LongSound_FLAC_readAudioToShortcxx . . $ _LongSound_FLAC_readAudioToShort(f3ebc2e91f6ce9). (me, buffer, firstSample, numberOfSamples); |
| 338 | } else if (mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding. == Melder_MPEG_COMPRESSION_16cxx . . $ `melder/melder_audiofiles.h:53:9`!) { |
| 339 | _LongSound_MP3_readAudioToShortcxx . . $ _LongSound_MP3_readAudioToShort(f3ebc2e91f6ce9). (me, buffer, firstSample, numberOfSamples); |
| 340 | } else { |
| 341 | _LongSound_FILE_seekSamplecxx . . $ _LongSound_FILE_seekSample(8c51e0e3497b4534). (me, firstSample); |
| 342 | Melder_readAudioToShortcxx . . $ Melder_readAudioToShort(deaf455a93aca0df). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structLongSound#file., mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., mycxx . . $ `melder/melder.h:44:9`! encodingcxx . . $ structLongSound#encoding., buffer, numberOfSamples); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | autoSoundcxx . . $ autoSound# LongSound_extractPartcxx . . $ LongSound_extractPart(8c068bc499307d4e). (LongSoundcxx . . $ LongSound# me, double tmin, double tmax, const bool preserveTimes) { |
| 347 | try { |
| 348 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 349 | if (tmin < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 350 | tmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 351 | if (tmax > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 352 | tmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 353 | integercxx . . $ integer# firstSample, lastSample; |
| 354 | const integercxx . . $ integer# numberOfSamples = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & firstSample, & lastSample); |
| 355 | if (numberOfSamples < 1) |
| 356 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Less than 1 sample in window."); |
| 357 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., |
| 358 | tmin, tmax, numberOfSamples, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, firstSample)); |
| 359 | if (! preserveTimes) { |
| 360 | thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. = 0.0; |
| 361 | thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. -= tmin; |
| 362 | thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. -= tmin; |
| 363 | } |
| 364 | LongSound_readAudioToFloatcxx . . $ LongSound_readAudioToFloat(d665ec187261507b). (me, thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), firstSample); |
| 365 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 366 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 367 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": Sound not extracted."); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | static void _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (LongSoundcxx . . $ LongSound# me, int16cxx . . $ int16# *buffer, const integercxx . . $ integer# imin, const integercxx . . $ integer# imax) { |
| 372 | LongSound_readAudioToShortcxx . . $ LongSound_readAudioToShort(f3ebc2e91f6ce9). (me, buffer, imin, imax - imin + 1); |
| 373 | } |
| 374 | |
| 375 | static void writePartToOpenFilecxx . . $ writePartToOpenFile(fe25f1875e30078f). (LongSoundcxx . . $ LongSound# me, int audioFileType, const integercxx . . $ integer# imin, const integercxx . . $ integer# n, |
| 376 | MelderFilecxx . . $ MelderFile# file, const int numberOfChannels_override, const int numberOfBitsPerSamplePoint) |
| 377 | { |
| 378 | if (! file -> filePointercxx . . $ structMelderFile#filePointer.) |
| 379 | return; |
| 380 | const integercxx . . $ integer# numberOfBuffers = (n - 1) / mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax. + 1; |
| 381 | const integercxx . . $ integer# numberOfSamplesInLastBuffer = (n - 1) % mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax. + 1; |
| 382 | for (integercxx . . $ integer# ibuffer = 1, offset = imin; ibuffer <= numberOfBuffers; ibuffer ++) { |
| 383 | const integercxx . . $ integer# numberOfSamplesToCopy = ( ibuffer < numberOfBuffers ? mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax. : numberOfSamplesInLastBuffer ); |
| 384 | mycxx . . $ `melder/melder.h:44:9`! invalidateBuffercxx . . $ structLongSound#invalidateBuffer(ced63f7c635d850d).(); |
| 385 | LongSound_readAudioToShortcxx . . $ LongSound_readAudioToShort(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), offset, numberOfSamplesToCopy); |
| 386 | offset += numberOfSamplesToCopy; |
| 387 | MelderFile_writeShortToAudiocxx . . $ MelderFile_writeShortToAudio(ab333573d658267f). (file, numberOfChannels_override ? numberOfChannels_override : mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., Melder_defaultAudioFileEncodingcxx . . $ Melder_defaultAudioFileEncoding(9b79fb6aee4c0440). (audioFileType, numberOfBitsPerSamplePoint), mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), numberOfSamplesToCopy); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | void LongSound_savePartAsAudioFilecxx . . $ LongSound_savePartAsAudioFile(ecfe2aaf8cd9945b). (LongSoundcxx . . $ LongSound# me, int audioFileType, double tmin, double tmax, MelderFilecxx . . $ MelderFile# file, int numberOfBitsPerSamplePoint) { |
| 392 | try { |
| 393 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 394 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., & tmin); |
| 395 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& tmax, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 396 | integercxx . . $ integer# imin, imax; |
| 397 | const integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & imin, & imax); |
| 398 | if (n < 1) |
| 399 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Less than 1 sample selected."); |
| 400 | autoMelderFilecxx . . $ autoMelderFile# mfile = MelderFile_createcxx . . $ autoMelderFile#autoMelderFile(1145552d769d7b5d). (file); |
| 401 | MelderFile_writeAudioFileHeadercxx . . $ MelderFile_writeAudioFileHeader(2bed0b35f5c41b2b). (file, audioFileType, mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., n, mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., numberOfBitsPerSamplePoint); |
| 402 | writePartToOpenFilecxx . . $ writePartToOpenFile(fe25f1875e30078f). (me, audioFileType, imin, n, file, 0, numberOfBitsPerSamplePoint); |
| 403 | MelderFile_writeAudioFileTrailercxx . . $ MelderFile_writeAudioFileTrailer(2bed0b35f5c41b2b). (file, audioFileType, mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., n, mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., numberOfBitsPerSamplePoint); |
| 404 | mfile.closecxx . . $ autoMelderFile#close(49f6e7a06ebc5aa8). (); |
| 405 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 406 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not written to sound file ", file, U"."); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | void LongSound_saveChannelAsAudioFilecxx . . $ LongSound_saveChannelAsAudioFile(d8aad8f0b8024c1e). (LongSoundcxx . . $ LongSound# me, int audioFileType, integercxx . . $ integer# channel, MelderFilecxx . . $ MelderFile# file) { |
| 411 | try { |
| 412 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. != 2) |
| 413 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"This audio file is not a stereo file. It does not have a ", channel == 0 ? U"left" : U"right", U" channel."); |
| 414 | autoMelderFilecxx . . $ autoMelderFile# mfile = MelderFile_createcxx . . $ autoMelderFile#autoMelderFile(1145552d769d7b5d). (file); |
| 415 | if (file -> filePointercxx . . $ structMelderFile#filePointer.) |
| 416 | MelderFile_writeAudioFileHeadercxx . . $ MelderFile_writeAudioFileHeader(2bed0b35f5c41b2b). (file, audioFileType, mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., 1, 8 * mycxx . . $ `melder/melder.h:44:9`! numberOfBytesPerSamplePointcxx . . $ structLongSound#numberOfBytesPerSamplePoint.); |
| 417 | writePartToOpenFilecxx . . $ writePartToOpenFile(fe25f1875e30078f). (me, audioFileType, 1, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., file, channel == 0 ? -1 : -2, 8 * mycxx . . $ `melder/melder.h:44:9`! numberOfBytesPerSamplePointcxx . . $ structLongSound#numberOfBytesPerSamplePoint.); |
| 418 | MelderFile_writeAudioFileTrailercxx . . $ MelderFile_writeAudioFileTrailer(2bed0b35f5c41b2b). (file, audioFileType, mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., 1, 8 * mycxx . . $ `melder/melder.h:44:9`! numberOfBytesPerSamplePointcxx . . $ structLongSound#numberOfBytesPerSamplePoint.); |
| 419 | mfile.closecxx . . $ autoMelderFile#close(49f6e7a06ebc5aa8). (); |
| 420 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 421 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Channel ", channel, U" of ", me, U": not written to sound file ", file, U"."); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | static void _LongSound_haveSamplescxx . . $ _LongSound_haveSamples(c5e569014be5f0ed). (LongSoundcxx . . $ LongSound# me, integercxx . . $ integer# imin, integercxx . . $ integer# imax) { |
| 426 | TRACEcxx . . $ `melder/melder_debug.h:54:9`! |
| 427 | tracecxx . . $ `melder/melder_debug.h:60:10`! (0); |
| 428 | integercxx . . $ integer# n = imax - imin + 1; |
| 429 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (n <= mycxx . . $ `melder/melder.h:44:9`! nmax); |
| 430 | /* |
| 431 | Included? |
| 432 | */ |
| 433 | if (imin >= mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. && imax <= mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax.) |
| 434 | return; |
| 435 | /* |
| 436 | Extendable? |
| 437 | */ |
| 438 | if (imin >= mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. && imax - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. + 1 <= mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax.) { |
| 439 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. + 1, imax); |
| 440 | mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. = imax; |
| 441 | return; |
| 442 | } |
| 443 | /* |
| 444 | Determine the loadable imin..imax. |
| 445 | Add margins on both sides. |
| 446 | */ |
| 447 | imin -= MARGINcxx . . $ `fon/LongSound.cpp:53:9`! * n; |
| 448 | if (imin < 1) |
| 449 | imin = 1; |
| 450 | imax = imin + Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((1.0 + 2.0 * MARGINcxx . . $ `fon/LongSound.cpp:53:9`!) * n); |
| 451 | if (imax > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) |
| 452 | imax = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 453 | imin = imax - Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((1.0 + 2.0 * MARGINcxx . . $ `fon/LongSound.cpp:53:9`!) * n); |
| 454 | if (imin < 1) |
| 455 | imin = 1; |
| 456 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (imax - imin + 1 <= mycxx . . $ `melder/melder.h:44:9`! nmax); |
| 457 | tracecxx . . $ `melder/melder_debug.h:60:10`! (1); |
| 458 | /* |
| 459 | Overlap? |
| 460 | */ |
| 461 | if (imax < mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. || imin > mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax.) { |
| 462 | /* |
| 463 | No overlap. |
| 464 | */ |
| 465 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), imin, imax); |
| 466 | } else if (imin < mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) { |
| 467 | /* |
| 468 | Left overlap. |
| 469 | */ |
| 470 | if (imax <= mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax.) { |
| 471 | /* |
| 472 | Only left overlap (e.g. scrolling up). |
| 473 | */ |
| 474 | const integercxx . . $ integer# nshift = (imax - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., shift = (mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. - imin) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 475 | #if USE_MEMMOVEcxx . . $ `fon/LongSound.cpp:54:9`! |
| 476 | memmove (mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + shift, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), nshift * sizeof (int16cxx . . $ int16#)); |
| 477 | #else |
| 478 | for (i = nshift; i >= 1; i --) |
| 479 | my buffer [i + shift] = my buffer [i]; |
| 480 | #endif |
| 481 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), imin, mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. - 1); |
| 482 | } else { |
| 483 | /* |
| 484 | Left and right overlap (e.g. zooming out). |
| 485 | */ |
| 486 | const integercxx . . $ integer# nshift = (mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., shift = (mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. - imin) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 487 | #if USE_MEMMOVEcxx . . $ `fon/LongSound.cpp:54:9`! |
| 488 | memmove (mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + shift, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), nshift * sizeof (int16cxx . . $ int16#)); |
| 489 | #else |
| 490 | for (i = nshift; i >= 1; i --) |
| 491 | my buffer [i + shift] = my buffer [i]; |
| 492 | #endif |
| 493 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), imin, mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. - 1); |
| 494 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. - imin + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. + 1, imax); |
| 495 | } |
| 496 | } else { |
| 497 | /* |
| 498 | Only right overlap (e.g. scrolling down). |
| 499 | */ |
| 500 | const integercxx . . $ integer# nshift = (mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. - imin + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., shift = (imin - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 501 | #if USE_MEMMOVEcxx . . $ `fon/LongSound.cpp:54:9`! |
| 502 | memmove (mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + shift, nshift * sizeof (int16cxx . . $ int16#)); |
| 503 | #else |
| 504 | for (i = 1; i <= nshift; i ++) |
| 505 | my buffer [i] = my buffer [i + shift]; |
| 506 | #endif |
| 507 | _LongSound_readSamplescxx . . $ _LongSound_readSamples(f3ebc2e91f6ce9). (me, mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. - imin + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. + 1, imax); |
| 508 | } |
| 509 | mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin. = imin; |
| 510 | mycxx . . $ `melder/melder.h:44:9`! imaxcxx . . $ structLongSound#imax. = imax; |
| 511 | tracecxx . . $ `melder/melder_debug.h:60:10`! (2); |
| 512 | } |
| 513 | |
| 514 | bool LongSound_haveWindowcxx . . $ LongSound_haveWindow(800e017703ada13a). (LongSoundcxx . . $ LongSound# me, double tmin, double tmax) { |
| 515 | integercxx . . $ integer# imin, imax; |
| 516 | const integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & imin, & imax); |
| 517 | if ((1.0 + 2 * MARGINcxx . . $ `fon/LongSound.cpp:53:9`!) * n + 1 > mycxx . . $ `melder/melder.h:44:9`! nmaxcxx . . $ structLongSound#nmax.) |
| 518 | return false; |
| 519 | _LongSound_haveSamplescxx . . $ _LongSound_haveSamples(c5e569014be5f0ed). (me, imin, imax); |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | void LongSound_getWindowExtremacxx . . $ LongSound_getWindowExtrema(149e83e2dc5652b8). (LongSoundcxx . . $ LongSound# me, double tmin, double tmax, const integercxx . . $ integer# channel, double *minimum, double *maximum) { |
| 524 | integercxx . . $ integer# imin, imax; |
| 525 | (void) Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & imin, & imax); |
| 526 | *minimum = 1.0; |
| 527 | *maximum = -1.0; |
| 528 | try { |
| 529 | LongSound_haveWindowcxx . . $ LongSound_haveWindow(800e017703ada13a). (me, tmin, tmax); |
| 530 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 531 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 532 | return; |
| 533 | } |
| 534 | integercxx . . $ integer# minimum_int = 32767, maximum_int = -32768; |
| 535 | for (integercxx . . $ integer# i = imin; i <= imax; i ++) { |
| 536 | const integercxx . . $ integer# value = mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).(i - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. + channel]; |
| 537 | if (value < minimum_int) |
| 538 | minimum_int = value; |
| 539 | if (value > maximum_int) |
| 540 | maximum_int = value; |
| 541 | } |
| 542 | *minimum = minimum_int / 32768.0; |
| 543 | *maximum = maximum_int / 32768.0; |
| 544 | } |
| 545 | |
| 546 | static struct LongSoundPlaycxx . . $ LongSoundPlay# { |
| 547 | integercxx . . $ integer# numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples., i1cxx . . $ LongSoundPlay#i1., i2cxx . . $ LongSoundPlay#i2., silenceBeforecxx . . $ LongSoundPlay#silenceBefore., silenceAftercxx . . $ LongSoundPlay#silenceAfter.; |
| 548 | double startTimecxx . . $ LongSoundPlay#startTime., endTimecxx . . $ LongSoundPlay#endTime., dtcxx . . $ LongSoundPlay#dt., t1cxx . . $ LongSoundPlay#t1.; |
| 549 | int16cxx . . $ int16# *resampledBuffercxx . . $ LongSoundPlay#resampledBuffer.; |
| 550 | Sound_PlayCallbackcxx . . $ Sound_PlayCallback# playCallbackcxx . . $ LongSoundPlay#playCallback.; |
| 551 | Thingcxx . . $ Thing# playBosscxx . . $ LongSoundPlay#playBoss.; |
| 552 | } thePlayingLongSoundcxx . . $ thePlayingLongSound.; |
| 553 | |
| 554 | static bool melderPlayCallbackcxx . . $ melderPlayCallback(22efc3fb69126f04). (void *closure, const integercxx . . $ integer# samplesPlayed) { |
| 555 | struct LongSoundPlaycxx . . $ LongSoundPlay# *me = (struct LongSoundPlaycxx . . $ LongSoundPlay# *) closure; |
| 556 | int phase = 2; |
| 557 | const double t = samplesPlayed <= mycxx . . $ `melder/melder.h:44:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. ? mycxx . . $ `melder/melder.h:44:9`! startTimecxx . . $ LongSoundPlay#startTime. : |
| 558 | samplesPlayed >= mycxx . . $ `melder/melder.h:44:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. + mycxx . . $ `melder/melder.h:44:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples. ? mycxx . . $ `melder/melder.h:44:9`! endTimecxx . . $ LongSoundPlay#endTime. : |
| 559 | mycxx . . $ `melder/melder.h:44:9`! t1cxx . . $ LongSoundPlay#t1. + (mycxx . . $ `melder/melder.h:44:9`! i1cxx . . $ LongSoundPlay#i1. - 1.5 + samplesPlayed - mycxx . . $ `melder/melder.h:44:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore.) * mycxx . . $ `melder/melder.h:44:9`! dtcxx . . $ LongSoundPlay#dt.; |
| 560 | if (! MelderAudio_isPlayingcxx . . $ MelderAudio_isPlaying.) { |
| 561 | phase = 3; |
| 562 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`! (mycxx . . $ `melder/melder.h:44:9`! resampledBuffer); |
| 563 | } |
| 564 | if (mycxx . . $ `melder/melder.h:44:9`! playCallbackcxx . . $ LongSoundPlay#playCallback.) |
| 565 | return mycxx . . $ `melder/melder.h:44:9`! playCallbackcxx . . $ LongSoundPlay#playCallback. (cxx . . $ MelderCallback#`operator()`(6e5e9b08e48f7d7).mycxx . . $ `melder/melder.h:44:9`! playBosscxx . . $ LongSoundPlay#playBoss., phase, mycxx . . $ `melder/melder.h:44:9`! startTimecxx . . $ LongSoundPlay#startTime., mycxx . . $ `melder/melder.h:44:9`! endTimecxx . . $ LongSoundPlay#endTime., t); |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | void LongSound_playPartcxx . . $ LongSound_playPart(f36b44453a225d5d). (LongSoundcxx . . $ LongSound# me, double startTime, double endTime, Sound_PlayCallbackcxx . . $ Sound_PlayCallback# playCallback, Thingcxx . . $ Thing# playBoss) { |
| 570 | struct LongSoundPlaycxx . . $ LongSoundPlay# *thee = (struct LongSoundPlaycxx . . $ LongSoundPlay# *) & thePlayingLongSoundcxx . . $ thePlayingLongSound.; |
| 571 | MelderAudio_stopPlayingcxx . . $ MelderAudio_stopPlaying(efaadfb7dc14930a). (MelderAudio_IMPLICITcxx . . $ `melder/melder_audio.h:57:9`!); |
| 572 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`! (thycxx . . $ `melder/melder.h:45:9`! resampledBuffer); // just in case, and after playing has stopped |
| 573 | try { |
| 574 | const bool fits = LongSound_haveWindowcxx . . $ LongSound_haveWindow(800e017703ada13a). (me, startTime, endTime); |
| 575 | if (! fits) |
| 576 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sound too long (", endTime - startTime, U" seconds)."); |
| 577 | /* |
| 578 | Assign to *thee only after stopping the playing sound. |
| 579 | */ |
| 580 | thycxx . . $ `melder/melder.h:45:9`! startTimecxx . . $ LongSoundPlay#startTime. = startTime; |
| 581 | thycxx . . $ `melder/melder.h:45:9`! endTimecxx . . $ LongSoundPlay#endTime. = endTime; |
| 582 | thycxx . . $ `melder/melder.h:45:9`! playCallbackcxx . . $ LongSoundPlay#playCallback. =cxx . . $ MelderCallback#`operator=`(ed2c7da5520fb00d). playCallback; |
| 583 | thycxx . . $ `melder/melder.h:45:9`! playBosscxx . . $ LongSoundPlay#playBoss. = playBoss; |
| 584 | integercxx . . $ integer# i1, i2; |
| 585 | const integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, startTime, endTime, & i1, & i2); |
| 586 | if (n < 2) |
| 587 | return; |
| 588 | const integercxx . . $ integer# bestSampleRate = MelderAudio_getOutputBestSampleRatecxx . . $ MelderAudio_getOutputBestSampleRate(8ce0d1b217db7fd1). (mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.); |
| 589 | if (bestSampleRate == mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.) { |
| 590 | thycxx . . $ `melder/melder.h:45:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples. = n; |
| 591 | thycxx . . $ `melder/melder.h:45:9`! dtcxx . . $ LongSoundPlay#dt. = 1.0 / mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; |
| 592 | thycxx . . $ `melder/melder.h:45:9`! t1cxx . . $ LongSoundPlay#t1. = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.; |
| 593 | thycxx . . $ `melder/melder.h:45:9`! i1cxx . . $ LongSoundPlay#i1. = i1; |
| 594 | thycxx . . $ `melder/melder.h:45:9`! i2cxx . . $ LongSoundPlay#i2. = i2; |
| 595 | thycxx . . $ `melder/melder.h:45:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate. * MelderAudio_getOutputSilenceBeforecxx . . $ MelderAudio_getOutputSilenceBefore(31fa7155c10fdd13). ()); |
| 596 | thycxx . . $ `melder/melder.h:45:9`! silenceAftercxx . . $ LongSoundPlay#silenceAfter. = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate. * MelderAudio_getOutputSilenceAftercxx . . $ MelderAudio_getOutputSilenceAfter(31fa7155c10fdd13). ()); |
| 597 | if (thycxx . . $ `melder/melder.h:45:9`! playCallbackcxx . . $ LongSoundPlay#playCallback.) |
| 598 | thycxx . . $ `melder/melder.h:45:9`! playCallbackcxx . . $ LongSoundPlay#playCallback. (cxx . . $ MelderCallback#`operator()`(6e5e9b08e48f7d7).thycxx . . $ `melder/melder.h:45:9`! playBosscxx . . $ LongSoundPlay#playBoss., 1, startTime, endTime, startTime); |
| 599 | if (thycxx . . $ `melder/melder.h:45:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. > 0 || thycxx . . $ `melder/melder.h:45:9`! silenceAftercxx . . $ LongSoundPlay#silenceAfter. > 0 || 1) { |
| 600 | thycxx . . $ `melder/melder.h:45:9`! resampledBuffercxx . . $ LongSoundPlay#resampledBuffer. = Melder_calloccxx . . $ `melder/melder_alloc.h:34:9`! (int16, (thycxx . . $ `melder/melder.h:45:9`! silenceBefore + thycxx . . $ `melder/melder.h:45:9`! numberOfSamples + thycxx . . $ `melder/melder.h:45:9`! silenceAfter) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannels); |
| 601 | memcpy (& thycxx . . $ `melder/melder.h:45:9`! resampledBuffercxx . . $ LongSoundPlay#resampledBuffer. [thycxx . . $ `melder/melder.h:45:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.], |
| 602 | mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (i1 - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., |
| 603 | thycxx . . $ `melder/melder.h:45:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples. * sizeof (int16cxx . . $ int16#) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.); |
| 604 | MelderAudio_play16cxx . . $ MelderAudio_play16(4eeb2eee1b9aa526). (thycxx . . $ `melder/melder.h:45:9`! resampledBuffercxx . . $ LongSoundPlay#resampledBuffer., mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., thycxx . . $ `melder/melder.h:45:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. + thycxx . . $ `melder/melder.h:45:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples. + thycxx . . $ `melder/melder.h:45:9`! silenceAftercxx . . $ LongSoundPlay#silenceAfter., |
| 605 | mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., melderPlayCallbackcxx . . $ melderPlayCallback(22efc3fb69126f04)., thee); |
| 606 | } else { |
| 607 | MelderAudio_play16cxx . . $ MelderAudio_play16(4eeb2eee1b9aa526). (mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (i1 - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate., |
| 608 | thycxx . . $ `melder/melder.h:45:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples., mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., melderPlayCallbackcxx . . $ melderPlayCallback(22efc3fb69126f04)., thee); |
| 609 | } |
| 610 | } else { |
| 611 | const integercxx . . $ integer# newSampleRate = bestSampleRate; |
| 612 | const integercxx . . $ integer# newN = ((double) n * newSampleRate) / mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate. - 1; |
| 613 | const integercxx . . $ integer# silenceBefore = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (newSampleRate * MelderAudio_getOutputSilenceBeforecxx . . $ MelderAudio_getOutputSilenceBefore(31fa7155c10fdd13). ()); |
| 614 | const integercxx . . $ integer# silenceAfter = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (newSampleRate * MelderAudio_getOutputSilenceAftercxx . . $ MelderAudio_getOutputSilenceAfter(31fa7155c10fdd13). ()); |
| 615 | int16cxx . . $ int16# *resampledBuffer = Melder_calloccxx . . $ `melder/melder_alloc.h:34:9`! (int16, (silenceBefore + newN + silenceAfter) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannels); |
| 616 | int16cxx . . $ int16# *from = mycxx . . $ `melder/melder.h:44:9`! buffercxx . . $ structLongSound#buffer..asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + (i1 - mycxx . . $ `melder/melder.h:44:9`! imincxx . . $ structLongSound#imin.) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; // guaranteed: from [0 .. (my imax - my imin + 1) * nchan] |
| 617 | const double t1 = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., dt = 1.0 / newSampleRate; |
| 618 | thycxx . . $ `melder/melder.h:45:9`! numberOfSamplescxx . . $ LongSoundPlay#numberOfSamples. = newN; |
| 619 | thycxx . . $ `melder/melder.h:45:9`! dtcxx . . $ LongSoundPlay#dt. = dt; |
| 620 | thycxx . . $ `melder/melder.h:45:9`! t1cxx . . $ LongSoundPlay#t1. = t1 + i1 / mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; |
| 621 | thycxx . . $ `melder/melder.h:45:9`! i1cxx . . $ LongSoundPlay#i1. = 0; |
| 622 | thycxx . . $ `melder/melder.h:45:9`! i2cxx . . $ LongSoundPlay#i2. = newN - 1; |
| 623 | thycxx . . $ `melder/melder.h:45:9`! silenceBeforecxx . . $ LongSoundPlay#silenceBefore. = silenceBefore; |
| 624 | thycxx . . $ `melder/melder.h:45:9`! silenceAftercxx . . $ LongSoundPlay#silenceAfter. = silenceAfter; |
| 625 | thycxx . . $ `melder/melder.h:45:9`! resampledBuffercxx . . $ LongSoundPlay#resampledBuffer. = resampledBuffer; |
| 626 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. == 1) { |
| 627 | for (integercxx . . $ integer# i = 0; i < newN; i ++) { |
| 628 | const double t = t1 + i * dt; // from t1 to t1 + (newN-1) * dt |
| 629 | const double index = (t - t1) * mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; // from 0 |
| 630 | const integercxx . . $ integer# flore = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (index); |
| 631 | const double fraction = index - flore; |
| 632 | resampledBuffer [i + silenceBefore] = (1.0 - fraction) * from [flore] + fraction * from [flore + 1]; |
| 633 | } |
| 634 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. == 2) { |
| 635 | for (integercxx . . $ integer# i = 0; i < newN; i ++) { |
| 636 | const double t = t1 + i * dt; |
| 637 | const double index = (t - t1) * mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; |
| 638 | const integercxx . . $ integer# flore = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (index); |
| 639 | const double fraction = index - flore; |
| 640 | const integercxx . . $ integer# ii = i + silenceBefore; |
| 641 | resampledBuffer [ii + ii] = (1.0 - fraction) * from [flore + flore] + fraction * from [flore + flore + 2]; |
| 642 | resampledBuffer [ii + ii + 1] = (1.0 - fraction) * from [flore + flore + 1] + fraction * from [flore + flore + 3]; |
| 643 | } |
| 644 | } else { |
| 645 | for (integercxx . . $ integer# i = 0; i < newN; i ++) { |
| 646 | const double t = t1 + i * dt; |
| 647 | const double index = (t - t1) * mycxx . . $ `melder/melder.h:44:9`! sampleRatecxx . . $ structLongSound#sampleRate.; |
| 648 | const integercxx . . $ integer# flore = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (index); |
| 649 | const double fraction = index - flore; |
| 650 | const integercxx . . $ integer# ii = (i + silenceBefore) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 651 | for (integercxx . . $ integer# chan = 0; chan < mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels.; chan ++) { |
| 652 | resampledBuffer [ii + chan] = |
| 653 | (1.0 - fraction) * from [flore * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. + chan] + |
| 654 | fraction * from [(flore + 1) * mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels. + chan]; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | if (thycxx . . $ `melder/melder.h:45:9`! playCallbackcxx . . $ LongSoundPlay#playCallback.) |
| 659 | thycxx . . $ `melder/melder.h:45:9`! playCallbackcxx . . $ LongSoundPlay#playCallback. (cxx . . $ MelderCallback#`operator()`(6e5e9b08e48f7d7).thycxx . . $ `melder/melder.h:45:9`! playBosscxx . . $ LongSoundPlay#playBoss., 1, startTime, endTime, startTime); |
| 660 | MelderAudio_play16cxx . . $ MelderAudio_play16(4eeb2eee1b9aa526). (resampledBuffer, newSampleRate, silenceBefore + newN + silenceAfter, mycxx . . $ `melder/melder.h:44:9`! numberOfChannelscxx . . $ structLongSound#numberOfChannels., melderPlayCallbackcxx . . $ melderPlayCallback(22efc3fb69126f04)., thee); |
| 661 | } |
| 662 | //Melder_free (thy resampledBuffer); // cannot do that, because MelderAudio_play16 isn't necessarily synchronous |
| 663 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 664 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`! (thycxx . . $ `melder/melder.h:45:9`! resampledBuffer); |
| 665 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not played."); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | void LongSound_concatenatecxx . . $ LongSound_concatenate(a82c96a37173ed04). (SoundAndLongSoundListcxx . . $ SoundAndLongSoundList# me, MelderFilecxx . . $ MelderFile# file, const int audioFileType, const int numberOfBitsPerSamplePoint) { |
| 670 | try { |
| 671 | integercxx . . $ integer# sampleRate, n; // integer sampling frequencies only, because of possible rounding errors |
| 672 | integercxx . . $ integer# numberOfChannels; |
| 673 | if (mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size. < 1) |
| 674 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No Sound or LongSound objects to concatenate."); |
| 675 | /* |
| 676 | The sampling frequencies and numbers of channels must be equal for all (long)sounds. |
| 677 | */ |
| 678 | SampledXYcxx . . $ SampledXY# data = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]; |
| 679 | if (data -> classInfocxx . . $ structThing#classInfo. == classSoundcxx . . $ classSound.) { |
| 680 | Soundcxx . . $ Sound# sound = (Soundcxx . . $ Sound#) data; |
| 681 | sampleRate = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (1.0 / sound -> dxcxx . . $ structSampled#dx.); |
| 682 | numberOfChannels = sound -> nycxx . . $ structSampledXY#ny.; |
| 683 | n = sound -> nxcxx . . $ structSampled#nx.; |
| 684 | } else { |
| 685 | LongSoundcxx . . $ LongSound# longSound = (LongSoundcxx . . $ LongSound#) data; |
| 686 | sampleRate = Melder_iroundTowardsZerocxx . . $ Melder_iroundTowardsZero(a6e4a4c8b00c35a3). (longSound -> sampleRatecxx . . $ structLongSound#sampleRate.); |
| 687 | numberOfChannels = longSound -> numberOfChannelscxx . . $ structLongSound#numberOfChannels.; |
| 688 | n = longSound -> nxcxx . . $ structSampled#nx.; |
| 689 | } |
| 690 | /* |
| 691 | Check whether all the sampling frequencies and channels match. |
| 692 | */ |
| 693 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; i ++) { |
| 694 | bool sampleRatesMatch, numbersOfChannelsMatch; |
| 695 | data = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 696 | if (data -> classInfocxx . . $ structThing#classInfo. == classSoundcxx . . $ classSound.) { |
| 697 | Soundcxx . . $ Sound# sound = (Soundcxx . . $ Sound#) data; |
| 698 | sampleRatesMatch = ( Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (1.0 / sound -> dxcxx . . $ structSampled#dx.) == sampleRate ); |
| 699 | numbersOfChannelsMatch = sound -> nycxx . . $ structSampledXY#ny. == numberOfChannels; |
| 700 | n += sound -> nxcxx . . $ structSampled#nx.; |
| 701 | } else { |
| 702 | LongSoundcxx . . $ LongSound# longSound = (LongSoundcxx . . $ LongSound#) data; |
| 703 | sampleRatesMatch = ( longSound -> sampleRatecxx . . $ structLongSound#sampleRate. == sampleRate ); |
| 704 | numbersOfChannelsMatch = longSound -> numberOfChannelscxx . . $ structLongSound#numberOfChannels. == numberOfChannels; |
| 705 | n += longSound -> nxcxx . . $ structSampled#nx.; |
| 706 | } |
| 707 | if (! sampleRatesMatch) |
| 708 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sampling frequencies are not equal."); |
| 709 | if (! numbersOfChannelsMatch) |
| 710 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot mix stereo and mono."); |
| 711 | } |
| 712 | /* |
| 713 | Create output file and write header. |
| 714 | */ |
| 715 | autoMelderFilecxx . . $ autoMelderFile# mfile = MelderFile_createcxx . . $ autoMelderFile#autoMelderFile(1145552d769d7b5d). (file); |
| 716 | if (file -> filePointercxx . . $ structMelderFile#filePointer.) |
| 717 | MelderFile_writeAudioFileHeadercxx . . $ MelderFile_writeAudioFileHeader(2bed0b35f5c41b2b). (file, audioFileType, sampleRate, n, numberOfChannels, numberOfBitsPerSamplePoint); |
| 718 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; i ++) { |
| 719 | data = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 720 | if (data -> classInfocxx . . $ structThing#classInfo. == classSoundcxx . . $ classSound.) { |
| 721 | Soundcxx . . $ Sound# sound = (Soundcxx . . $ Sound#) data; |
| 722 | if (file -> filePointercxx . . $ structMelderFile#filePointer.) { |
| 723 | MelderFile_writeFloatToAudiocxx . . $ MelderFile_writeFloatToAudio(a1ad9e07d2cef856). (file, soundcxx . . $ constmatrixview#constmatrixview(eed9513d24570b3d). -> zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), |
| 724 | Melder_defaultAudioFileEncodingcxx . . $ Melder_defaultAudioFileEncoding(9b79fb6aee4c0440). (audioFileType, numberOfBitsPerSamplePoint), true); |
| 725 | } |
| 726 | } else { |
| 727 | LongSoundcxx . . $ LongSound# longSound = (LongSoundcxx . . $ LongSound#) data; |
| 728 | writePartToOpenFilecxx . . $ writePartToOpenFile(fe25f1875e30078f). (longSound, audioFileType, 1, longSound -> nxcxx . . $ structSampled#nx., file, 0, numberOfBitsPerSamplePoint); |
| 729 | } |
| 730 | } |
| 731 | MelderFile_writeAudioFileTrailercxx . . $ MelderFile_writeAudioFileTrailer(2bed0b35f5c41b2b). (file, audioFileType, sampleRate, n, numberOfChannels, numberOfBitsPerSamplePoint); |
| 732 | mfile.closecxx . . $ autoMelderFile#close(49f6e7a06ebc5aa8). (); |
| 733 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 734 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sounds not concatenated and not saved to ", file, U"."); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /* End of file LongSound.cpp */ |