| 1 |
#ifndef _Sound_extensions_h_ |
| 2 |
#define _Sound_extensions_h_ |
| 3 |
/* Sound_extensions.h |
| 4 |
* |
| 5 |
* Copyright (C) 1993-2022 David Weenink |
| 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. See the GNU |
| 15 |
* 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 "Pitch.h" |
| 23 |
#include "Collection.h" |
| 24 |
#include "PointProcess.h" |
| 25 |
#include "TextGrid.h" |
| 26 |
#include "Sound_extensions_enums.h" |
| 27 |
|
| 28 |
Thing_declare (Interpreter); |
| 29 |
|
| 30 |
int Sound_writeToNistAudioFile (Sound me, MelderFile file); |
| 31 |
|
| 32 |
void Sound_saveAsMP3File_VBR (Sound me, MelderFile file, double inverseQuality); |
| 33 |
/* |
| 34 |
0 <= inverseQuality < 10 |
| 35 |
0 is highest quality, 9.99 is lowest quality |
| 36 |
*/ |
| 37 |
|
| 38 |
autoSound Sound_readFromCmuAudioFile (MelderFile file); |
| 39 |
|
| 40 |
/* only 16 bit signed has been tested !! */ |
| 41 |
autoSound Sound_readFromRawFile (MelderFile file, const char *format, int nBitsCoding, |
| 42 |
bool littleEndian, bool unSigned, integer skipNBytes, double samplingFrequency); |
| 43 |
/* Reads a Sound from a raw file: |
| 44 |
* fileName : name of the file |
| 45 |
* format : "integer" (default) |
| 46 |
* "float" (this implies nBitsCoding=nBitsStorage=32, see below) |
| 47 |
* nBitsCoding : number of bits used in the coding (1..16) (default = 16 ) |
| 48 |
* (the storage is assumed to be a multiple of 8 bits ) |
| 49 |
* littleEndian: if littleEndian != 0 then little-endian else big-endian |
| 50 |
* unSigned : if unSigned != 0 then unsigned else signed |
| 51 |
* skipNBytes : start reading after this number of bytes (skipNBytes >= 0 ) |
| 52 |
*/ |
| 53 |
|
| 54 |
autoSound Sound_readFromDialogicADPCMFile (MelderFile file, double sampleRate); |
| 55 |
/* |
| 56 |
*/ |
| 57 |
|
| 58 |
autoSound Sound_readFromOggVorbisFile (MelderFile file); |
| 59 |
autoSound Sound_readFromOggOpusFile (MelderFile file); |
| 60 |
|
| 61 |
void Sound_into_Sound (Sound me, Sound to, double startTime); |
| 62 |
/* precondition: my dx == to->dx (equal sampling times */ |
| 63 |
|
| 64 |
void Sound_overwritePart (Sound me, double t1, double t2, Sound thee, double t3); |
| 65 |
/* |
| 66 |
Overwrite the part between (t1,t2) in me with samples from Sound thee, |
| 67 |
starting at t3 in thee. |
| 68 |
*/ |
| 69 |
|
| 70 |
autoSound Sound_derivative (Sound me, double lowPassFrequency, double smoothing, double peakAmplitude); |
| 71 |
/* |
| 72 |
The real derivative |
| 73 |
*/ |
| 74 |
|
| 75 |
autoSound Sound_createGaussian (double windowDuration, double samplingFrequency); |
| 76 |
|
| 77 |
autoSound Sound_createHamming (double windowDuration, double samplingFrequency); |
| 78 |
|
| 79 |
autoSound Sound_createSimpleToneComplex (double minimumTime, double maximumTime, double samplingFrequency, |
| 80 |
double firstFrequency, integer numberOfComponents, double frequencyDistance, bool scaleAmplitudes); |
| 81 |
|
| 82 |
autoSound Sound_createMistunedHarmonicComplex (double minimumTime, double maximumTime, double samplingFrequency, |
| 83 |
double firstFrequency, integer numberOfComponents, integer mistunedComponent, double mistuningFraction, bool scaleAmplitudes); |
| 84 |
|
| 85 |
autoSound Sound_createGammaTone (double minimumTime, double maximumTime, double samplingFrequency, |
| 86 |
double gamma, double frequency, double bandwidth, double initialPhase, double addition, bool scaleAmplitudes); |
| 87 |
|
| 88 |
autoSound Sound_createShepardTone (double minimumTime, double maximumTime, double samplingFrequency, |
| 89 |
double lowestFrequency, integer numberOfComponents, double frequencyChange, double amplitudeRange); |
| 90 |
|
| 91 |
autoSound Sound_createShepardToneComplex (double minimumTime, double maximumTime, |
| 92 |
double samplingFrequency, double lowestFrequency, integer numberOfComponents, |
| 93 |
double frequencyChange_st, double amplitudeRange, double octaveShiftFraction); |
| 94 |
|
| 95 |
autoSound Sound_createPattersonWightmanTone (double minimumTime, double maximumTime, double samplingFrequency, |
| 96 |
double baseFrequency, double frequencyShiftRatio, integer numberOfComponents); |
| 97 |
|
| 98 |
autoSound Sound_createPlompTone (double minimumTime, double maximumTime, double samplingFrequency, |
| 99 |
double baseFrequency, double frequencyFraction, integer m); |
| 100 |
|
| 101 |
autoSound Sound_createFromWindowFunction (double effectiveTime, double samplingFrequency, int windowType); |
| 102 |
/* 1; rect 2:hamming 3: bartlet 4: welch 5: hanning 6:gaussian */ |
| 103 |
|
| 104 |
autoSound Sound_filterByGammaToneFilter4 (Sound me, double centre_frequency, double bandwidth); |
| 105 |
|
| 106 |
autoSound Sound_filterByGammaToneFilter (Sound me, double centre_frequency, double bandwidth, double gamma, double initialPhase); |
| 107 |
|
| 108 |
void Sounds_multiply (Sound me, Sound thee); |
| 109 |
/* precondition: my nx == thy nx */ |
| 110 |
|
| 111 |
double Sound_correlateParts (Sound me, double t1, double t2, double duration); |
| 112 |
/* |
| 113 |
Correlate part (t1, t1+duration) with (t2, t2+duration) |
| 114 |
*/ |
| 115 |
|
| 116 |
double Sound_localPeak (Sound me, double fromTime, double toTime, double reference); |
| 117 |
|
| 118 |
autoSound Sound_localAverage (Sound me, double averaginginterval, int windowType); |
| 119 |
/* y [n] = sum(i=-n, i=n, x [n+i]) / (2*n+1) */ |
| 120 |
|
| 121 |
double Sound_power (Sound me); |
| 122 |
|
| 123 |
void Sound_scale_dB (Sound me, double level_dB); |
| 124 |
/* |
| 125 |
Scales the amplitude of a Sound to a certain dB level. |
| 126 |
The reference value is an amplitude of 1. |
| 127 |
All amplitudes are multiplied by a scale factor which is |
| 128 |
10^(level_dB/10) / extremum, |
| 129 |
where extremum is the maximum of the absolute values the signal values. |
| 130 |
*/ |
| 131 |
|
| 132 |
void Sound_fade (Sound me, int channel, double t, double fadeTime, bool fadeOut, bool fadeGlobal); |
| 133 |
/* if !fadeOut fade in with (1-cos)/2 else fade out with (1+cos)/2 |
| 134 |
channel = 0 (all). |
| 135 |
*/ |
| 136 |
|
| 137 |
void Sound_draw_btlr (Sound me, Graphics g, double tmin, double tmax, double amin, double amax, kSoundDrawingDirection drawingDirection, bool garnish); |
| 138 |
/* direction is one of the macros's FROM_LEFT_TO_RIGHT... */ |
| 139 |
|
| 140 |
void Sound_drawWhere (Sound me, Graphics g, double tmin, double tmax, double minimum, double maximum, |
| 141 |
bool garnish, conststring32 method, integer numberOfBisections, conststring32 formula, Interpreter interpreter); |
| 142 |
|
| 143 |
void Sound_paintWhere (Sound me, Graphics g, MelderColour colour, double tmin, double tmax, |
| 144 |
double minimum, double maximum, double level, bool garnish, |
| 145 |
integer numberOfBisections, conststring32 formula, Interpreter interpreter |
| 146 |
); |
| 147 |
|
| 148 |
void Sounds_paintEnclosed (Sound me, Sound thee, Graphics g, MelderColour colour, double tmin, double tmax, |
| 149 |
double minimum, double maximum, bool garnish); |
| 150 |
|
| 151 |
autoSound Sound_changeGender (Sound me, double pitchMin, double pitchMax, double pitchRatio, double formantFrequenciesRatio, double durationRatio); |
| 152 |
|
| 153 |
autoSound Sound_Pitch_changeGender (Sound me, Pitch him, double pitchRatio, double formantFrequenciesRatio, double durationRatio); |
| 154 |
|
| 155 |
autoSound Sound_changeGender_old (Sound me, double fmin, double fmax, double formantRatio, double new_pitch, double pitchRangeFactor, double durationFactor); |
| 156 |
|
| 157 |
autoSound Sound_Pitch_changeGender_old (Sound me, Pitch him, double formantRatio, double new_pitch, double pitchRangeFactor, double durationFactor); |
| 158 |
|
| 159 |
autoPointProcess Sound_to_PointProcess_getJumps (Sound me, integer channel, double minimumJump, double maximumDuration); |
| 160 |
/* |
| 161 |
Marks jumps in the signal where the amplitude changes more than 'minimumJump' |
| 162 |
within a time interval of maximumDuration |
| 163 |
*/ |
| 164 |
|
| 165 |
autoSound Sound_changeSpeaker (Sound me, double pitchMin, double pitchMax, |
| 166 |
double formantMultiplier, // > 0 |
| 167 |
double pitchMultiplier, // > 0 |
| 168 |
double pitchRangeMultiplier, // any number |
| 169 |
double durationMultiplier // > 0 |
| 170 |
); |
| 171 |
|
| 172 |
autoSound Sound_Pitch_changeSpeaker (Sound me, Pitch him, |
| 173 |
double formantMultiplier, // > 0 |
| 174 |
double pitchMultiplier, // > 0 |
| 175 |
double pitchRangeMultiplier, // any number |
| 176 |
double durationMultiplier // > 0 |
| 177 |
); |
| 178 |
|
| 179 |
/* Outphased */ |
| 180 |
autoSound Sound_changeGender_old (Sound me, double fmin, double fmax, double formantRatio, |
| 181 |
double new_pitch, double pitchRangeFactor, double durationFactor); |
| 182 |
|
| 183 |
void Sound_getStartAndEndTimesOfSounding (Sound me, double minPitch, double timeStep, |
| 184 |
double silenceThreshold, double minSilenceDuration, double minSoundingDuration, double *out_t1, double *out_t2); |
| 185 |
|
| 186 |
autoSound Sound_IntervalTier_cutPartsMatchingLabel (Sound me, IntervalTier thee, conststring32 match); |
| 187 |
/* Cut intervals that match the label from the sound. The starting time of the new sound is |
| 188 |
* (1) my xmin if the first interval is not matching |
| 189 |
* (2) the end time of the first interval if matching |
| 190 |
*/ |
| 191 |
|
| 192 |
autoSound Sound_trimSilencesAtStartAndEnd (Sound me, double trimDuration, double minPitch, double timeStep, double silenceThreshold, |
| 193 |
double minSilenceDuration, double minSoundingDuration, double *startTimeOfSounding, double *endTimeOfSounding); |
| 194 |
|
| 195 |
autoSound Sound_trimSilences (Sound me, double trimDuration, bool onlyAtStartAndEnd, double minPitch, double timeStep, |
| 196 |
double silenceThreshold, double minSilenceDuration, double minSoundingDuration, autoTextGrid *tg, conststring32 trimLabel); |
| 197 |
|
| 198 |
autoSound Sound_removeNoise (Sound me, double noiseStart, double noiseEnd, double windowLength, double minBandFilterFrequency, double maxBandFilterFrequency, double smoothing, kSoundNoiseReductionMethod method); |
| 199 |
|
| 200 |
autoSound Sound_reduceNoise (Sound me, double noiseStart, double noiseEnd, double windowLength, double minBandFilterFrequency, double maxBandFilterFrequency, double smoothing, double noiseReduction_dB, kSoundNoiseReductionMethod method); |
| 201 |
|
| 202 |
void Sound_playAsFrequencyShifted (Sound me, double shiftBy, double newSamplingFrequency, integer precision); |
| 203 |
|
| 204 |
/**** the following functions belongs to a numeric library. However there is an unwanted dependency on fon/Sound_enums.h */ |
| 205 |
|
| 206 |
void windowShape_into_VEC (kSound_windowShape windowShape, VEC inout_window); |
| 207 |
|
| 208 |
autoSound Sound_resampleAndOrPreemphasize (constSound me, double maximumFrequency, integer depth, double preEmphasisFrequency); |
| 209 |
|
| 210 |
#endif /* _Sound_extensions_h_ */ |