Bach raised to the n-th power: exploring musical harmony of counterpoint​
​by James Lu
Bach is a master of counterpoint, with music containing melodic lines that are harmonically interdependent on each other. His music often combines beauty with an almost mathematical structure. Listen to the first 24 seconds of the following clip, and note how the first subject re-enters in modified forms starting at t=6th and 16th seconds:
In[]:=
BachClip=Import["https://wolfr.am/Zds5yDLH"];​​BachClipTrim=AudioTrim[%,24]
Out[]=
One can see this in the spectrogram, note how a lower sequence of notes appear around 6th second:
Spectrogram[BachClipTrim]
Out[]=
Can we add to Bach’s counterpoint, by successively adding layers on top of the original?
Using Wolfram Language, we can try this out using a code of only 127 characters in length!
In[]:=
BachToPower3=​​AudioChannelCombine@MapIndexed[AudioAmplify[#1,1/#2[[1]]]~AudioPad~{6#2[[1]]-6,0}&,Import["https://wolfr.am/Zds5yDLH"]~Table~3];
The following are the spectrograms of each of the 3 layers we are adding with the above code, each of which is obtained by time-translation and attenuation of the original:
Spectrogram[AudioTrim[#,24]]&/@MapIndexed[AudioAmplify[#1,1/#2[[1]]]~AudioPad~{6#2[[1]]-6,0}&,Import["https://wolfr.am/Zds5yDLH"]~Table~3]//List//Grid
Out[]=
Finally, the following is the spectrogram of the 3 combined:
Spectrogram[AudioTrim[BachToPower3,24]]
Out[]=
The effect of the operations we’ve implemented can also be visualized by the following plot, which compares the original audio plot to the result from the WL code:
Grid[{{AudioPlot[BachClipTrim],AudioPlot[AudioTrim[BachToPower3,24]]}},AlignmentTop]
Out[]=
Would Bach have done this to explore harmonies if he had access to Wolfram Language?
The ultimate test of music is its aesthetics, so one will just have to listen to the music and make your own judgement:
In[]:=
BachToPower3
Out[]=