Files
hack/bin/main.cpp

96 lines
2.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <vector>
#include <forward_list>
#include "hack/audio/generate.hpp"
#include "hack/audio/play.hpp"
#include "hack/audio/save.hpp"
#include "hack/logger/logger.hpp"
#include "hack/range/sort.hpp"
#include "hack/range/save_to_file.hpp"
#include "hack/math/max.hpp"
#include "hack/patterns/ring_buffer.hpp"
#include "hack/patterns/identificator.hpp"
// #include "hack/security/uuid.hpp"
auto main(int argc, char *argv[]) -> int
{
{
int sample_rate = 44100;
// Воспроизведение последовательности нот
hack::warn()("Пример использования: audio");
std::vector<double> frequencies = { 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94 };
std::vector<double> melody;
for (double freq : frequencies)
{
auto note = hack::audio::generate::sine(freq, 0.3, sample_rate);
melody.insert(melody.end(), note.begin(), note.end());
// Добавляем небольшую паузу между нотами. Т.е. вставляем кол-во с нулевым значением.
melody.insert(melody.end(), sample_rate * 0.05, 0.0);
}
hack::log()("Воспроизведение последовательности нот...");
hack::audio::play(melody, sample_rate);
hack::log()("Запись последовательности нот в файл");
hack::audio::save("/mnt/raid/projects/hack/hack/bin/test/note.wav", melody, sample_rate);
}
// patterns::ring_buffer
{
hack::patterns::ring_buffer<int> rb;
rb.create(10);
for (int i = 0; i < 10; ++i) rb.put(i);
hack::log()(rb);
hack::log()(rb.size());
rb.skip(3);
hack::log()(rb.get().value());
hack::log()(rb.size());
std::vector<int> v(3);
rb.get(v, 3);
hack::log()(v);
}
// security
{
// hack::log()(hack::security::generate_uuid());
}
// patterns::identificator
{
struct a : public hack::patterns::identificator<>
{} aa;
a bb;
a cc;
a dd;
hack::log()(aa.m_id, bb.m_id, cc.m_id, dd.m_id);
}
// range::sort
{
std::vector<int> v { 4, 4, 6, 1, 4, 3, 2 };
std::forward_list<int> l { 8, 7, 5, 9, 0, 1, 3, 2, 6, 4 };
hack::range::sort(v);
hack::range::sort(l);
hack::log()(v);
hack::log()(l);
hack::range::save_to_file("/mnt/raid/projects/hack/hack/bin/test/range.txt", v);
hack::range::save_to_file("/mnt/raid/projects/hack/hack/bin/test/range.delemiter.txt", v, ":");
}
// math::max
{
int a = 4, b = 5;
int& c = a;
hack::log()(hack::math::max(4, 5));
hack::log()(hack::math::max(c, b));
}
}