Created
February 23, 2010 03:23
-
-
Save bsstoner/311816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################################################### | |
## Playing around with the awesome Echonest Remix API. | |
## | |
## http://code.google.com/p/echo-nest-remix/ | |
## | |
## This is a script that will loop 4 beats from track 1 and mix them | |
## behind track 2., also syncing the track tempos | |
## | |
## Change the variables below. | |
########################################################################### | |
import operator | |
from echonest import audio | |
from echonest.modify import Modify | |
from pyechonest import config | |
################################################################################## | |
# Variables | |
config.ECHO_NEST_API_KEY="XXXXXXXX" # Put Your API Key Here | |
LOOP_SONG_PATH = "/Users/bsstoner/Music/Passion Pit/Manners/09 - Sleepyhead.mp3" | |
MAIN_SONG_PATH = "/Users/bsstoner/Music/05 O.N.E.mp3" | |
LOOP_OCTAVE = 0 # Set to +1 or -1 to raise/lower the octave of the loop track | |
LOOP_VOL_ADJUSTMENT = -3 # can make the loop louder/quieter | |
OUTPUT_SONG_PATH = "/Users/bsstoner/Music/mashup.mp3" | |
# | |
################################################################################## | |
back_loop = audio.LocalAudioFile(LOOP_SONG_PATH) | |
song = audio.LocalAudioFile(MAIN_SONG_PATH) | |
# Shift the tempo so the two songs are aligned, save temp file and re open. | |
m = Modify() | |
ratio = song.analysis.tempo['value']/back_loop.analysis.tempo['value'] | |
new_loop = m.shiftTempo(back_loop,ratio) | |
new_loop = m.shiftPitchOctaves(new_loop,LOOP_OCTAVE) | |
new_loop.encode("temposhift.mp3") | |
back_loop = audio.LocalAudioFile("temposhift.mp3") | |
connect = audio.AudioQuantumList() | |
loop_beats = back_loop.analysis.beats | |
song_beats = song.analysis.beats | |
iBeat = 0 # cycle 0 through 3 | |
iVariation = 0 # Variation Offset, moves the loop sample forward | |
iVarCounter = 0 # Variation Counter, only moving the offset by 8, every 16 beats in the main track | |
softer = audio.LevelDB(LOOP_VOL_ADJUSTMENT) | |
for b in song_beats: | |
loop_beat = loop_beats[iBeat+iVariation] | |
new_beat = audio.Simultaneous([b,softer(loop_beat)]) | |
song_beats.insert(song_beats.index(b),new_beat) # Insert into the beat list | |
song_beats.remove(b) # remove the old beat | |
if iBeat==3: | |
# Every 4 beats, reseat the iBeat counter | |
iBeat=0 | |
# Only increment variation counter if there's enough beats in the loop track | |
if (iVarCounter==15): | |
if (iVariation<24): | |
iVariation+=8 | |
else: | |
iVariation=0 | |
iVarCounter=0 # reset the counter | |
# Increment Counters | |
iVarCounter+=1 | |
else: | |
iBeat+=1 | |
[connect.append(b) for b in song_beats] | |
connect.encode(OUTPUT_SONG_PATH) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment