manual_Sampling.cpp 8.9 KB

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