| 1 | /* manual_Sampling.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2005,2007,2011,2014-2017,2021-2023,2025 Paul Boersma |
| 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 "ManPagesM.h"cxx . . $ `<file>/sys/ManPagesM.h`/ |
| 20 | |
| 21 | #include "Sound.h"cxx . . $ `<file>/fon/Sound.h`/ |
| 22 | |
| 23 | void manual_Sampling_initcxx . . $ manual_Sampling_init(e57bd08652fa63a5). (ManPagescxx . . $ ManPages# me); |
| 24 | void manual_Sampling_initcxx . . $ manual_Sampling_init(e57bd08652fa63a5). (ManPagescxx . . $ ManPages# me) { |
| 25 | |
| 26 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get sampling period", U"ppgb", 20221202) |
| 27 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a @Sound object.") |
| 28 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the @@sampling period@ in seconds.") |
| 29 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Usage") |
| 30 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"You will not often choose this command with the mouse, " |
| 31 | "since the sampling period is included in the information that you get " |
| 32 | "by clicking the #Info button. This command is probably more useful in a Praat script:") |
| 33 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"selectObject: \"Sound hello\"") |
| 34 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"samplingPeriod = Get sampling period") |
| 35 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 36 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"With @Inspect, you can see how the sampling period is stored in a #Sound object: it is the #dx attribute.") |
| 37 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 38 | |
| 39 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get sampling frequency", U"ppgb", 20221202) |
| 40 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a @Sound object.") |
| 41 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the @@sampling frequency@ in hertz.") |
| 42 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Usage") |
| 43 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"You will not often choose this command with the mouse, " |
| 44 | "since the sampling frequency is included in the information that you get " |
| 45 | "by clicking the #Info button. This command is probably more useful in a Praat script:") |
| 46 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"selectObject: \"Sound hello\"") |
| 47 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"samplingFrequency = Get sampling frequency") |
| 48 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Algorithm") |
| 49 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The sampling frequency is defined as 1 / (\\De%t), where \\De%t is the @@sampling period@. " |
| 50 | "See @@Get sampling period@.") |
| 51 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 52 | |
| 53 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get time from sample number...", U"ppgb", 20221202) |
| 54 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 55 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the time (in seconds) associated with the sample number that you specify.") |
| 56 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Setting") |
| 57 | TERMcxx . . $ `sys/ManPagesM.h:42:9`! (U"##Sample number") |
| 58 | DEFINITIONcxx . . $ `sys/ManPagesM.h:46:9`! (U"the sample number whose time is sought.") |
| 59 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Algorithm") |
| 60 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"the result is") |
| 61 | EQUATIONcxx . . $ `sys/ManPagesM.h:57:9`! (U"%t__1_ + (%sampleNumber - 1) \\.c \\De%t") |
| 62 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"where %t__1_ is the time associated with the first sample, and \\De%t is the sampling period.") |
| 63 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 64 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select a Sound or LongSound and click @Inspect, " |
| 65 | "you can see how the relation between sample numbers and times is stored in the object: " |
| 66 | "%t__1_ is the #x1 attribute, and \\De%t is the #dx attribute.") |
| 67 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 68 | |
| 69 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get sample number from time...", U"ppgb", 20221202) |
| 70 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 71 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the sample number belonging to the time that you specify. " |
| 72 | "The result is presented as a real number.") |
| 73 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Setting") |
| 74 | TERMcxx . . $ `sys/ManPagesM.h:42:9`! (U"##Time (s)") |
| 75 | DEFINITIONcxx . . $ `sys/ManPagesM.h:46:9`! (U"the time (in seconds) for which you want to know the sample number.") |
| 76 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Example") |
| 77 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If the sound has a sampling frequency of 10 kHz, the sample number associated with a time of 0.1 seconds " |
| 78 | "will usually be 1000.5.") |
| 79 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Scripting") |
| 80 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"You can use this command to put the nearest sample number into a script variable:") |
| 81 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"selectObject: \"Sound hallo\"") |
| 82 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"sampleNumber = Get sample number from time... 0.1") |
| 83 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"nearestSample = round (sampleNumber)") |
| 84 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"In this case, the value will not be written into the Info window. To round down or up, use") |
| 85 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"leftSample = floor (sampleNumber)") |
| 86 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"rightSample = ceiling (sampleNumber)") |
| 87 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Algorithm") |
| 88 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"the result is") |
| 89 | EQUATIONcxx . . $ `sys/ManPagesM.h:57:9`! (U"1 + (%time \\-- %t__1_) / \\De%t") |
| 90 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"where %t__1_ is the time associated with the first sample, and \\De%t is the sampling period.") |
| 91 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 92 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select a Sound or LongSound and click @Inspect, " |
| 93 | "you can see how the relation between sample numbers and times is stored in the object: " |
| 94 | "%t__1_ is the #x1 attribute, and \\De%t is the #dx attribute.") |
| 95 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 96 | |
| 97 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get number of samples", U"ppgb", 20221202) |
| 98 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 99 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the total number of time samples in this object.") |
| 100 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Example") |
| 101 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If the sampling frequency is 44100 hertz, a recording with a duration of 60 seconds " |
| 102 | "will contain 2,646,000 samples.") |
| 103 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 104 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select a Sound or LongSound and click @Inspect, " |
| 105 | "you can see how the number of samples is stored in the object: it is the #nx attribute.") |
| 106 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 107 | |
| 108 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get time from frame number...", U"ppgb", 20221202) |
| 109 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a sound-analysis object that is a function of time " |
| 110 | "and that is evenly sampled in time (@Pitch, @Formant, @Intensity, @Harmonicity).") |
| 111 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the time associated with the frame number that you specify.") |
| 112 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Setting") |
| 113 | TERMcxx . . $ `sys/ManPagesM.h:42:9`! (U"##Frame number") |
| 114 | DEFINITIONcxx . . $ `sys/ManPagesM.h:46:9`! (U"the frame number whose time is sought.") |
| 115 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Algorithm") |
| 116 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"the result is") |
| 117 | EQUATIONcxx . . $ `sys/ManPagesM.h:57:9`! (U"%t__1_ + (%frameNumber - 1) \\.c \\De%t") |
| 118 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"where %t__1_ is the time associated with the centre of the first frame, and \\De%t is the time step.") |
| 119 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 120 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select one of the above objects and click @Inspect, " |
| 121 | "you can see how the relation between frame numbers and times is stored in the object: " |
| 122 | "%t__1_ is the #x1 attribute, and \\De%t is the #dx attribute.") |
| 123 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 124 | |
| 125 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get frame number from time...", U"ppgb", 20221202) // 2025 |
| 126 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a sound-analysis object that is a function of time " |
| 127 | "and that is evenly sampled in time (@Pitch, @Formant, @Intensity, @Harmonicity).") |
| 128 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the frame number belonging to the time that you specify. " |
| 129 | "The result is presented as a real number.") |
| 130 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Setting") |
| 131 | TERMcxx . . $ `sys/ManPagesM.h:42:9`! (U"##Time (s)") |
| 132 | DEFINITIONcxx . . $ `sys/ManPagesM.h:46:9`! (U"the time (in seconds) for which you want to know the frame number.") |
| 133 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Example") |
| 134 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If the Pitch object has a time step of 10 ms, and the first frame is centred around 18 ms, " |
| 135 | "the frame number associated with a time of 0.1 seconds is 9.2.") |
| 136 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Scripting") |
| 137 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"You can use this command to put the nearest frame centre into a script variable:") |
| 138 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"selectObject: \"Pitch hallo\"") |
| 139 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"frame = Get frame number from time... 0.1") |
| 140 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"nearestFrame = round (frame)") |
| 141 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"In this case, the value will not be written into the Info window. To round down or up, use") |
| 142 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"leftFrame = floor (frame)") |
| 143 | CODEcxx . . $ `sys/ManPagesM.h:50:9`! (U"rightFrame = ceiling (frame)") |
| 144 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Algorithm") |
| 145 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"the result is") |
| 146 | EQUATIONcxx . . $ `sys/ManPagesM.h:57:9`! (U"1 + (%time \\-- %t__1_) / \\De%t") |
| 147 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"where %t__1_ is the time associated with the centre of the first frame, " |
| 148 | "and \\De%t is the time step.") |
| 149 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 150 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select one of the above objects and click @Inspect, " |
| 151 | "you can see how the relation between frame numbers and times is stored in the object: " |
| 152 | "%t__1_ is the #x1 attribute, and \\De%t is the #dx attribute.") |
| 153 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 154 | |
| 155 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get time step", U"ppgb", 20221202) |
| 156 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a sound-analysis object that is a function of time " |
| 157 | "and that is evenly sampled in time (@Pitch, @Formant, @Intensity, @Harmonicity).") |
| 158 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the time difference between consecutive frames, e.g. " |
| 159 | "the time difference between consecutive formant circles in the sound editor window.") |
| 160 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 161 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select one of the above objects and click @Inspect, " |
| 162 | "you can see how the time step is stored in the object: it is the #dx attribute.") |
| 163 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 164 | |
| 165 | MAN_BEGINcxx . . $ `sys/ManPagesM.h:33:9`! (U"Get number of frames", U"ppgb", 20221202) |
| 166 | INTROcxx . . $ `sys/ManPagesM.h:35:9`! (U"A command that becomes available in the @@Query submenu@ if you select a sound-analysis object that is a function of time " |
| 167 | "and that is evenly sampled in time (@Pitch, @Formant, @Intensity, @Harmonicity).") |
| 168 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"The Info window will tell you the total number of time frames in the object.") |
| 169 | ENTRYcxx . . $ `sys/ManPagesM.h:36:9`! (U"Details for hackers") |
| 170 | NORMALcxx . . $ `sys/ManPagesM.h:37:9`! (U"If you select one of the above objects and click @Inspect, " |
| 171 | "you can see how the number of frames is stored in the object: it is the #nx attribute.") |
| 172 | MAN_ENDcxx . . $ `sys/ManPagesM.h:61:9`! |
| 173 | |
| 174 | } |
| 175 | |
| 176 | /* End of file manual_Sampling.cpp */ |