1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef RHYTHMGAME_UTILITYFUNCTIONS_H 18 #define RHYTHMGAME_UTILITYFUNCTIONS_H 19 20 #include <stdint.h> 21 22 constexpr int64_t kMillisecondsInSecond = 1000; 23 constexpr int64_t kNanosecondsInMillisecond = 1000000; 24 25 enum class TapResult { 26 Early, 27 Late, 28 Success 29 }; 30 31 int64_t nowUptimeMillis(); 32 convertFramesToMillis(const int64_t frames,const int sampleRate)33constexpr int64_t convertFramesToMillis(const int64_t frames, const int sampleRate){ 34 return static_cast<int64_t>((static_cast<double>(frames)/ sampleRate) * kMillisecondsInSecond); 35 } 36 37 TapResult getTapResult(int64_t tapTimeInMillis, int64_t tapWindowInMillis); 38 39 void renderEvent(TapResult r); 40 41 42 #endif //RHYTHMGAME_UTILITYFUNCTIONS_H 43