Created
December 4, 2012 14:51
-
-
Save bolero-MURAKAMI/4204724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 入力ファイル名 : デフォルト = 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