[cfe-dev] Making music with clang

Richard Smith richard at metafoo.co.uk
Sun Dec 9 21:49:09 PST 2012


On Sun, Dec 9, 2012 at 12:29 PM, Jonathan Sauer <jonathan.sauer at gmx.de> wrote:
> 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.

Thanks for reporting this, it's very interesting to see what people
are doing with constexpr. I find it particularly interesting that GCC
couldn't cope with this code because its memoization used up too much
memory (although it looks like Clang had some trouble with memory
usage too, on some of the later examples).

If nothing else, this provides us with a set of interesting testcases
for any constexpr optimization work. I'm also curious whether
globalopt would have been able to reduce the initialization down to
constant if we removed the 'constexpr' keywords!



More information about the cfe-dev mailing list