fastaudio / fastai2_audio

[DEPRECATED] Audio Module for fastai v2
Apache License 2.0
65 stars 15 forks source link

Add testing to ensure spectrograms remain right-side up #9

Closed johanndiedrick closed 4 years ago

johanndiedrick commented 4 years ago

We've had a lot of issues ensuring we don't accidentally display spectrograms upside down! This should be basic and is easily tested by generating a tone of e.g. 100hz and then making sure the spectrogram has a bar near the bottom.

@rbracco I was able to generate a spectrogram for a 100hz sine wave. Which function are we wanting to test in the notebooks?

johanndiedrick commented 4 years ago

notes from @rbracco :

In 00_core:

  1. remove the .flip(1) from the last line of AudioToSpec.encodes

  2. make a line that is like a2s = AudioToSpec(mel=True, to_db=True, f_max=8000, f_min=50, n_mels=128...etc) where all the possible settings are set explicitly, that way if we change defaults it won't mess with your test

that part is pretty annoying but im not sure how else to do it

  1. make something that makes an AudioItem with a given frequency (e.g. 100hz)

  2. make a spectrogram from that, sg = a2s(ai_100hz)

  3. get the max row from the spectrogram like this x.max(dim=1).indices.mode().values.item()

  4. make a test that compares x.max(dim=1).indices.mode().values.item() with the int value you got in 5, that way if it breaks we will know, so like test_eq(x.max(dim=1).indices.mode().values.item(), 11)

and if it flips, the 11th row wont be the most lit up, it will be the 117th or something

haha and this was supposed to be easy! lmk if you think of a better way

also when you make the tone, make sure it is of shape (1 x samples) not just (samples) all of our code assumes there is a channel dimension

actually one optimization is just setting the frequency super low, to say 5hz and then i think it will mean bin 0 is the most activated, that gets rid of step 5