| 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" |
| 20 |
|
| 21 |
#include "Sound.h" |
| 22 |
|
| 23 |
void manual_Sampling_init (ManPages me); |
| 24 |
void manual_Sampling_init (ManPages me) { |
| 25 |
|
| 26 |
MAN_BEGIN (U"Get sampling period", U"ppgb", 20221202) |
| 27 |
INTRO (U"A command that becomes available in the @@Query submenu@ if you select a @Sound object.") |
| 28 |
NORMAL (U"The Info window will tell you the @@sampling period@ in seconds.") |
| 29 |
ENTRY (U"Usage") |
| 30 |
NORMAL (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 |
CODE (U"selectObject: \"Sound hello\"") |
| 34 |
CODE (U"samplingPeriod = Get sampling period") |
| 35 |
ENTRY (U"Details for hackers") |
| 36 |
NORMAL (U"With @Inspect, you can see how the sampling period is stored in a #Sound object: it is the #dx attribute.") |
| 37 |
MAN_END |
| 38 |
|
| 39 |
MAN_BEGIN (U"Get sampling frequency", U"ppgb", 20221202) |
| 40 |
INTRO (U"A command that becomes available in the @@Query submenu@ if you select a @Sound object.") |
| 41 |
NORMAL (U"The Info window will tell you the @@sampling frequency@ in hertz.") |
| 42 |
ENTRY (U"Usage") |
| 43 |
NORMAL (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 |
CODE (U"selectObject: \"Sound hello\"") |
| 47 |
CODE (U"samplingFrequency = Get sampling frequency") |
| 48 |
ENTRY (U"Algorithm") |
| 49 |
NORMAL (U"The sampling frequency is defined as 1 / (\\De%t), where \\De%t is the @@sampling period@. " |
| 50 |
"See @@Get sampling period@.") |
| 51 |
MAN_END |
| 52 |
|
| 53 |
MAN_BEGIN (U"Get time from sample number...", U"ppgb", 20221202) |
| 54 |
INTRO (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 55 |
NORMAL (U"The Info window will tell you the time (in seconds) associated with the sample number that you specify.") |
| 56 |
ENTRY (U"Setting") |
| 57 |
TERM (U"##Sample number") |
| 58 |
DEFINITION (U"the sample number whose time is sought.") |
| 59 |
ENTRY (U"Algorithm") |
| 60 |
NORMAL (U"the result is") |
| 61 |
EQUATION (U"%t__1_ + (%sampleNumber - 1) \\.c \\De%t") |
| 62 |
NORMAL (U"where %t__1_ is the time associated with the first sample, and \\De%t is the sampling period.") |
| 63 |
ENTRY (U"Details for hackers") |
| 64 |
NORMAL (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_END |
| 68 |
|
| 69 |
MAN_BEGIN (U"Get sample number from time...", U"ppgb", 20221202) |
| 70 |
INTRO (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 71 |
NORMAL (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 |
ENTRY (U"Setting") |
| 74 |
TERM (U"##Time (s)") |
| 75 |
DEFINITION (U"the time (in seconds) for which you want to know the sample number.") |
| 76 |
ENTRY (U"Example") |
| 77 |
NORMAL (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 |
ENTRY (U"Scripting") |
| 80 |
NORMAL (U"You can use this command to put the nearest sample number into a script variable:") |
| 81 |
CODE (U"selectObject: \"Sound hallo\"") |
| 82 |
CODE (U"sampleNumber = Get sample number from time... 0.1") |
| 83 |
CODE (U"nearestSample = round (sampleNumber)") |
| 84 |
NORMAL (U"In this case, the value will not be written into the Info window. To round down or up, use") |
| 85 |
CODE (U"leftSample = floor (sampleNumber)") |
| 86 |
CODE (U"rightSample = ceiling (sampleNumber)") |
| 87 |
ENTRY (U"Algorithm") |
| 88 |
NORMAL (U"the result is") |
| 89 |
EQUATION (U"1 + (%time \\-- %t__1_) / \\De%t") |
| 90 |
NORMAL (U"where %t__1_ is the time associated with the first sample, and \\De%t is the sampling period.") |
| 91 |
ENTRY (U"Details for hackers") |
| 92 |
NORMAL (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_END |
| 96 |
|
| 97 |
MAN_BEGIN (U"Get number of samples", U"ppgb", 20221202) |
| 98 |
INTRO (U"A command that becomes available in the @@Query submenu@ if you select a @Sound or @LongSound object.") |
| 99 |
NORMAL (U"The Info window will tell you the total number of time samples in this object.") |
| 100 |
ENTRY (U"Example") |
| 101 |
NORMAL (U"If the sampling frequency is 44100 hertz, a recording with a duration of 60 seconds " |
| 102 |
"will contain 2,646,000 samples.") |
| 103 |
ENTRY (U"Details for hackers") |
| 104 |
NORMAL (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_END |
| 107 |
|
| 108 |
MAN_BEGIN (U"Get time from frame number...", U"ppgb", 20221202) |
| 109 |
INTRO (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 |
NORMAL (U"The Info window will tell you the time associated with the frame number that you specify.") |
| 112 |
ENTRY (U"Setting") |
| 113 |
TERM (U"##Frame number") |
| 114 |
DEFINITION (U"the frame number whose time is sought.") |
| 115 |
ENTRY (U"Algorithm") |
| 116 |
NORMAL (U"the result is") |
| 117 |
EQUATION (U"%t__1_ + (%frameNumber - 1) \\.c \\De%t") |
| 118 |
NORMAL (U"where %t__1_ is the time associated with the centre of the first frame, and \\De%t is the time step.") |
| 119 |
ENTRY (U"Details for hackers") |
| 120 |
NORMAL (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_END |
| 124 |
|
| 125 |
MAN_BEGIN (U"Get frame number from time...", U"ppgb", 20221202) // 2025 |
| 126 |
INTRO (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 |
NORMAL (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 |
ENTRY (U"Setting") |
| 131 |
TERM (U"##Time (s)") |
| 132 |
DEFINITION (U"the time (in seconds) for which you want to know the frame number.") |
| 133 |
ENTRY (U"Example") |
| 134 |
NORMAL (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 |
ENTRY (U"Scripting") |
| 137 |
NORMAL (U"You can use this command to put the nearest frame centre into a script variable:") |
| 138 |
CODE (U"selectObject: \"Pitch hallo\"") |
| 139 |
CODE (U"frame = Get frame number from time... 0.1") |
| 140 |
CODE (U"nearestFrame = round (frame)") |
| 141 |
NORMAL (U"In this case, the value will not be written into the Info window. To round down or up, use") |
| 142 |
CODE (U"leftFrame = floor (frame)") |
| 143 |
CODE (U"rightFrame = ceiling (frame)") |
| 144 |
ENTRY (U"Algorithm") |
| 145 |
NORMAL (U"the result is") |
| 146 |
EQUATION (U"1 + (%time \\-- %t__1_) / \\De%t") |
| 147 |
NORMAL (U"where %t__1_ is the time associated with the centre of the first frame, " |
| 148 |
"and \\De%t is the time step.") |
| 149 |
ENTRY (U"Details for hackers") |
| 150 |
NORMAL (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_END |
| 154 |
|
| 155 |
MAN_BEGIN (U"Get time step", U"ppgb", 20221202) |
| 156 |
INTRO (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 |
NORMAL (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 |
ENTRY (U"Details for hackers") |
| 161 |
NORMAL (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_END |
| 164 |
|
| 165 |
MAN_BEGIN (U"Get number of frames", U"ppgb", 20221202) |
| 166 |
INTRO (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 |
NORMAL (U"The Info window will tell you the total number of time frames in the object.") |
| 169 |
ENTRY (U"Details for hackers") |
| 170 |
NORMAL (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_END |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
/* End of file manual_Sampling.cpp */ |