Sound_extensions.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #ifndef _Sound_extensions_h_
  2. #define _Sound_extensions_h_
  3. /* Sound_extensions.h
  4. *
  5. * Copyright (C) 1993-2018 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. #include "Sound.h"
  21. #include "Pitch.h"
  22. #include "Collection.h"
  23. #include "PointProcess.h"
  24. #include "TextGrid.h"
  25. Thing_declare (Interpreter);
  26. int Sound_writeToNistAudioFile (Sound me, MelderFile file);
  27. autoSound Sound_readFromCmuAudioFile (MelderFile file);
  28. /* only 16 bit signed has been tested !! */
  29. autoSound Sound_readFromRawFile (MelderFile file, const char *format, int nBitsCoding,
  30. bool littleEndian, bool unSigned, integer skipNBytes, double samplingFrequency);
  31. /* Reads a Sound from a raw file:
  32. * fileName : name of the file
  33. * format : "integer" (default)
  34. * "float" (this implies nBitsCoding=nBitsStorage=32, see below)
  35. * nBitsCoding : number of bits used in the coding (1..16) (default = 16 )
  36. * (the storage is assumed to be a multiple of 8 bits )
  37. * littleEndian: if littleEndian != 0 then little-endian else big-endian
  38. * unSigned : if unSigned != 0 then unsigned else signed
  39. * skipNBytes : start reading after this number of bytes (skipNBytes >= 0 )
  40. */
  41. autoSound Sound_readFromDialogicADPCMFile (MelderFile file, double sampleRate);
  42. /*
  43. */
  44. void Sound_writeToRawFile (Sound me, MelderFile file, const char *format, bool littleEndian, int nBitsCoding, bool unSigned);
  45. void Sound_into_Sound (Sound me, Sound to, double startTime);
  46. /* precondition: my dx == to->dx (equal sampling times */
  47. void Sound_overwritePart (Sound me, double t1, double t2, Sound thee, double t3);
  48. /*
  49. Overwrite the part between (t1,t2) in me with samples from Sound thee,
  50. starting at t3 in thee.
  51. */
  52. void Sound_preEmphasis (Sound me, double preEmphasisFrequency);
  53. /* deEmphasis = exp(- 2 * NUMpi * deEmphasisFrequency * my dx); */
  54. /* for (i=my nx; i >=2; i-- ) my z[1][i] -= preEmphasis * my z[1][i-1]; */
  55. void Sound_deEmphasis (Sound me, double preEmphasisFrequency);
  56. /* for (i=2; i <= my nx; i++ ) my z[1][i] += deEmphasis * my z[1][i-1]; */
  57. autoSound Sound_createGaussian (double windowDuration, double samplingFrequency);
  58. autoSound Sound_createHamming (double windowDuration, double samplingFrequency);
  59. autoSound Sound_createSimpleToneComplex (double minimumTime, double maximumTime, double samplingFrequency,
  60. double firstFrequency, integer numberOfComponents, double frequencyDistance, bool scaleAmplitudes);
  61. autoSound Sound_createMistunedHarmonicComplex (double minimumTime, double maximumTime, double samplingFrequency,
  62. double firstFrequency, integer numberOfComponents, integer mistunedComponent, double mistuningFraction, bool scaleAmplitudes);
  63. autoSound Sound_createGammaTone (double minimumTime, double maximumTime, double samplingFrequency,
  64. double gamma, double frequency, double bandwidth, double initialPhase, double addition, bool scaleAmplitudes);
  65. autoSound Sound_createShepardTone (double minimumTime, double maximumTime, double samplingFrequency,
  66. double lowestFrequency, integer numberOfComponents, double frequencyChange, double amplitudeRange);
  67. autoSound Sound_createShepardToneComplex (double minimumTime, double maximumTime,
  68. double samplingFrequency, double lowestFrequency, integer numberOfComponents,
  69. double frequencyChange_st, double amplitudeRange, double octaveShiftFraction);
  70. autoSound Sound_createPattersonWightmanTone (double minimumTime, double maximumTime, double samplingFrequency,
  71. double baseFrequency, double frequencyShiftRatio, integer numberOfComponents);
  72. autoSound Sound_createPlompTone (double minimumTime, double maximumTime, double samplingFrequency,
  73. double baseFrequency, double frequencyFraction, integer m);
  74. autoSound Sound_createFromWindowFunction (double effectiveTime, double samplingFrequency, int windowType);
  75. /* 1; rect 2:hamming 3: bartlet 4: welch 5: hanning 6:gaussian */
  76. autoSound Sound_filterByGammaToneFilter4 (Sound me, double centre_frequency, double bandwidth);
  77. autoSound Sound_filterByGammaToneFilter (Sound me, double centre_frequency, double bandwidth, double gamma, double initialPhase);
  78. void Sounds_multiply (Sound me, Sound thee);
  79. /* precondition: my nx = thy nx */
  80. double Sound_correlateParts (Sound me, double t1, double t2, double duration);
  81. /*
  82. Correlate part (t1, t1+duration) with (t2, t2+duration)
  83. */
  84. void Sound_localMean (Sound me, double fromTime, double toTime, double *mean);
  85. void Sound_localPeak (Sound me, double fromTime, double toTime, double ref, double *peak);
  86. autoSound Sound_localAverage (Sound me, double averaginginterval, int windowType);
  87. /* y[n] = sum(i=-n, i=n, x[n+i])/(2*n+1) */
  88. double Sound_power (Sound me);
  89. void Sound_scale_dB (Sound me, double level_dB);
  90. /*
  91. Scales the amplitude of a Sound to a certain dB level.
  92. The reference value is an amplitude of 1.
  93. All amplitudes are multiplied by a scale factor which is
  94. 10^(level_dB/10) / extremum,
  95. where extremum is the maximum of the absolute values the signal values.
  96. */
  97. void Sound_fade (Sound me, int channel, double t, double fadeTime, int inout, bool fadeGlobal);
  98. /* if inout <= 0 fade in with (1-cos)/2 else fade out with (1+cos)/2
  99. channel = 0 (all), 1 (left), 2 (right).
  100. */
  101. #define FROM_LEFT_TO_RIGHT 0
  102. #define FROM_RIGHT_TO_LEFT 1
  103. #define FROM_BOTTOM_TO_TOP 2
  104. #define FROM_TOP_TO_BOTTOM 3
  105. void Sound_draw_btlr (Sound me, Graphics g, double tmin, double tmax, double amin, double amax, int direction, bool garnish);
  106. /* direction is one of the macros's FROM_LEFT_TO_RIGHT... */
  107. void Sound_drawWhere (Sound me, Graphics g, double tmin, double tmax, double minimum, double maximum,
  108. bool garnish, conststring32 method, integer numberOfBisections, conststring32 formula, Interpreter interpreter);
  109. void Sound_paintWhere (Sound me, Graphics g, Graphics_Colour colour, double tmin, double tmax,
  110. double minimum, double maximum, double level, bool garnish,
  111. integer numberOfBisections, conststring32 formula, Interpreter interpreter
  112. );
  113. void Sounds_paintEnclosed (Sound me, Sound thee, Graphics g, Graphics_Colour colour, double tmin, double tmax,
  114. double minimum, double maximum, bool garnish);
  115. autoSound Sound_changeGender (Sound me, double pitchMin, double pitchMax, double pitchRatio, double formantFrequenciesRatio, double durationRatio);
  116. autoSound Sound_Pitch_changeGender (Sound me, Pitch him, double pitchRatio, double formantFrequenciesRatio, double durationRatio);
  117. autoSound Sound_changeGender_old (Sound me, double fmin, double fmax, double formantRatio, double new_pitch, double pitchRangeFactor, double durationFactor);
  118. autoSound Sound_Pitch_changeGender_old (Sound me, Pitch him, double formantRatio, double new_pitch, double pitchRangeFactor, double durationFactor);
  119. autoPointProcess Sound_to_PointProcess_getJumps (Sound me, double minimumJump, double dt);
  120. /*
  121. Marks jumps in the signal where the amplitude changes more than 'minimumJump'
  122. within time dt
  123. */
  124. autoSound Sound_changeSpeaker (Sound me, double pitchMin, double pitchMax,
  125. double formantMultiplier, // > 0
  126. double pitchMultiplier, // > 0
  127. double pitchRangeMultiplier, // any number
  128. double durationMultiplier // > 0
  129. );
  130. autoSound Sound_Pitch_changeSpeaker (Sound me, Pitch him,
  131. double formantMultiplier, // > 0
  132. double pitchMultiplier, // > 0
  133. double pitchRangeMultiplier, // any number
  134. double durationMultiplier // > 0
  135. );
  136. /* Outphased */
  137. autoSound Sound_changeGender_old (Sound me, double fmin, double fmax, double formantRatio,
  138. double new_pitch, double pitchRangeFactor, double durationFactor);
  139. autoTextGrid Sound_to_TextGrid_detectSilences (Sound me, double minPitch, double timeStep,
  140. double silenceThreshold, double minSilenceDuration, double minSoundingDuration,
  141. conststring32 silentLabel, conststring32 soundingLabel);
  142. void Sound_getStartAndEndTimesOfSounding (Sound me, double minPitch, double timeStep,
  143. double silenceThreshold, double minSilenceDuration, double minSoundingDuration, double *t1, double *t2);
  144. autoSound Sound_IntervalTier_cutPartsMatchingLabel (Sound me, IntervalTier thee, conststring32 match);
  145. /* Cut intervals that match the label from the sound. The starting time of the new sound is
  146. * (1) my xmin if the first interval is not matching
  147. * (2) the end time of the first interval if matching
  148. */
  149. autoSound Sound_trimSilencesAtStartAndEnd (Sound me, double trimDuration, double minPitch, double timeStep, double silenceThreshold,
  150. double minSilenceDuration, double minSoundingDuration, double *startTimeOfSounding, double *endTimeOfSounding);
  151. autoSound Sound_trimSilences (Sound me, double trimDuration, bool onlyAtStartAndEnd, double minPitch, double timeStep,
  152. double silenceThreshold, double minSilenceDuration, double minSoundingDuration, autoTextGrid *tg, conststring32 trimLabel);
  153. autoSound Sound_copyChannelRanges (Sound me, conststring32 ranges);
  154. autoSound Sound_removeNoise (Sound me, double noiseStart, double noiseEnd, double windowLength, double minBandFilterFrequency, double maxBandFilterFrequency, double smoothing, int method);
  155. void Sound_playAsFrequencyShifted (Sound me, double shiftBy, double newSamplingFrequency, integer precision);
  156. #endif /* _Sound_extensions_h_ */