Mercurial > hg > syncopation-dataset
annotate Syncopation models/TOB.py @ 14:6b6f8e3d7262
updating lhl and prs
author | csong <csong@eecs.qmul.ac.uk> |
---|---|
date | Fri, 03 Apr 2015 17:10:57 +0100 |
parents | 031e2ccb1fb6 |
children | b959c2acb927 |
rev | line source |
---|---|
csong@1 | 1 ''' |
csong@1 | 2 Author: Chunyang Song |
csong@1 | 3 Institution: Centre for Digital Music, Queen Mary University of London |
csong@1 | 4 |
csong@1 | 5 ''' |
csong@1 | 6 |
csong@2 | 7 from BasicFuncs import ceiling, find_divisor, get_min_timeSpan |
csong@1 | 8 |
csong@1 | 9 # This function calculates the syncopation value for TOB model. |
csong@1 | 10 def get_syncopation(seq): |
csong@1 | 11 syncopation = 0 |
csong@1 | 12 bseq_ts = get_min_timeSpan(ceiling(seq)) # converting to binary and mininum time-span sequence |
csong@1 | 13 divisors = find_divisor(len(bseq_ts)) # find all the divisors other than 1 and the length of this sequence |
csong@1 | 14 del divisors[0] |
csong@1 | 15 del divisors[-1] |
csong@1 | 16 |
csong@1 | 17 offbeatness = [1]*len(bseq_ts) |
csong@1 | 18 for index in range(len(bseq_ts)): |
csong@1 | 19 for d in divisors: |
csong@1 | 20 if index % d == 0: |
csong@1 | 21 offbeatness[index] = 0 |
csong@1 | 22 break |
csong@1 | 23 syncopation += bseq_ts[index]*offbeatness[index] |
csong@1 | 24 return syncopation |