Music retargeting

Music retargeting is the idea of taking a song and remixing it from its own existing beats/structure to fit the music to certain constraints.

Example applications:

radiotool.algorithms.retarget.retarget_to_length(song, duration, start=True, end=True, slack=5)

Create a composition of a song that changes its length to a given duration.

Parameters:
  • song (radiotool.composer.Song) – Song to retarget
  • duration (float) – Duration of retargeted song (in seconds)
  • start (boolean) – Start the retargeted song at the beginning of the original song
  • end (boolean) – End the retargeted song at the end of the original song
  • slack (float) – Track will be within slack seconds of the target duration (more slack allows for better-sounding music)
Returns:

Composition of retargeted song

Return type:

radiotool.composer.Composition

radiotool.algorithms.retarget.retarget_with_change_points(song, cp_times, duration)

Create a composition of a song of a given duration that reaches music change points at specified times. This is still under construction. It might not work as well with more than 2 cp_times at the moment.

Here’s an example of retargeting music to be 40 seconds long and hit a change point at the 10 and 30 second marks:

song = Song("instrumental_music.wav")
composition, change_points = retarget.retarget_with_change_points(song, [10, 30], 40)
composition.export(filename="retargeted_instrumental_music.")
Parameters:
  • song (radiotool.composer.Song) – Song to retarget
  • cp_times (list of floats) – Times to reach change points (in seconds)
  • duration (float) – Target length of retargeted music (in seconds)
Returns:

Composition of retargeted song and list of locations of change points in the retargeted composition

Return type:

(radiotool.composer.Composition, list)

radiotool.algorithms.retarget.retarget(song, duration, music_labels=None, out_labels=None, out_penalty=None)

Retarget a song to a duration given input and output labels on the music.

Suppose you like one section of a song, say, the guitar solo, and you want to create a three minute long version of the solo. Suppose the guitar solo occurs from the 150 second mark to the 200 second mark in the original song.

You can set the label the guitar solo with ‘solo’ and the rest of the song with ‘other’ by crafting the music_labels input function. And you can set the out_labels function to give you nothing but solo:

def labels(t):
    if 150 < t < 200:
        return 'solo'
    return 'other'

def target(t): return 'solo'

song = Song("sweet-rock-song.wav")

composition, info = retarget(song, 180,
    music_labels=labels, out_labels=target)

composition.export(filename="super-long-solo")

You can achieve much more complicated retargetings by adjusting the music_labels, out_labels and out_penalty functions, but this should give you a basic sense of how to use the retarget function.

Parameters:
  • song (radiotool.composer.Song) – Song to retarget
  • duration (float) – Duration of retargeted song (in seconds)
  • music_labels (function) – A function that takes a time (in seconds) and returns the label (str) of the input music at that time
  • out_labels (function) – A function that takes a time (in seconds) and returns the desired label (str) of the output music at that time
  • out_penalty (function) – A function that takes a time (in seconds) and returns the penalty for not matching the correct output label at that time (default is 1.0)
Returns:

Composition of retargeted song, and dictionary of information about the retargeting

Return type:

(radiotool.composer.Composition, dict)

Previous topic

Dynamics

Next topic

Music novelty

This Page

Fork me on GitHub