code: def testImpulse(self):
      # tests that for an impulse will yield the correct position
      audiosize = 10000
      audio = zeros(audiosize)
      pos = 5.5  # impulse will be in between frames 4 and 5
      audio[int(floor(pos * (hopsize)))] = 1.0
      frames = FrameGenerator(
          audio,
          frameSize=framesize,
          hopSize=hopsize,
          startFromZero=True,
      )
      win = Windowing(type="hamming", zeroPadding=framesize)
      fft = FFT()
      onset_hfc = OnsetDetection(method="hfc")
      onset_complex_phase = OnsetDetection(method="complex_phase")
      onset_rms = OnsetDetection(method="rms")
      onset_flux = OnsetDetection(method="flux")
      onset_melflux = OnsetDetection(method="melflux")
      onset_complex = OnsetDetection(method="complex")
  
      nframe = 0
      for frame in frames:
          mag, ph = CartesianToPolar()(fft(win(frame)))
  
          # 'rms' (energy flux) and 'melflux' method will result in a non-zero value on frames 4 and 5,
          # energy flux for frame 6 is zero due to half-rectification
          # 'flux' on contrary will results in non-zero value for frame 6, as it does not half-rectify
  
          if nframe == floor(pos) - 1:  # 4th frame
              self.assertNotEqual(onset_complex_phase(mag, ph), 0)
              self.assertNotEqual(onset_hfc(mag, ph), 0)
              self.assertNotEqual(onset_rms(mag, ph), 0)
              self.assertNotEqual(onset_flux(mag, ph), 0)
              self.assertNotEqual(onset_melflux(mag, ph), 0)
              self.assertNotEqual(onset_complex(mag, ph), 0)
          elif nframe == ceil(pos) - 1:  # 5th frame
              self.assertNotEqual(onset_complex_phase(mag, ph), 0)
              self.assertNotEqual(onset_hfc(mag, ph), 0)
              self.assertNotEqual(onset_rms(mag, ph), 0)
              self.assertNotEqual(onset_flux(mag, ph), 0)
              self.assertNotEqual(onset_melflux(mag, ph), 0)
              self.assertNotEqual(onset_complex(mag, ph), 0)
          elif nframe == ceil(pos):  # 6th frame
              self.assertEqual(onset_complex_phase(mag, ph), 0)
              self.assertEqual(onset_hfc(mag, ph), 0)
              self.assertEqual(onset_rms(mag, ph), 0)
              self.assertNotEqual(onset_flux(mag, ph), 0)
              self.assertEqual(onset_melflux(mag, ph), 0)
              self.assertNotEqual(onset_complex(mag, ph), 0)
          else:
              self.assertEqual(onset_complex_phase(mag, ph), 0)
              self.assertEqual(onset_hfc(mag, ph), 0)
              self.assertEqual(onset_rms(mag, ph), 0)
              self.assertEqual(onset_flux(mag, ph), 0)
              self.assertEqual(onset_melflux(mag, ph), 0)
              self.assertEqual(onset_complex(mag, ph), 0)
          nframe += 1
  
file_path: essentia/test/src/unittests/rhythm/test_onsetdetection.py
imports: from numpy import *
  from essentia_test import *
label_desc: Use image node_id 2 for calling the TestOnsetDetection obj's underlying member method code with example usage: obj.testImpulse() without return types