def analysisSynthesis(params, signal):

    outsignal = array(0)
    # framecutter >  windowing > FFT > IFFT > OverlapAdd
    frames = cutFrames(params, signal)

    w = std.Windowing(type="hann")
    fft = std.FFT(size=params['frameSize'])
    ifft = std.IFFT(size=params['frameSize'])
    overl = std.OverlapAdd(frameSize=params['frameSize'],
                           hopSize=params['hopSize'])
    counter = 0
    for f in frames:
        #outframe = OverlapAdd(frameSize = params['frameSize'], hopSize = params['hopSize'])(IFFT(size = params['frameSize'])(FFT(size = params['frameSize'])(Windowing()(f))))

        # STFT analysis
        infft = fft(w(f))
        # here we could apply spectral transformations
        outfft = infft

        # STFT synthesis
        ifftframe = ifft(outfft)
        of = ifftframe
        outframe = overl(of)

        if counter >= (params['frameSize'] / (2 * params['hopSize'])):
            outsignal = numpy.append(outsignal, outframe)

        counter += 1

    return outsignal
Ejemplo n.º 2
0
def analysisSynthesis(params, signal):

    outsignal = array(0)
    signal  = numpy.append(signal, zeros(params['frameSize']/2))
    
    frames = cutFrames(params, signal)
    
    w = std.Windowing(type = "hann");
    fft = std.FFT(size = params['frameSize']);
    ifft = std.IFFT(size = params['frameSize']);    
    overl = std.OverlapAdd (frameSize = params['frameSize'], hopSize = params['hopSize'], gain = 1./params['frameSize']);    
    counter = 0
    for f in frames:
      
      
      # STFT analysis
      infft = fft(w(f))
      # here we could apply spectral transformations
      outfft = infft
    
      # STFT synthesis
      ifftframe = ifft(outfft)
      of = ifftframe
      outframe = overl(of)
      
      if counter >= (params['frameSize']/(2*params['hopSize'])):
        outsignal = numpy.append(outsignal,outframe)

      counter += 1

    
    return outsignal
Ejemplo n.º 3
0
def analysisSynthesisStandard(params, signal):
  
    w = std.Windowing(type = "hann");
    fft = std.FFT(size = params['frameSize']);
    ifft = std.IFFT(size = params['frameSize']);    
    overl = std.OverlapAdd (frameSize = params['frameSize'], hopSize = params['hopSize'], gain = 1./params['frameSize']);
    # add half window of zeros to input signal to reach same ooutput length
    signal  = numpy.append(signal, zeros(params['frameSize']/2))
    
    frames = cutFrames(params, signal)

    outsignal = []
    counter = 0
    outframe = array(0)
    for f in frames:
      
      outframe = overl(ifft(fft(w(f))))
      outsignal = numpy.append(outsignal,outframe)


    outsignal = outsignal [2*params['hopSize']:]
    return outsignal
Ejemplo n.º 4
0
def analysisSynthesis(params, signal):

    outsignal = array(0)
    signal = numpy.append(signal, zeros(params['frameSize'] // 2))

    frames = cutFrames(params, signal)

    w = std.Windowing(type="hann")
    overl = std.OverlapAdd(frameSize=params['frameSize'],
                           hopSize=params['hopSize'])
    counter = 0
    for f in frames:

        of = w(f)
        outframe = overl(of)

        if counter >= (params['frameSize'] / (2 * params['hopSize'])):
            outsignal = numpy.append(outsignal, outframe)

        counter += 1

    return outsignal
import matplotlib.pylab as plt

if mode == 'standard':

  # create an audio loader and import audio file
  loader = std.MonoLoader(filename = inputFilename, sampleRate = 44100)
  audio = loader()

  print("Duration of the audio sample [sec]:")
  print(len(audio)/44100.0)

  w = std.Windowing(type = "hann");
  fft = std.FFT(size = framesize);
  ifft = std.IFFT(size = framesize);
  overl = std.OverlapAdd (frameSize = framesize, hopSize = hopsize);
  awrite = std.MonoWriter (filename = outputFilename, sampleRate = 44100);


  for frame in std.FrameGenerator(audio, frameSize = framesize, hopSize = hopsize):
    # STFT analysis
    infft = fft(w(frame))
    
    # here we could apply spectral transformations
    outfft = infft

    # STFT synthesis
    ifftframe = ifft(outfft)
    out = overl(ifftframe)    

    if counter >= (framesize/(2*hopsize)):
    def analysis_synthesis_spr_model_standard(self, params, signal):

        pool = essentia.Pool()
        #   Streaming Algos for Sine Model Analysis
        w = es.Windowing(type="hann")
        fft = es.FFT(size=params['fftSize'])
        smanal = es.SineModelAnal(
            sampleRate=params['sampleRate'],
            maxnSines=params['maxnSines'],
            magnitudeThreshold=params['magnitudeThreshold'],
            freqDevOffset=params['freqDevOffset'],
            freqDevSlope=params['freqDevSlope'])

        #   Standard Algos for Sine Model Analysis
        smsyn = es.SineModelSynth(sampleRate=params['sampleRate'],
                                  fftSize=params['frameSize'],
                                  hopSize=params['hopSize'])
        ifft = es.IFFT(size=params['frameSize'])
        overlSine = es.OverlapAdd(frameSize=params['frameSize'],
                                  hopSize=params['hopSize'],
                                  gain=1. / params['frameSize'])
        overlres = es.OverlapAdd(frameSize=params['frameSize'],
                                 hopSize=params['hopSize'],
                                 gain=1. / params['frameSize'])

        fft_original = []

        # analysis
        for frame in es.FrameGenerator(signal,
                                       frameSize=params["frameSize"],
                                       hopSize=params["hopSize"]):
            frame_fft = fft(w(frame))
            fft_original.append(frame_fft)
            freqs, mags, phases = smanal(frame_fft)
            pool.add("frequencies", freqs)
            pool.add("magnitudes", mags)
            pool.add("phases", phases)

        # remove short tracks
        minFrames = int(params['minSineDur'] * params['sampleRate'] /
                        params['hopSize'])
        pool = self.cleaningSineTracks(pool, minFrames)

        # synthesis
        sineTracksAudio = np.array([])
        resTracksAudio = np.array([])
        for frame_ix, _ in enumerate(pool["frequencies"]):
            sine_frame_fft = smsyn(pool["magnitudes"][frame_ix],
                                   pool["frequencies"][frame_ix],
                                   pool["phases"][frame_ix])
            res_frame_fft = fft_original[frame_ix] - sine_frame_fft
            sine_outframe = overlSine(ifft(sine_frame_fft))
            sineTracksAudio = np.append(sineTracksAudio, sine_outframe)
            res_outframe = overlres(ifft(res_frame_fft))
            resTracksAudio = np.append(resTracksAudio, res_outframe)

        sineTracksAudio = sineTracksAudio.flatten()[-len(signal):]
        resTracksAudio = resTracksAudio.flatten()[-len(signal):]

        #print("len signal", len(signal), "len res", len(resTracksAudio))
        return essentia.array(signal), essentia.array(
            sineTracksAudio), essentia.array(resTracksAudio)