Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Chord root

by benn (Priest)
on Aug 11, 2003 at 19:19 UTC ( #282998=note: print w/ replies, xml ) Need Help??

in reply to Chord root

Richard Parncutt has got a bunch of 'C' code building on Prof. Terhardt's work, including a chord root program that examines progressions. This is the 'single chord' core of his version, which gives a level of ambiguity as well. I'm still playing with both this and the above...for single chords, the above may still be better - the now-infamous 'Tristan' example comes out as G# (second = B) - both valid, (and I would possibly argue more for the G#m6 spelling than a C#9 ), but research continues - *one* of them will make it into Music::Chord, I'm sure :)

use List::Util qw(max sum); use strict; use warnings; sub note2num { my ($n,$m) = split(//,uc(shift())); my %nums = qw(C 0 D 2 E 4 F 5 G 7 A 9 B 11); my $num = $nums{$n}; $num++ if ($m eq 'S' || $m eq '#'); $num-- if ($m eq 'F' || $m eq 'B'); $num; } sub num2note { my $num = int(shift()) % 12; my %notes = (0,'C',1,'C#',2,'D',3,'D#',4,'E',5,'F',6,'F#',7,'G',8, +'G#',9,'A',10,'A#',11,'B'); $notes{$num}; } sub root { my @chord = @_; my @weights; my @rootWeights = (10,0,1,0,3,0,0,5,0,0,2,0); # weights of root-su +pport intervals, similar to those in Parncutt (1988) my @notes; $notes[$_] = 0 foreach (0..11); $notes[note2num($_)] = 1 foreach (@chord); foreach my $pc(0..11) { $weights[$pc] = sum(map{$notes[($pc+$_)%12]*$rootWeights[$_]} +(0..11)); } my $ambig=sqrt(sum(@weights)/max(@weights)); my @final = map {num2note($_)} sort {$weights[$b] <=> $weights[$a] +} (0..11); ($ambig,@final); } my ($ambiguity, @roots) = root('b','d#','f','g#'); foreach ($ambiguity)) { print "Root $_ = $roots[$_-1]\n"; }

Comment on Re: Chord root
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://282998]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-08-20 22:59 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (125 votes), past polls