Files
hack/bin/audio.cpp

42 lines
1.7 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 "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<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()("Запись последовательности нот масива в файл");
std::string file = "/mnt/raid/projects/hack/hack/bin/test/note.wav";
hack::audio::save(file, melody, sample_rate);
hack::log()("Воспроизведение последовательности нот из файла");
hack::audio::play(file);
hack::log()("Запись аудио с микрофона");
std::vector<double> recorded_data;
hack::audio::record(recorded_data, sample_rate, 1, 5.0);
hack::log()("Воспроизведение аудио с микрофона");
hack::audio::play(recorded_data, sample_rate, 1);
}