Beispiel #1
0
    def synth(self, LPC, Pitch, Gain):
        stp = self.param.step
        Sn = np.array([])

        SniPrev = np.zeros(stp)
        stepInset = 0
        for step, pitch in enumerate(Pitch[:]):

            lpcCoefs = LPC[step]
            gain = float(Gain[step])
            stepLeftover = stp - stepInset
            Sni = np.array([])
            if pitch == 0:
                G = float(np.sqrt(1 / stp) * gain)
                Sni = np.append(Sni, self.gNoise(stepLeftover, G))
                stepInset = 0
            else:
                G = float(np.sqrt(pitch / stp) * gain)
                innerJumps = int(1 if pitch == 0 else np.ceil(stepLeftover /
                                                              pitch))
                spannedStep = 0
                Snisub = np.array([])
                for ij in range(innerJumps):
                    Snisubi = self.glutealPulse(pitch, G)
                    Snisub = np.append(Snisub, Snisubi)
                    spannedStep += pitch
                Sni = np.append(Sni, Snisub)
                stepInset = spannedStep - stepLeftover

            Sni = self.linearPredictor(lpcCoefs, Sni, SniPrev)
            SniPrev = Sni
            Sn = np.append(Sn, np.array(Sni))

        return Sn
Beispiel #2
0
    def run(self, save=1):
        stp = self.param.step
        Sn = np.array([])

        SniPrev = np.zeros(self.param.step)
        stepInset = 0
        for step, pitch in enumerate(self.data.pitch[:]):

            lpcCoefs = self.data.lpc[step]
            gain = float(self.data.gain[step])
            stepLeftover = stp - stepInset
            Sni = np.array([])
            if pitch == 0:
                G = float(np.sqrt(1 / self.param.step) * gain)
                Sni = np.append(Sni, self.gNoise(stepLeftover, G))
                stepInset = 0
            else:
                G = float(np.sqrt(pitch / self.param.step) * gain)
                innerJumps = int(1 if pitch == 0 else np.ceil(stepLeftover /
                                                              pitch))
                spannedStep = 0
                Snisub = np.array([])
                for ij in range(innerJumps):
                    Snisubi = self.glutealPulse(pitch, G)
                    Snisub = np.append(Snisub, Snisubi)
                    spannedStep += pitch
                Sni = np.append(Sni, Snisub)
                stepInset = spannedStep - stepLeftover

            Sni = self.linearPredictor(lpcCoefs, Sni, SniPrev)

            SniPrev = Sni

            Sn = np.append(Sn, np.array(Sni))

            if (step in self.pc.stepInto3 or step in self.pc.stepIntoAll):
                self.p.prnt(2, str(step) + "------------------ start", 1)
                self.p.prnt(4, str("In Third Cycle"), 1)
                self.p.plot([(Sn, 'Sn', 'b', 0),
                             (Sni, 'Sni', 'r', len(Sn) - len(Sni)),
                             (self.data.raw[:len(Sn)] * 1, 'raw*0.3', 'c', 0)],
                            0)
                prev = 3
                since = len(Sn) - len(Sni) * prev
                since = 0 if since < 0 else since
                self.p.plot(
                    [(self.data.raw[since:len(Sn)] * 2, 'raw*2', 'c', since),
                     (Sn[since:len(Sn) - len(Sni)], 'Sn', 'b', since),
                     (Sni, 'Sni', 'r', len(Sn) - len(Sni))], 0)

                if self.pc.stop3:
                    input("   ...")

        self.syntesized = Sn

        if save:
            self.pickle.SaveData(self.data)
            self.pickle.save('syntesized', self.syntesized)
Beispiel #3
0
 def prefixLpcWith1(self, lpc ):
     lpc1 = []
     for i, aks in enumerate(lpc):
         ak = np.insert(aks, 0, 1., axis=0)
         lpc1.append(ak.tolist())            
     lpc1 = np.array(lpc1)
     return lpc1   
Beispiel #4
0
    def getDistanceRoute(self, expD):
        target = expD.shape
        Route = np.zeros(expD.shape)
        expDRoute = np.array(expD)

        baseline = 0.5
        pos = np.array([0, 0])
        dist = 0
        Route[pos[0], pos[1]] = baseline
        step = 0

        while ((target[0] - 1) - pos[0] + (target[0] - 1) - pos[0]) != 0:
            around = expD[pos[0]:pos[0] + 2, pos[1]:pos[1] + 2]
            pos, dist, delta = self.stepOne(dist, pos, around)
            step = step + 1
            Route[pos[0], pos[1]] = baseline + delta
            expDRoute[pos[0], pos[1]] = expDRoute[pos[0], pos[1]] + 3
        globalDist = np.inf
        if 0 < step:
            globalDist = dist / step

        return globalDist, Route, expDRoute
Beispiel #5
0
 def createSegmentValues(self, segments):
     quantas = [];
     lastS = 0;  
     putInCap = 0
     for i, S in enumerate(segments):
         if i == 0:
             lastS = S
         else:        
             quantas.append((S + lastS)*0.5)
             lastS = S
             putInCap = 1
     if putInCap == 1:
         quantas.append((quantas[-1]+ lastS)*0.5)
     return np.array(quantas)
Beispiel #6
0
    def stepOne(self, dist, position, arround):
        dim = arround.shape
        if 2 < sum(dim):
            dirs = np.array([])
            if 1 < dim[0] and 1 < dim[1]:
                dirs = np.array([[1, 0], [0, 1], [1, 1]])
            elif 1 < dim[0]:
                dirs = np.array([[1, 0]])
            elif 1 < dim[1]:
                dirs = np.array([[0, 1]])

            minDir = dirs[0]
            minVal = arround[minDir[0], minDir[1]]

            for d in dirs:
                thisVal = arround[d[0], d[1]]
                if thisVal <= minVal:
                    minDir = d
                    minVal = thisVal

            dist = dist + minVal
            position = position + minDir

        return position, dist, minVal
Beispiel #7
0
 def lspToLpc(self, lsp):
     lsp = np.array(lsp)
     return self.cu.lsf_to_lpc(lsp)
Beispiel #8
0
 def removeLpcPrefix(self, lpc1 ):
     lpc = []
     for i, aks in enumerate(lpc1):
         lpc.append(aks[1:])            
     lpc = np.array(lpc)
     return lpc  
Beispiel #9
0
 def __init__(self, seg, val = None):
     self.segments = np.array(seg)
     self.values = np.array(val) if val else CodingUtils().createSegmentValues(self.segments)
     self.segs = len(seg)
     self.bits = np.log2(self.segs+1).astype(np.uint8) 
Beispiel #10
0
 def getExpandedDistanceMap(self, D):
     eD = np.zeros(np.array(D.shape) + 1) + np.Inf
     eD[1:, 1:] = D
     eD[0, 0] = 0
     return eD
Beispiel #11
0
 def gNoise(self, length, val=1):
     return np.array([np.random.normal() for i in range(int(length))]) * val