add save wav
This commit is contained in:
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@@ -1,7 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": []
|
||||
}
|
||||
36
src/hack/utils/save_wav.hpp
Normal file
36
src/hack/utils/save_wav.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sndfile.h>
|
||||
#include "hack/logger/logger.hpp"
|
||||
|
||||
namespace hack::utils
|
||||
{
|
||||
inline void save_wav(const std::string& path, const std::vector<float>& samples, int sample_rate)
|
||||
{
|
||||
SF_INFO sf_info;
|
||||
sf_info.samplerate = sample_rate;
|
||||
sf_info.channels = 1;
|
||||
|
||||
// SF_FORMAT_PCM_16/24/32
|
||||
// Максимальная точность (подходит для обработки в DAW, научных расчётов).
|
||||
// Меньше ошибок округления при многократной обработке (фильтрация, нормализация).
|
||||
// Поддержка чисел с плавающей запятой (если используется float или double).
|
||||
// Большой размер файла (в 2 раза больше, чем 16-bit).
|
||||
// Избыточен для финального аудио (обычно 16-24 бит достаточно).
|
||||
sf_info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
|
||||
|
||||
|
||||
SNDFILE* outfile = sf_open(path.c_str(), SFM_WRITE, &sf_info);
|
||||
if (!outfile)
|
||||
{
|
||||
hack::error()("Error: could not open file ", path);
|
||||
return;
|
||||
}
|
||||
|
||||
sf_write_float(outfile, samples.data(), samples.size());
|
||||
sf_close(outfile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user