The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Music::Tension - music tension analysis

SYNOPSIS

  use Music::Tension;
  my $t = Music::Tension;
  $t->pitch2freq(60);
  $t->freq2pitch(440);

  use Music::Tension::Cope;
  my $ct = Music::Tension::Cope;
  $ct->...  # see that module for details

  use Music::Tension::Counterpoint;
  my $cpt = Music::Tension::Counterpoint;
  $cpt->... # see that module for details

  use Music::Tension::PlompLevelt;
  my $plt = Music::Tension::PlompLevelt;
  $plt->... # see that module for details

DESCRIPTION

Music tension (dissonance) analysis. This module is the parent class and as such does not offer much. The other modules under this distribution provide routines that produce numbers for how consonant or dissonant a chord or other musical events are according to some system of rules.

The numbers produced by one module can only be used in comparison with that same module (and possibly only the same version of that module with the same configuration parameters); no attempt has been made to correlate the output of any overlapping methods between the different modules.

SUB-MODULES

If you have ideas for a new tension analysis module, please let me know, so it can be included in this distribution, or locate it outside of the Music::Tension::* space.

  • Music::Tension::Cope - methods outlined in "Computer Models of Musical Creativity" by David Cope, including routines for specific pitches, verticals (chords), metric position, and other factors.

  • Music::Tension::Counterpoint - interval checks per the rules of counterpoint (or hopefully some fairly common flavor thereof).

  • Music::Tension::PlompLevelt - Plomp-Levelt consonance curve calculations based on writings and code by William Sethares, among others. For frequencies (and pitches) in vertical relationships.

METHODS

Any method may croak if something is awry with the input. These methods are inherited by the sub-modules.

new optional params

Constructor. Accepts an optional parameter to change the reference frequency use by the frequency/pitch conversion calls (440 by default).

  my $t = Music::Tension->new(reference_frequency => 442);
freq2pitch frequency

Given a frequency (Hz), returns the integer pitch number (which might also be a MIDI number). Fractional pitch results are rounded to the nearest pitch number. (I am unsure if the standard practice is to round or truncate the conversion, so I guessed to round.)

offset_tensions phrase1, phrase2

Since version 1.03.

Accumulates the tension between the given phrases (array references of pitch numbers) at each possible offset between the two. For example given the phrases D F E D and A C B A these can be compared at the following offsets:

  0
    A  C  B  A
    D  F  E  D
    69 72 71 69
    62 65 64 62
  
  1
       A  C  B  A
    D  F  E  D
       69 72 71
    62 65 64 62
  
  2
          A  C  B  A
    D  F  E  D
          69 72
    62 65 64 62
  
  3
             A  C  B  A
    D  F  E  D
             69
    62 65 64 62

The final three comparisons are typical for canon, fugue, or imitation.

Internally the pitches method is used to compute the tension between each pair of notes. Music::Tension does not implement any such method, so a sub-module must instead be used.

The return value is a list of array references of tensions; for the above there would be four items in the list, and the first array reference would have four tension values (offset 0), the second three tension values (offset 1), etc.

pitch2freq pitch

Given a pitch number (a positive integer, perhaps from the MIDI numbers range), returns the frequency (Hz).

SEE ALSO

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Jeremy Mates

https://opensource.org/licenses/BSD-3-Clause