astronify icon indicating copy to clipboard operation
astronify copied to clipboard

Metronome

Open Jenneh opened this issue 4 years ago • 5 comments
trafficstars

Create function to easily add a regular beat behind sonification that acts as tics on the time axis. (default to data time, ie: 4 days)

User should be able to define the frequency of the beat.

Jenneh avatar Feb 15 '21 17:02 Jenneh

this may not be ideal, but it could be possible to use audacity (https://www.reddit.com/r/audacity/comments/9n2xkv/how_do_i_add_a_metronome_or_click_track_to_my/) to generate the metronome and then combine it with the existing sound and/or video using ffpmeg in a similar way to #47. In my limited research I havent yet seen a python solution for generating this metronome tone though

MoralCode avatar Feb 19 '21 20:02 MoralCode

@MoralCode The goal here is to have completely coupled with the sonification so that it can be used directly from the command line.

ceb8 avatar Feb 22 '21 14:02 ceb8

I have successfully updated the code from the animation issue previously referenced to be able to combine multiple audio sources but seem to be stuck on actually generating the audio files with the metronome pulses to feed into it.

starting from the gist in the animation issue, you can add lines like this to combine audio sources (two at a time) and then feed this combined audio into the final call that merges the audio with the video. This example is for adding two metronome tracks, but can easily be chained for more inputs by repeating the second line and making a new variable for it:

claps = ffmpeg.filter([input_audio2, input_audio3], 'amix')
merged_audio = ffmpeg.filter([input_audio, claps], 'amix')

i can also put the full code in a git repo or gist if you prefer.

~~Searches for metronomes in python, particularly using pythons built in timing function, seem to indicate that using python can cause timing can be off (one place i saw seemed to indicate about 50ms in either direction) due to the various uncontrollable layers that python has to go through to get to the hardware, with each adding a little latency.~~

~~What are the timing/accuracy requirements that you have for this metronome? would this be sufficient?~~

MoralCode avatar Feb 22 '21 22:02 MoralCode

here is a repo for some python code that takes in two wav files, (one as the tone to use for the metronome, the other is the sonification), a frequency in BPM, and a gif file and:

  1. copies and pads the tone with silence so that it is the correct length for the provided BPM
  2. loops this tone and combines it with the sonification audio
  3. combines this audio with the gif
  4. outputs to an mp4 file

Hope this works for you! If this should be a separate thing or if you'd like me to do some more refactoring to make it all into functions I can do that as well

MoralCode avatar Feb 23 '21 05:02 MoralCode

That's super cool! And will definitely be a backup option. Ultimately, I would like build it within pyo (http://ajaxsoundstudio.com/software/pyo/) and have it integrated with the sonification functionality so that it doesn't have to be post processing on a wav file.

ceb8 avatar Feb 25 '21 17:02 ceb8