Skip to content

Instantly share code, notes, and snippets.

@bolero-MURAKAMI
Created December 4, 2012 14:51
Show Gist options
  • Save bolero-MURAKAMI/4204724 to your computer and use it in GitHub Desktop.
Save bolero-MURAKAMI/4204724 to your computer and use it in GitHub Desktop.
// 入力ファイル名 : デフォルト = input.wav.hpp
#ifndef CMP_FILENAME
# define CMP_FILENAME input.wav.hpp
#endif
#include <sprout/compost.hpp>
#include <sprout/array.hpp>
#include <sprout/preprocessor.hpp>
#include "wave_io.hpp"
int main(int argc, char* argv[]) {
namespace cmp = sprout::compost;
# define COMPOST_DEF_LOAD_SOURCE_IDENTIFIER wav
# define COMPOST_DEF_LOAD_INFO_IDENTIFIER wav_info
# define COMPOST_DEF_LOAD_SOURCE_FILE SPROUT_PP_STRINGIZE(CMP_FILENAME)
# include COMPOST_LOAD_SOURCE
typedef decltype(wav)::elements_type src_t;
typedef std::int16_t wav_elem_t;
typedef sprout::array<wav_elem_t, src_t::static_size> wav_t;
// 波形の生成
constexpr wav_t wav_data =
wav.elements()
| cmp::effects::distorted(100., 0.5) // ディストーション
| cmp::formats::as_pcm_wave16 // 16bitWAVE に変換
| cmp::ranges::copied // 任意のコンテナに変換可能にする
;
// ================ ここまでコンパイル時 ================
// WAVE ファイルに出力
char const* filename = argc >= 2 ? argv[1] : "distortion.wav";
output_wav(filename, wav_info, wav_data);
// dsp デバイスのセットアップ
int fd = setup_dev_dsp(wav_info);
if (fd < 0) {
return 0;
}
// dsp デバイスに書き込み
write_dev_dsp(fd, wav_data.data(), wav_data.size() * sizeof(wav_elem_t));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment