#include "hack/audio/generate.hpp" #include "hack/audio/play.hpp" #include "hack/audio/save.hpp" #include "hack/audio/record.hpp" #include "hack/logger/logger.hpp" auto main(int argc, char *argv[]) -> int { hack::warn()("Пример работы: audio"); int sample_rate = 44100; // созданиен массива звуков std::vector 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 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()("Запись последовательности нот масива в файл"); std::string file = "/mnt/raid/projects/hack/hack/bin/examples/audio/note.wav"; hack::audio::save(file, melody, sample_rate); hack::log()("Воспроизведение последовательности нот из файла"); hack::audio::play(file); hack::log()("Запись аудио с микрофона"); std::vector recorded_data; hack::audio::record(recorded_data, sample_rate, 1, 5.0); hack::log()("Воспроизведение аудио с микрофона"); hack::audio::play(recorded_data, sample_rate, 1); }