question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’d like to use librosa onsets for separating transients for sampling. I noticed the peaks are always a little later than where I’d usually chop up a sound, so I wrote a little code to walk them back to the most recent local minima:

def tweak_onsets(onset_frames, o_env):
    tweaked = []
    for onset_frame in onset_frames:
        while True:
            if onset_frame == 0:
                break
            cur = o_env[onset_frame]
            prev = o_env[onset_frame - 1]
            if prev > cur:
                break
            onset_frame = onset_frame - 1
        tweaked.append(onset_frame)
    return np.array(tweaked)

Some onsets before:

before

And after:

after

It’s not exactly right, but for my application it works pretty well. I’m not sure that this is something librosa is designed for, and therefore not a bug per se, but I can imagine someone else wanting to use librosa to chop up sounds into transient samples, so I thought I’d leave this note here.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
bmcfeecommented, Oct 11, 2016

Compromise: factor into it’s own function, and optionally call it from onset_detect?

  • onset_backtrack(events, energy) returns events (frame indices) rolled back to the most recent local min of energy
  • onset_detect(..., backtrack=True, energy=None) calls above with energy=onset_envelope
  • onset_detect(..., backtrack=True, energy=e) calls above with energy=e as a pre-computed energy curve e (eg, output of feature.rmse)

Sound reasonable?

1reaction
bmcfeecommented, Oct 11, 2016

Thanks @kylemcdonald for responding.

I’m thinking about the API here, and it’s not completely obvious how best to implement this.

One option is to add an energy argument to onset_detect. If energy is given, then backtracking to local min is enabled. Otherwise, we leave it as is. Note: we can’t directly compute energy from within onset_detect because it’s input may just be the onset envelope, and not the input signal.

Backtracking on the onset envelope itself is probably not correct, but maybe better than nothing? Should we make that an option as well?

Alternately, we could just make backtracking into a separate function that takes in onset times and an energy signal, and does the backtracking.

[Tagging @craffel for thoughts]

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is Tweaking? Tweaking is the 4th stage that meth users ...
Tweaking is the 4th stage that meth users experience, and is also the most dangerous. The condition occurs when the user has come...
Read more >
Tweaking From Meth - How To Get Help | Prosperity Haven
In today's guide, we are going to explain the term of tweaking from meth ... as well as the onset of highly unpleasant...
Read more >
Urinary HER2, TWEAK and VCAM-1 levels are ... - PubMed
Urinary HER2, TWEAK and VCAM-1 levels are associated with new-onset proteinuria in paediatric lupus nephritis · Authors · Affiliations.
Read more >
'Tweaking' the model for understanding and preventing ...
Although this model addresses some of the core areas that can be targeted to drastically reduce maternal and neonatal morbidity and mortality, ...
Read more >
Urinary HER2, TWEAK and VCAM-1 levels are associated ...
These biomarkers were not increased in acute kidney injury or JIA. Conclusion All three biomarkers were associated with new onset proteinuria and increased...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found