Example #1
0
def main() :
    config.ECHO_NEST_API_KEY= "GG0IO4JU1FZQJ0IH1"
    clips = file(sys.argv[1], "r")
    dataList = []
    rate = 12000
    channels = 2
    for line in clips:
        detailArray = line.split('|')
        songFile = detailArray[0]
        startTime = float(detailArray[1])
        duration = float(detailArray[2])
        endTime = startTime + duration
        n = numpy.array([])
        e = echoAudio.AudioData(songFile, n, None, rate, channels)
        q = echoAudio.AudioQuantumList(None, "segment", None, e)
        a = echoAudio.AudioAnalysis(songFile)
        segments = a.segments
        finalSeg = segments[len(segments) - 1]
        songLength = finalSeg.start + finalSeg.duration
        complete = False
        while(not complete):
            for s in segments:
                    if((s.start >= startTime) & (s.start <= endTime)):
                        q.append(s)
            if songLength >= endTime:
                complete = True
            else:
                complete = False
                endTime = endTime - songLength                            
        p = echoAudio.getpieces(e, q)
        dataList.append(p)
    clips.close()
    echoAudio.assemble(dataList, channels, rate).encode(sys.argv[2])
Example #2
0
def render(actions, filename, verbose=True):
    """Calls render on each action in actions, concatenates the results, 
    renders an audio file, and returns a path to the file"""
    pieces = [a.render() for a in actions]
    # TODO: allow numChannels and sampleRate to vary.
    out = assemble(pieces, numChannels=2, sampleRate=44100, verbose=verbose)
    return out, out.encode(filename)
Example #3
0
def render(actions, filename, verbose=True):
    """Calls render on each action in actions, concatenates the results,
    renders an audio file, and returns a path to the file"""
    pieces = [a.render() for a in actions]
    # TODO: allow numChannels and sampleRate to vary.
    out = assemble(pieces, numChannels=2, sampleRate=44100, verbose=verbose)
    return out, out.encode(filename)
Example #4
0
def tempo_warp(section, bpm):
	print "tempo_warp"
	new_beat_duration = 60.0/bpm
	beats = song.analysis.beats.that(are_contained_by(section))
	
	new_beats = []
	for beat in beats:
		ratio = beat.duration / new_beat_duration
		new_beat = st.shiftTempo(song[beat], ratio)
		new_beats.append(new_beat)
	out = audio.assemble(new_beats)
	return out
Example #5
0
def main():
    try:
        in_filename = sys.argv[1]
        out_filename = sys.argv[2]
    except Exception:
        print USAGE
        sys.exit(-1)
    afile = audio.LocalAudioFile(in_filename)
    st = modify.Modify()
    beats = afile.analysis.beats
    collect = []
    for beat in beats:
        context = beat.local_context()
        ratio = (math.cos(math.pi * 2 * context[0] / float(context[1])) / 2) + 1
        new = st.shiftTempo(afile[beat], ratio)
        collect.append(new)
    out = audio.assemble(collect)
    out.encode(out_filename)
Example #6
0
def main(inputFilename, outputFilename, swing):
    
    infile = audio.LocalAudioFile(inputFilename)
    tats = infile.analysis.tatums
    st = modify.Modify()
    collect = []
    
    for x in tats:
        y, z = x.local_context()
        if y < z/2.:
            ratio = swing / (((z + 1) // 2) / float(z))
        else:
            ratio = (1. - swing) / (1 - ((z + 1) // 2) / float(z))
        new = st.shiftTempo(infile[x], 1./ratio)
        print "Expected:\t%1.3f\tActual:  \t%1.3f" % (x.duration * ratio, float(len(new))/new.sampleRate)
        collect.append(new)
    out = audio.assemble(collect)
    out.encode(outputFilename)
def thedownundersafetydance(down_under, safety_dance):
    du_sections = down_under.analysis.sections
    sd_sections = safety_dance.analysis.sections
    
    collect = []
    for n in range(min(len(du_sections), len(sd_sections))):
        du_beats = get_beats_from_section(du_sections[n])
        sd_beats = get_beats_from_section(sd_sections[n])
        process_index = n % 3
        if process_index == 0:
            new = choppy_choppy(down_under, safety_dance, du_beats, sd_beats)
            collect.extend(new)
        elif process_index == 2:
            new = choppy_choppy(down_under, safety_dance, du_beats, sd_beats, droppy=True)
            collect.extend(new)
        else:
            #new = matchy_matchy(down_under, safety_dance, du_beats, sd_beats)
            new = matchy_matchy(safety_dance, down_under, sd_beats, du_beats)
            collect.append(new)

    out = audio.assemble(collect, numChannels=2)
    return out
Example #8
0
def main(username):
  auds=[]
  p = re.compile("mix")
  files = os.listdir("f")
  for file in files:
    m = p.findall(file)
    if m:
      print "processing f/"+file
      try:
        auds.append(audio.LocalAudioFile("f/"+file))
      except:
        print "failed to include "+file
  
  auds.sort(key=keysig)
  
  mixed = []
  end = None
  previous = None
  for aud in auds:
    bars = aud.analysis.bars
    try:
      if end != None and previous != None:
        mix = audio.mix(audio.getpieces(previous, [end]), audio.getpieces(aud, [bars[0]]), 0.5)
        mixed.append(mix)
      else:
        mixed.append(audio.getpieces(aud, [bars[0]]))
    except:
      print "failed to create mix bar"

    try:
      mixed.append(audio.getpieces(aud, bars[1:-5]))
      end = bars[-5]
      previous = aud
    except:
      print "unable to append bars"

  out = audio.assemble(mixed, numChannels=2)
  out.encode(username+".mp3")
Example #9
0
def beatrepeat_and_tempo_warp(section, bpm):
	print "beatrepeat_and_tempo_warp"
	beats = song.analysis.beats.that(are_contained_by(section))
	tatums = song.analysis.beats.that(are_contained_by(section))
	br = audio.AudioQuantumList()
	
	new_beat_duration = 60.0/bpm
	beats = song.analysis.beats.that(are_contained_by(section))
	
	new_beats = []
	for beat in beats:
		ratio = beat.duration / new_beat_duration
		new_beat = st.shiftTempo(song[beat], ratio)
		new_beats.append(new_beat)
	out = audio.assemble(new_beats)
	return out
	
	
	for _ in range(2): 
		br.append(song[beats[-4]])
		br.append(song[beats[-3]])
		br.append(song[beats[-2]])
		br.append(song[beats[-1]])
Example #10
0
def render(actions, filename):
    """Calls render on each action in actions, concatenates the results, renders an audio file, and returns a path to the file"""
    pieces = [a.render() for a in actions]
    out = assemble(pieces, numChannels=2, sampleRate=44100) # TODO: make these vary.
    return out, out.encode(filename)