/* Copyright (c) 2021 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __Note_H__ #define __Note_H__ #ifdef __cplusplus extern "C" { #endif #include typedef int NoteValue; // 12 keys per octave; 48 = 220hz, 60 = 440hz typedef float OctaveValue; // Log2 frequency; 4.0 = 220hz, 5.0 = 440hz #define NOTE_Ab -1 #define NOTE_A 0 #define NOTE_As 1 #define NOTE_Bb 1 #define NOTE_B 2 #define NOTE_C 3 #define NOTE_Cs 4 #define NOTE_Db 4 #define NOTE_D 5 #define NOTE_Ds 6 #define NOTE_Eb 6 #define NOTE_E 7 #define NOTE_F 8 #define NOTE_Fs 9 #define NOTE_Gb 9 #define NOTE_G 10 #define NOTE_Gs 11 #define NOTE_VALUE(note, octave) ((NoteValue) ((octave) * 12 + (note))) static inline float hertzToOctave(float hertz) { return log2f(hertz / 13.75f); } static inline float octaveToHertz(float octave) { return 13.75f * powf(2.0f, octave); } #ifdef __cplusplus } #endif #endif