def invpostaud(y, fmax, fb_type='bark', broaden=0): """ invert the effects of postaud (loudness equalization and cube - root compression) - y = postaud output - x = reconstructed critical band filters - rows = critical bands - cols = frames """ nbands, nframes = y.shape if fb_type == 'bark': bandcfhz = bark2hz(np.linspace(0, hz2bark(fmax), nbands)) elif fb_type == 'mel': bandcfhz = mel2hz(np.linspace(0, hz2mel(fmax), nbands)) elif fb_type == 'htkmel' or fb_type == 'fcmel': bandcfhz = mel2hz(np.linspace(0, hz2mel(fmax, htk=True), nbands), htk=True) bandcfhz = bandcfhz[broaden:(nbands - broaden)] fsq = bandcfhz**2 ftmp = fsq + 1.6e5 eql = np.multiply((fsq / ftmp)**2, (fsq + 1.44e6) / (fsq + 9.61e6)) x = y**(1 / 0.33) if eql[0] == 0: eql[0] = eql[1] eql[-1] = eql[-2] x = np.divide(x[broaden:(nbands - broaden + 1), :], np.add(np.tile(eql.T, (nframes, 1)).T, 1e-8)) return x, eql
def postaud(x, fmax, fb_type='bark', broaden=0): """ do loudness equalization and cube root compression - x = critical band filters - rows = critical bands - cols = frames """ nbands, nframes = x.shape nfpts = int(nbands + 2 * broaden) if fb_type == 'bark': bandcfhz = bark2hz(np.linspace(0, hz2bark(fmax), nfpts)) elif fb_type == 'mel': bandcfhz = mel2hz(np.linspace(0, hz2mel(fmax), nfpts)) elif fb_type == 'htkmel' or fb_type == 'fcmel': bandcfhz = mel2hz(np.linspace(0, hz2mel(fmax, htk=True), nfpts), htk=True) bandcfhz = bandcfhz[broaden:(nfpts - broaden)] fsq = np.power(bandcfhz, 2) ftmp = np.add(fsq, 1.6e5) eql = np.multiply((fsq / ftmp)**2, (fsq + 1.44e6) / (fsq + 9.61e6)) z = np.multiply(np.tile(eql, (nframes, 1)).T, x) z = np.power(z, 0.33) if broaden: y = np.zeros((z.shape[0] + 2, z.shape[1])) y[0, :] = z[0, :] y[1:nbands + 1, :] = z y[nbands + 1, :] = z[z.shape[0] - 1, :] else: y = np.zeros((z.shape[0], z.shape[1])) y[0, :] = z[1, :] y[1:nbands - 1, :] = z[1:z.shape[0] - 1, :] y[nbands - 1, :] = z[z.shape[0] - 2, :] return y, eql
def test_mel2hz(fmel, fhz, htk): # TO REVISE if htk == 0: fmel = np.round(hz2mel(fhz, htk)) fhz = np.round(mel2hz(fmel, htk)) np.testing.assert_almost_equal(mel2hz(fmel, htk), fhz, 0)
def test_hz2mel(fhz, fmel, htk): if htk == 0: fhz = np.round(mel2hz(fmel, htk)) np.testing.assert_almost_equal(hz2mel(fhz, htk), fmel, 0)