add save range to file
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
namespace hack::audio
|
||||
{
|
||||
// пока только wav
|
||||
inline void save(const std::string& path, const std::vector<float>& samples, int sample_rate)
|
||||
inline void save(const std::string& path, const std::vector<double>& samples, int sample_rate)
|
||||
{
|
||||
SF_INFO sf_info;
|
||||
sf_info.samplerate = sample_rate;
|
||||
@@ -30,7 +30,7 @@ namespace hack::audio
|
||||
return;
|
||||
}
|
||||
|
||||
sf_write_float(outfile, samples.data(), samples.size());
|
||||
sf_write_double(outfile, samples.data(), samples.size());
|
||||
sf_close(outfile);
|
||||
}
|
||||
}
|
||||
|
||||
40
src/hack/range/save_to_file.hpp
Normal file
40
src/hack/range/save_to_file.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "hack/logger/logger.hpp"
|
||||
|
||||
namespace hack::range
|
||||
{
|
||||
namespace {
|
||||
template<typename T>
|
||||
void save_to_file_impl(const std::filesystem::path& p, T& v, std::string delemiter = ", ")
|
||||
{
|
||||
std::ofstream file(p);
|
||||
if (!file)
|
||||
{
|
||||
error()("cant open file", p);
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < v.size(); ++i)
|
||||
{
|
||||
if (i == v.size() - 1) delemiter = "";
|
||||
file << v[i] << delemiter;
|
||||
}
|
||||
file.close();
|
||||
if (file.fail())
|
||||
error()("file dont save", p);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void save_to_file(const std::filesystem::path& p, T& v, std::string delemiter = ", ")
|
||||
{
|
||||
save_to_file_impl(p, v, delemiter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ headers = [
|
||||
'hack/math/max.hpp',
|
||||
|
||||
'hack/range/sort.hpp',
|
||||
'hack/range/save_to_file.hpp',
|
||||
|
||||
'hack/patterns/ring_buffer.hpp',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user