-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.py
More file actions
78 lines (52 loc) · 1.61 KB
/
example.py
File metadata and controls
78 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Example and main function of the program.
"""
# LHE Codec for Audio
# Author: Eduardo Rodes Pastor
import sys
from LHEquantizer import *
from binary_enc import *
from binary_dec import *
from audio_dec import *
from Auxiliary.psnr import *
# ------------------------#
# CODING/DECODING EXAMPLE #
# ------------------------#
if __name__=='__main__':
# Codec function (encoding/decoding)
function = "none"
# Function selection
while (function != "enc" and function != "dec" and function != "exit"):
print ""
function = raw_input("Select the function. Please, type enc for encoding, dec for decoding or exit if you want to close the program: ")
# --- ENCODER --- #
if function == "enc":
# Input audio path
using = "input_audio/insomnia.wav"
# LHE Quantizer
samples, n_samples, max_sample, min_sample = getSamples(using)
hops, result = getHops(samples, n_samples, max_sample, min_sample)
# We get the audio PSNR
print ""
calculatePSNR(result, samples, n_samples)
print ""
# Binary encoder
sym = getSymbols(hops)
writeFile(sym, samples[0], n_samples, max_sample, min_sample)
print ".lhe file created."
# --- DECODER --- #
elif function == "dec":
# Lhe file path
path = "output_lhe/lhe_file.lhe"
# Binary decoder
n_sym, first_amp, n_samples, max_sample, min_sample = getData(path)
sym = getSymbolsList(path, n_sym, n_samples)
# Audio decoder
hops = symbolsToHops(sym)
samples = hopsToSamples(hops, first_amp, n_samples, max_sample, min_sample)
getAudio(samples)
print "Output audio file created."
# --- EXIT --- #
elif function == "exit":
print ''
sys.exit(1)