| 1 | /* praat_sensors_init.cpp |
| 2 | * |
| 3 | * Copyright (C) 2023 David Weenink |
| 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 2 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 | #include <string.h> |
| 20 | #include "Electroglottogram.h" |
| 21 | |
| 22 | #include "EMA.h" |
| 23 | #include "EMArawData.h" |
| 24 | #include "praat_sensors_init.h" |
| 25 | #include "Sound_extensions.h" |
| 26 | |
| 27 | static autoDaata CarstensEMA50xV3PosFileRecognizer (integer nread, const char *header, MelderFile file) { |
| 28 | if (nread > 69 && strnequ (header, "AG50xDATA_V00", 13) && |
| 29 | (strstr (header, "NumberOfChannels=") != nullptr) && |
| 30 | (strstr (header, "SamplingFrequencyHz=") != nullptr) && |
| 31 | (strstr (header, "Calf_Channel_0") == nullptr)) |
| 32 | return EMA_readFromCarstensEMA50xPosFile (file); |
| 33 | else |
| 34 | return autoDaata (); |
| 35 | } |
| 36 | |
| 37 | static autoDaata CarstensEMA50xV3AmpFileRecognizer (integer nread, const char *header, MelderFile file) { |
| 38 | if (nread > 69 && strnequ (header, "AG50xDATA_V00", 13) && |
| 39 | (strstr (header, "NumberOfChannels=") != nullptr) && |
| 40 | (strstr (header, "SamplingFrequencyHz=") != nullptr) && |
| 41 | (strstr (header, "Calf_Channel_0") != nullptr)) |
| 42 | return EMArawData_readFromCarstensEMA50xAmpFile (file); |
| 43 | else |
| 44 | return autoDaata (); |
| 45 | } |
| 46 | |
| 47 | /******************** Electroglottogram ********************************************/ |
| 48 | |
| 49 | FORM (CONVERT_EACH_TO_ONE__Electroglottogram_highPassFilter, U"Electroglottogram: High-pass filter", U"Electroglottogram: High-pass filter...") { |
| 50 | REAL (fromFrequency, U"From frequency (Hz)", U"100.0") |
| 51 | POSITIVE (smoothing, U"Smoothing (Hz)", U"100.0") |
| 52 | OK |
| 53 | DO |
| 54 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 55 | autoElectroglottogram result = Electroglottogram_highPassFilter (me, fromFrequency, smoothing); |
| 56 | CONVERT_EACH_TO_ONE_END (my name.get(), U"_filtered") |
| 57 | } |
| 58 | |
| 59 | FORM (CONVERT_EACH_TO_ONE__Electroglottogram_to_TextGrid_closedGlottis, U"Electroglottogram: To TextGrid (closed glottis)", |
| 60 | U"Electroglottogram: To TextGrid (closed glottis)...") { |
| 61 | POSITIVE (pitchFloor, U"Pitch floor (Hz)", U"75.0") |
| 62 | POSITIVE (pitchCeiling, U"Pitch ceiling (Hz)", U"500.0") |
| 63 | POSITIVE (closingThreshold, U"Closing threshold", U"0.30") |
| 64 | POSITIVE (peakThresholdFraction, U"Peak threshold (0-1)", U"0.05") |
| 65 | OK |
| 66 | DO |
| 67 | Melder_require (closingThreshold < 1.0, |
| 68 | U"The closing threshold should be smaller than 1."); |
| 69 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 70 | autoTextGrid result = Electroglottogram_to_TextGrid_closedGlottis (me, pitchFloor, pitchCeiling, |
| 71 | closingThreshold, peakThresholdFraction |
| 72 | ); |
| 73 | CONVERT_EACH_TO_ONE_END (my name.get()) |
| 74 | } |
| 75 | |
| 76 | FORM (CONVERT_EACH_TO_ONE__Electroglottogram_to_AmplitudeTier_levels, U"Electroglottogram: To AmplitudeTier (levels)", U"") { |
| 77 | POSITIVE (pitchFloor, U"Pitch floor (Hz)", U"75.0") |
| 78 | POSITIVE (pitchCeiling, U"Pitch ceiling (Hz)", U"500.0") |
| 79 | POSITIVE (closingThreshold, U"Closing threshold", U"0.30") |
| 80 | BOOLEAN (wantPeaks, U"Peaks", 0) |
| 81 | BOOLEAN (wantValleys, U"Valleys", 0) |
| 82 | OK |
| 83 | DO |
| 84 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 85 | autoAmplitudeTier peaks, valleys; |
| 86 | autoAmplitudeTier result = Electroglottogram_to_AmplitudeTier_levels (me, pitchFloor, pitchCeiling, |
| 87 | closingThreshold, & peaks, & valleys |
| 88 | ); |
| 89 | if (wantPeaks) |
| 90 | praat_new (peaks.move(), my name.get(), U"_peaks"); |
| 91 | if (wantValleys) |
| 92 | praat_new (valleys.move(), my name.get(), U"_valleys"); |
| 93 | CONVERT_EACH_TO_ONE_END (my name.get()) |
| 94 | } |
| 95 | |
| 96 | FORM (CONVERT_EACH_TO_ONE__Electroglottogram_derivative, U"Electroglottogram: Derivative", U"Electroglottogram: Derivative...") { |
| 97 | POSITIVE (lowPassFrequency, U"Low-pass frequency (Hz)", U"5000.0") |
| 98 | POSITIVE (smoothing, U"Smoothing (Hz)", U"100.0") |
| 99 | REAL (newAbsolutePeak, U"New absolute peak", U"0.0 (= don't scale)") |
| 100 | OK |
| 101 | DO |
| 102 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 103 | autoSound result = Sound_derivative (me, lowPassFrequency, smoothing, newAbsolutePeak); |
| 104 | CONVERT_EACH_TO_ONE_END (my name.get(), U"_derivative") |
| 105 | } |
| 106 | |
| 107 | FORM (CONVERT_EACH_TO_ONE__Electroglottogram_firstCentralDifference, U"Electroglottogram: First central difference", U"Electroglottogram: First central difference...") { |
| 108 | REAL (scalePeak, U"New absolute peak", U"0.0 (= don't scale)") |
| 109 | OK |
| 110 | DO |
| 111 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 112 | autoSound result = Electroglottogram_firstCentralDifference (me, scalePeak); |
| 113 | CONVERT_EACH_TO_ONE_END (my name.get(), U"_cdiff") |
| 114 | } |
| 115 | |
| 116 | DIRECT (CONVERT_EACH_TO_ONE__Electroglottogram_to_Sound) { |
| 117 | CONVERT_EACH_TO_ONE (Electroglottogram) |
| 118 | autoSound result = Electroglottogram_to_Sound (me); |
| 119 | CONVERT_EACH_TO_ONE_END (my name.get()) |
| 120 | } |
| 121 | |
| 122 | FORM (CONVERT_EACH_TO_ONE__Sound_extractElectroglottogram, U"Sound: Extract Electroglottogram", U"Sound: Extract Electroglottogram...") { |
| 123 | NATURAL (channelNumber, U"Channel number", U"1") |
| 124 | BOOLEAN (invert, U"Invert", 0) |
| 125 | OK |
| 126 | DO |
| 127 | CONVERT_EACH_TO_ONE (Sound) |
| 128 | autoElectroglottogram result = Sound_extractElectroglottogram (me, channelNumber, invert); |
| 129 | CONVERT_EACH_TO_ONE_END (my name.get()) |
| 130 | } |
| 131 | |
| 132 | void praat_uvafon_sensors_init () { |
| 133 | Thing_recognizeClassesByName (classElectroglottogram, classEMA, classEMArawData); |
| 134 | |
| 135 | Data_recognizeFileType (CarstensEMA50xV3PosFileRecognizer); |
| 136 | Data_recognizeFileType (CarstensEMA50xV3AmpFileRecognizer); |
| 137 | |
| 138 | praat_addAction1 (classElectroglottogram, 0, U"High-pass filter...", nullptr, 0, |
| 139 | CONVERT_EACH_TO_ONE__Electroglottogram_highPassFilter); |
| 140 | praat_addAction1 (classElectroglottogram, 0, U"To TextGrid (closed glottis)... || Get closed glottis intervals...", nullptr, 0, |
| 141 | CONVERT_EACH_TO_ONE__Electroglottogram_to_TextGrid_closedGlottis); |
| 142 | praat_addAction1 (classElectroglottogram, 0, U"To AmplitudeTier (levels)...", nullptr, 0, |
| 143 | CONVERT_EACH_TO_ONE__Electroglottogram_to_AmplitudeTier_levels); |
| 144 | praat_addAction1 (classElectroglottogram, 0, U"Derivative...", nullptr, 0, |
| 145 | CONVERT_EACH_TO_ONE__Electroglottogram_derivative); |
| 146 | praat_addAction1 (classElectroglottogram, 0, U"First central difference...", nullptr, 0, |
| 147 | CONVERT_EACH_TO_ONE__Electroglottogram_firstCentralDifference); |
| 148 | praat_addAction1 (classElectroglottogram, 0, U"To Sound", nullptr, 0, |
| 149 | CONVERT_EACH_TO_ONE__Electroglottogram_to_Sound); |
| 150 | |
| 151 | praat_addAction1 (classSound, 0, U"Extract Electroglottogram...", U"Extract part for overlap...", 1, |
| 152 | CONVERT_EACH_TO_ONE__Sound_extractElectroglottogram); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | /* End of file praat_sensors_init.cpp */ |
| 157 |