Q:

How to add more cowbell?

Remember that Christopher Walken skit on Saturday Night live where he told the band “it needs more cowbell” https://en.wikipedia.org/wiki/More_cowbell ?  This site automated it http://www.morecowbell.dj/ using echonest http://developer.echonest.com/ .  That’s all fine.  Question is: “What is the actual algorithm behind the beat detection and cowbell insertion?”

A:

The beat and onset detection algorithms used at the Echo Nest are probably variants/improvements of the techniques developed by Tristan Jehan in his Ph.D. This is not the only approach, and I would recommend you to try first:

Getting an onset detection function using spectral flux or complex amplitude.
Using this algorithm to detect beats (you can improve it using the "comb template" method described here to score tempo candidates - I believe this combination of Ellis' dynamic programming approach with a more sophisticated candidate scoring function is what is used in Sonic Visualizer's default beat detection vamp plug-in).

As for adding the cowbell, I think there are a bunch of heuristics that could work. First of all, you can use the breaking down of the song into sections (as provided by the EN analyzer or by an algorithm like this), and process each section individually - to have changes in the cowbell pattern coincide with changes into chorus/verse. For each section, you can align the detected onsets on a grid of 16 or 32 sixteenth note to get a discrete representation of the onsets (a bit similar to what you would see on a drum machine or sequencer); and then average these patterns to get a summary of the rhythmic structure of the section. If the section is too chaotic - use a cowbell hit on each 4th or 8th note... Possible refinements: tune the cowbell so that it matches the key of the song, stop it in the sections that have a very low loudness...

