[cfe-dev] Making music with clang

Jonathan Sauer jonathan.sauer at gmx.de
Sun Dec 9 12:29:52 PST 2012


Hello,

we all know that clang can compile C++ code. But using the power of constexpr it can also create
sounds, even music: <http://d.hatena.ne.jp/boleros/20121207/1354888090> (Japanese)

Not knowing Japanese myself I had to resort to Microsoft's translator to understand the description
in the blog post: At compile-time, constexpr is used to generate a huge array (44100 elements for a
single second of sound) with the sound's waveform. The generated application then simply writes
this array into a .wav file (which are included in the blog post via Youtube).

It takes time though: Depending on the sound/music being generated, compiling (i.e. executing
the meta-program that generates the waveform) takes between a few minutes and several hours.
But it's still an interesting exploration of constexpr's possibilities.


Jonathan





More information about the cfe-dev mailing list