def test_encode_dct2(self): encoded = codec.encode(np.array([1, 2, 3, 4, 1, 2, 3, 4]), 2, 2, dct2) self.assertTrue( np.allclose(encoded.getDadosComprimidos(), [ 20, -6.30864406, 0, -0.448341529, 20, -6.30864406, 0, -0.448341529 ]))
def _test_decode_depois_descarte_dct1(self): encoded = codec.encode(np.array([1, 2, 3, 4, 1, 2, 3, 4]), 2, 2, dct1) encoded.descartar(2) decodec = codec.decode(encoded.getDadosComprimidos(), 2, 2, dct1) self.assertTrue( np.array_equal( np.rint(decodec).astype(int), [1, 2, 3, 4, 1, 2, 3, 4]))
def test_encode_sobreposicao(self): result = cd.encode(np.array([1, 2, 3, 4, 1, 2, 3, 4]), 2, 2, mock_alg, 1) self.assertTrue( np.array_equal(result.getDadosComprimidos(), [3, 5, 7, 9, 9, 3, 5, 7, 7, 9, 1, 1]))
def test_encode(self): result = cd.encode(np.array([1, 2, 3, 4, 1, 2, 3]), 2, 2, mock_alg) self.assertTrue( np.array_equal(result.getDadosComprimidos(), [3, 5, 7, 9, 3, 5, 7, 1]))
from shutil import copyfile def current_milli_time(): return int(round(time.time() * 1000)) prefixoNome = "f0001038.16k.q20ms.dct2.descarta160.s0-2" os.makedirs('./result/' + prefixoNome) origem = "f0001038.16k.WAV" copyfile("./waves/" + origem, "./result/%s/%s" % (prefixoNome, origem)) fs, audData = wv.open_wave("./waves/f0001038.16k.WAV") b = current_milli_time() encoded = codec.encode(audData, fs, 0.02, dct2, 0) a = current_milli_time() print('Tempo de encode: ', a - b) encoded.descartar(160) #Arquivo comprimido encoded.saveToFile("./result/%s/encoded.dct" % prefixoNome) b = current_milli_time() decoded = codec.decodeFromEncoded(encoded, dct2) a = current_milli_time() print('Tempo de decode: ', a - b) #Arquivo recuperado wv.save_wave("./result/%s/recuperado-memoria.wav" % prefixoNome, fs, decoded, 16)
def test_encode_com_tamanho_nao_divisivel_dct1(self): encoded = codec.encode(np.array([1, 2, 3, 4, 1, 2]), 2, 2, dct1) self.assertTrue( np.array_equal( np.rint(encoded.getDadosComprimidos()).astype(int), [15, -4, 0, -1, 5, 3, -1, -3]))
def test_encode_dct1(self): encoded = codec.encode(np.array([1, 2, 3, 4, 1, 2, 3, 4]), 2, 2, dct1) self.assertTrue( np.array_equal( np.rint(encoded.getDadosComprimidos()).astype(int), [15, -4, 0, -1, 15, -4, 0, -1]))
import dcts.codec as codec import dcts.encoded as enc import dcts.dct1 as dct1 import dcts.dct2 as dct2 import sys import numpy as np entrada = sys.argv[1] descartes = int(sys.argv[2]) sobreposicao = int(sys.argv[3]) saida = sys.argv[4] saidaWav = None if len(sys.argv) > 5: saidaWav = sys.argv[5] fs, audData = wv.open_wave(entrada) encoded = codec.encode(audData, fs, 0.02, dct1, sobreposicao) encodedData = encoded.getDadosComprimidos() print(len(encodedData)) np.savez_compressed("result/teste1.npz", encodedData) encodedData.astype('int16').tofile("result/aa.npy") encoded.descartar(descartes) encoded.saveToFile(saida) if (saidaWav is not None): decoded = codec.decodeFromEncoded(encoded, dct1) wv.save_wave(saidaWav, encoded.fs, decoded, 16)