def synthesizeIFFT(self , newValue=None): ''' DEPRECATED synthesis using Python fftw3 wrapper but no waveform server... a lot slower ''' mdctVec = zeros(3*self.length); if newValue is None: mdctVec[self.length + self.frequencyBin] = self.mdct_value; else: mdctVec[self.length + self.frequencyBin] = newValue; self.waveform = imdct(mdctVec , self.length)[0.75*self.length : 1.75*self.length] return self.waveform
def runTest(self): # empty creation pyAtom = BaseAtom() self.assertEqual(pyAtom.length , 0) self.assertEqual(pyAtom.amplitude , 0) self.assertEqual(pyAtom.nature , 'Abstract') del pyAtom # full creation pyAtom2 = mdct_atom.Atom(1024 , 1 , 12432 , 128 , 44100 , 0.57) self.assertEqual(pyAtom2.length , 1024) self.assertEqual(pyAtom2.amplitude , 1) self.assertEqual(pyAtom2.mdct_value , 0.57) self.assertEqual(pyAtom2.samplingFrequency , 44100) self.assertEqual(pyAtom2.reducedFrequency , float(128 + 0.5)/float(1024)) self.assertEqual(pyAtom2.timePosition , 12432) self.assertEqual(pyAtom2.nature , 'MDCT') # synthesizedAtom2 = pyAtom2.synthesize() synthAtom3 = pyAtom2.synthesizeIFFT() # energy1 = sum(synthesizedAtom2.waveform**2) energy2 = sum(synthAtom3.real**2) print energy2 # plt.plot(synthesizedAtom2.real) plt.plot(synthAtom3.real) del pyAtom2 print " testing LOmp atoms synthesis " mdctValue = 0.57; timeShift = 144; projectionScore = -0.59; pyAtomLOmp = mdct_atom.Atom(1024 , 1 , 12432 , 128 , 44100 , 0.57) pyAtomLOmp.timeShift = timeShift pyAtomLOmp.projectionScore = projectionScore # test 1 synthesis pyAtomLOmp.synthesizeIFFT() wf1 = pyAtomLOmp.waveform.copy() wf2 = -(math.sqrt(abs(projectionScore)/sum(wf1**2)))*wf1 mdctVec = zeros(3*1024); mdctVec[1024 + 128] = projectionScore; wf3 = mdct.imdct(mdctVec , 1024)[0.75*1024 : 1.75*1024] plt.figure() plt.plot(wf1) plt.plot(wf2) plt.plot(wf3) plt.legend(('1', '2', '3'))
def synthesize(self , method = 0 , forceReSynthesis = True): """ function that will synthesise the approximant using the list of atoms this is mostly DEPRECATED""" if self.originalSignal == None: _Logger.warning("No original Signal provided") # return None if (self.recomposedSignal == None) | forceReSynthesis: synthesizedSignal = zeros(self.length) if len(self.atoms) == 0: _Logger.info("No Atoms") return None # first method by inverse MDCT if method == 0: for mdctSize in self.dico.sizes: mdctVec = zeros(self.length) for atom in self.atoms: if atom.length == mdctSize: # bugFIx n = atom.timePosition +1 frame = math.floor( float(n) / float(atom.length /2) ) +1 # mdctVec[frame*float(atom.length /2) + atom.frequencyBin] += atom.amplitude mdctVec[frame*float(atom.length /2) + atom.frequencyBin] += atom.mdct_value synthesizedSignal += imdct(mdctVec , mdctSize) # synthesizedSignal += concatenate((zeros(mdctSize/4) , imdct(mdctVec , mdctSize)) )[1:-mdctSize/4+1] # second method by recursive atom synthesis - NOT WORKING elif method == 1: for atom in self.atoms: atom.synthesizeIFFT() synthesizedSignal[atom.timePosition : atom.timePosition + atom.length] += atom.waveform # HACK here to resynthesize using LOMP atoms elif method == 2: for atom in self.atoms: atom.waveForm = atom.synthesizeIFFT() if (atom.projectionScore is not None): if (atom.projectionScore <0): atom.waveform = (-math.sqrt(-atom.projectionScore/sum(atom.waveform**2)) )*atom.waveform else: atom.waveform = (math.sqrt(atom.projectionScore/sum(atom.waveform**2)) )*atom.waveform synthesizedSignal[atom.timePosition : atom.timePosition + atom.length] += atom.waveform self.recomposedSignal = signals.Signal(synthesizedSignal , self.samplingFrequency) #return self.recomposedSignal # other case: we just give the existing synthesized Signal. return self.recomposedSignal