Monika90 |
» 2015-11-27 18:06:34 Ze słuchu
#include <windows.h> #include <cmath>
struct Note { float duration; float pitch; };
double frequency(double note) { return 440 * std::pow(2., (note - 69) / 12.); }
auto bpm(double tempo) { return [tempo](double duration) -> unsigned { return 240'000 / tempo * duration + 0.5; }; }
int main() { const Note notes[] = { {1/16., 64}, {1/16., 60}, {1/16.}, {1/16., 55},
{2/16.}, {1/16., 55.5}, {1/16.},
{1/16., 57}, {1/16., 65}, {1/16.}, {1/16., 65},
{1/16., 57}, {3/16.},
{1/12., 59}, {1/12., 69}, {1/12., 69},
{1/12., 69}, {1/12., 67}, {1/12., 65},
{1/16., 64}, {1/16., 60}, {1/16.}, {1/16., 57},
{1/16., 55}, {3/16.},
{1/16., 64}, {1/16., 60}, {1/16.}, {1/16., 55},
{2/16.}, {1/16., 55.5}, {1/16.},
{1/16., 57}, {1/16., 65}, {1/16.}, {1/16., 65},
{1/16., 57}, {3/16.},
{1/16., 59}, {1/16., 65}, {1/16.}, {1/16., 65},
{1/12., 65}, {1/12., 64}, {1/12., 62},
{1/16., 60}, {1/16., 55}, {1/16.}, {1/16., 52},
{1/16., 48}, {3/16.}, };
const auto time = bpm(96); const int transpose = 12; for (auto& note : notes) if (note.pitch) Beep(frequency(note.pitch + transpose) + 0.5, time(note.duration)); else Sleep(time(note.duration)); }
|