Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.35 KB

README.md

File metadata and controls

25 lines (17 loc) · 1.35 KB

Björklund's Algorithm in Elixir

I've read the Godfried Toussaint's work, The Euclidean Algorithm Generates Traditional Musical Rhythms. This paper describes how is possible to generate percussive rhythms using an Euclidean algorithm and how many classical rhythms have a link with this principle.

The paper also cite the Björklund's work The Theory of Rep-Rate Pattern Generation in the SNS Timing System where an algorithm to distribute k pulses (1s) in n slots of time is presented and shows how this algorithm is bounded to the Euclidean principle.

I decided to translate the algorithm in Elixir.

The module has two public functions:

  • bjorklund(slots, pulses), returns a list that represents the sequence of pulses 1s evenly distributed in slots units
  • is_evenly_distributed(seq), checks if seq is an evenly distributed sequence of 1s.

How to use

Here is an example usage (in iex):

iex(1)> Bjorklund.bjorklund 15, 6                                             
[0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]
iex(2)> Bjorklund.is_evenly_distributed [1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0] 
true
iex(3)> Bjorklund.is_evenly_distributed [0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0] 
false