MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / _modelFrameToTime

Method _modelFrameToTime

Lib/Model/Notes.h:148–168  ·  view source on GitHub ↗

* Get time in seconds given frame index. * Different behaviour in test because of weirdness in basic-pitch code * @param frame Index of frame. * @return Corresponding time in seconds. */

Source from the content-addressed store, hash-verified

146 * @return Corresponding time in seconds.
147 */
148 static inline double _modelFrameToTime(int frame)
149 {
150 // The following are compile-time computed consts only used here.
151 // If they need to be used elsewhere, please move to Constants.h
152
153 static constexpr int ANNOTATIONS_FPS = AUDIO_SAMPLE_RATE / FFT_HOP;
154 // number of frames in the time-frequency representations we compute
155 static constexpr int ANNOT_N_FRAMES = ANNOTATIONS_FPS * AUDIO_WINDOW_LENGTH;
156 // number of samples in the (clipped) audio that we use as input to the models
157 static constexpr int AUDIO_N_SAMPLES = AUDIO_SAMPLE_RATE * AUDIO_WINDOW_LENGTH - FFT_HOP;
158 // magic from Basic Pitch
159 static constexpr double WINDOW_OFFSET =
160 (double) FFT_HOP / AUDIO_SAMPLE_RATE * (ANNOT_N_FRAMES - AUDIO_N_SAMPLES / (double) FFT_HOP) + 0.0018;
161
162 // Weird stuff from Basic Pitch. Use only in test so they can pass.
163#if USE_TEST_NOTE_FRAME_TO_TIME
164 return (frame * FFT_HOP) / (double) (AUDIO_SAMPLE_RATE) -WINDOW_OFFSET * (frame / ANNOT_N_FRAMES);
165#else
166 return (frame * FFT_HOP) / (double) (AUDIO_SAMPLE_RATE);
167#endif
168 }
169
170 /**
171 * Returns a version of inOnsetsPG augmented by detecting differences in note posteriorgrams

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected