Get frame number from time...

A command that becomes available in the Query submenu if you select a sound-analysis object that is a function of time and that is evenly sampled in time (Pitch, Formant, Intensity, Harmonicity).

The Info window will tell you the frame number belonging to the time that you specify. The result is presented as a real number.


Time (s)
the time (in seconds) for which you want to know the frame number.


If the Pitch object has a time step of 10 ms, and the first frame is centred around 18 ms, the frame number associated with a time of 0.1 seconds is 9.2.


You can use this command to put the nearest frame centre into a script variable:

    selectObject: "Pitch hallo"
    frame = Get frame from time... 0.1
    nearestFrame = round (frame)

In this case, the value will not be written into the Info window. To round down or up, use

    leftFrame = floor (frame)
    rightFrame = ceiling (frame)


the result is

1 + (timet1) / Δt

where t1 is the time associated with the centre of the first frame, and Δt is the time step.

Details for hackers

If you select one of the above objects and click Inspect, you can see how the relation between frame numbers and times is stored in the object: t1 is the x1 attribute, and Δt is the dx attribute.

© ppgb 20221202