add audio generate and audio example

This commit is contained in:
2025-08-31 12:02:29 +03:00
parent e217920fe8
commit 7832b2095b
9 changed files with 99 additions and 12 deletions

View File

@@ -1,6 +1,10 @@
#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"
@@ -14,6 +18,28 @@
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;
@@ -55,8 +81,8 @@ auto main(int argc, char *argv[]) -> int
hack::log()(v);
hack::log()(l);
// hack::range::save_to_file("/mnt/raid/projects/hack/hack/test.txt", v);
// hack::range::save_to_file("/mnt/raid/projects/hack/hack/test.txt", v, ":");
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