Beispiel #1
0
def zipSongs(songA, songB, outfile_name, battle_length = 8, random_order = False):
	"""
	alternates between a downbeat from songA and a downbeat from songB for battle_length number of bars from each, then play the remainder from songA.
	
	if random_order is True then songA will still always win but the playorder will be reversed approximately half the time.

	"""
	if random_order == True and random.sample([True, False], 1)[0]:
		firstSong = songB
		secondSong = songA
		flipped = True
	else:
		firstSong = songA
		secondSong = songB
		flipped = False
	onesA = firstSong.analysis.beats.that(fall_on_the(1))
	onesB = secondSong.analysis.beats.that(fall_on_the(1))
		
	lacedUp = audio.AudioData(shape=
		(int(1.2*len(firstSong.data)),2), numChannels=firstSong.numChannels, sampleRate=firstSong.sampleRate)
	overlap_time = 0
	for bar_num in xrange(battle_length):
		lacedUp.append(audio.getpieces(firstSong, [onesA[bar_num]]))
		lacedUp.append(audio.getpieces(secondSong, [onesB[bar_num]]))
		overlap_time += onesA[bar_num].duration + onesB[bar_num].duration
	if flipped:
		lacedUp.append(audio.getpieces(firstSong, [onesA[battle_length]]))
		overlap_time += onesA[battle_length].duration
	lacedUp.append(audio.getpieces(songA,songA.analysis.bars[battle_length:]))
	lacedUp.encode(outfile_name)
	return overlap_time
Beispiel #2
0
 def assemble_by(self, samesongdownweight=10000, method = 'random'):
     #use max time signature as time signature
     out_ts = max([v.audio.analysis.time_signature['value'] for v in self.videos])
     print 'out_ts:', out_ts
     all_beats = []
     for beat in range(1,out_ts+1):
         all_beats.append([v.audio.analysis.beats.that(fall_on_the(beat)) for v in self.videos])
         # all_beats.append(dict(zip(range(len(videos)),[v.audio.analysis.beats.that(fall_on_the(beat)) for v in self.videos])))
     print 'beat break down:'
     for idx, beat in enumerate(all_beats):
         print 'beat',idx+1,':',
         print ' '.join([str(len(x)) for x in beat])
     # this_beat = all_beats[1][0].pop(0)
     on_the = 0
     # self.collectvid += self.videos[0].video[this_beat]
     # self.collectaudio += self.videos[0].audio[this_beat]
     
     while remaining_beats(all_beats) > 0:
         print 'remaining: ', remaining_beats(all_beats)
         #grabs from a track that still has beats
         try:
             next_beat_from = random.sample([x for x in range(len(all_beats[on_the])) if len(all_beats[on_the][x])>0],1)[0]
         except ValueError:
             print 'not enough beats left, giving up...'
             return
         print 'fetching a', on_the, 'beat from ', next_beat_from
         this_beat = all_beats[on_the][next_beat_from].pop(0)            
         self.collectvid += self.videos[next_beat_from].video[this_beat]
         self.collectaudio.append(audio.Simultaneous([self.videos[next_beat_from].audio[this_beat]]))
         #advance the beatticker
         on_the += 1
         if on_the >= out_ts:
             on_the = 0