def pickleAnalysisData(localAudioFiles):
    beatList = [laf.analysis.beats for laf in localAudioFiles]
    segmentList = [laf.analysis.segments for laf in localAudioFiles]
    beatPitchesList = []
    beatTimbreList = []
    beatLoudnessList = []
    for beats,segments in zip(beatList,segmentList):
        beatPitches = []
        for beat in beats:
            segs = segments.that(selection.overlap(beat))
            beatPitches.append(meanPitches(segs))
        beatPitchesList.append(beatPitches)
    for beats,segments in zip(beatList,segmentList):
        beatTimbre = []
        for beat in beats:
            segs = segments.that(selection.overlap(beat))
            beatTimbre.append(meanTimbre(segs))
        beatTimbreList.append(beatTimbre)
    for beats,segments in zip(beatList,segmentList):
        beatLoudness = []
        for beat in beats:
            segs = segments.that(selection.overlap(beat))
            beatLoudness.append(matlib.mean(segs.loudness_max))
        beatLoudnessList.append(beatLoudness)
    cPickle.dump(beatPitchesList, open('AmuInstPitches.pkl', 'w'))
    cPickle.dump(beatTimbreList, open('AmuInstTimbre.pkl', 'w'))
    cPickle.dump(beatLoudnessList, open('AmuInstLoudness.pkl', 'w'))
    sectionFirstBeats = []
    sections = [laf.analysis.sections for laf in localAudioFiles]
    for sectionsList,bList in zip(sections,beatList): 
        temp = [bList.index(bList.that(selection.overlap(section))[0]) for section in sectionsList]
        sectionFirstBeats.append(temp)
    cPickle.dump(sectionFirstBeats, open('AmuInstSections.pkl', 'w'))
def meanLoudness(segments, beats): 
    """ 
    Returns a loudness vector that is the mean of the loudness values of any segments  
    that overlap this AudioQuantum. 
    """ 
    loudness = []
    for beat in beats:
        segs = segments.that(selection.are_contained_by(beat))
        if(len(segs) == 0): segs = segments.that(selection.start_during(beat))
        if(len(segs) == 0): segs = segments.that(selection.overlap(beat))
        values = [seg.loudness_max for seg in segments.that(selection.are_contained_by
                                                            (beat))]
        loudness.append([sum(values)/len(segs)]*6)
    return loudness

    """
def meanTimbre(segments, beats): 
    """ 
    Returns a timbre vector that is the mean of the timbre vectors of any segments  
    that overlap this AudioQuantum. 
    """ 
    timbre = []
    for beat in beats:
        temp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        segs = segments.that(selection.are_contained_by(beat))
        if(len(segs) == 0): segs = segments.that(selection.start_during(beat))
        if(len(segs) == 0): segs = segments.that(selection.overlap(beat))
        for seg in segs:
            for index, tim in enumerate(seg.pitches): 
                temp[index] = temp[index] + tim
        timbre.append([float(tim / len(segs)) for tim in temp])
    return timbre
def meanPitches(segments, beats): 
    """ 
    Returns a pitch vector that is the mean of the pitch vectors of any segments
    that overlap this AudioQuantum. 
    """ 
    pitches = []
    for beat in beats:
        temp_pitches = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        segs = segments.that(selection.are_contained_by(beat))
        if(len(segs) == 0): segs = segments.that(selection.start_during(beat))
        if(len(segs) == 0): segs = segments.that(selection.overlap(beat))
        for seg in segs:
            for index, pitch in enumerate(seg.pitches): 
                temp_pitches[index] = temp_pitches[index] + pitch 
        pitches.append([float(pitch / len(segs)) for pitch in temp_pitches])
    return pitches 
Beispiel #5
0
def getBeatMarkers(loudnessMarkers,segments,beats):
    return [(b.index(b.that(selection.overlap(segments[i][loudnessMarkers[i][0]]))[0]),
             b.index(b.that(selection.overlap(segments[i][loudnessMarkers[i][1]]))[0]))
            for i,b in enumerate(beats)]