-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoEncodeDecode.py
More file actions
148 lines (139 loc) · 4.11 KB
/
Copy pathDoEncodeDecode.py
File metadata and controls
148 lines (139 loc) · 4.11 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
2026 copyrights Marina Bosi & Rich Goldberg
"""
import time
from features import RMCFeatures
from xrmc import Decode, Encode
def EncodeDecode(
inFilename="input.wav",
outFilename="output.wav",
codedFilename="coded.pac",
nMDCTLines=1024,
nScaleBits=5,
nMantSizeBits=3,
targetBitsPerSample=2.4,
tempo: int = 120,
verbose: bool = True,
features: RMCFeatures = RMCFeatures(),
):
"""Encodes input WAV file inFilename into perceptually coded file
codedFilename and then decodes that file into output WAV file outFilename.
Allowed parameters are the number of indep MDCT lines per block (half the block
length), the number of block floating point scale factor bits, the number of
bits to encode the mantissa bit allocations, and the target bit rate in units
of bits per sample.
"""
if verbose:
print(
"\nRunning the RMC coder ("
+ inFilename
+ " -> "
+ codedFilename
+ " -> "
+ outFilename
+ "):"
)
elapsed = time.time()
Encode(
inFilename,
features,
codedFilename=codedFilename,
nMDCTLines=nMDCTLines,
nScaleBits=nScaleBits,
nMantSizeBits=nMantSizeBits,
targetBitsPerSample=targetBitsPerSample,
tempo=tempo,
verbose=verbose,
)
Decode(
codedFilename,
features,
outFilename=outFilename,
verbose=verbose,
)
elapsed = time.time() - elapsed
if verbose:
print("\nDone with Encode/Decode test\n")
print(elapsed, " seconds elapsed")
if __name__ == "__main__":
# Base feature set
features = RMCFeatures()
# Feature set w/ prediction enabled
features_pred = RMCFeatures(PREDICTION=True)
# Feature set w/ block switching enabled
features_bs = RMCFeatures(BLOCK_SWITCHING=True)
# Block switching and prediction
features_bspred = RMCFeatures(PREDICTION=True, BLOCK_SWITCHING=True)
features_entropy = RMCFeatures(ENTROPY_CODING=True)
features_ecpred = RMCFeatures(ENTROPY_CODING=True, PREDICTION=True)
features_ecbs = RMCFeatures(ENTROPY_CODING=True, BLOCK_SWITCHING=True)
features_all = RMCFeatures(
PREDICTION=True, BLOCK_SWITCHING=True, ENTROPY_CODING=True
)
TARGET_KBPS = 80000
SAMPLE_RATE = 44100
target_bps = TARGET_KBPS / SAMPLE_RATE
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn.rmc",
outFilename="rn_base.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_pred.rmc",
outFilename="rn_pred.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_pred,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_bs.rmc",
outFilename="rn_bs.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_bs,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_bspred.rmc",
outFilename="rn_bspred.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_bspred,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_entropy.rmc",
outFilename="rn_entropy.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_entropy,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_ecpred.rmc",
outFilename="rn_ecpred.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_ecpred,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_ecbs.rmc",
outFilename="rn_ecbs.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_ecbs,
)
EncodeDecode(
inFilename="ringnoord.wav",
codedFilename="rn_all.rmc",
outFilename="rn_all.wav",
targetBitsPerSample=target_bps,
tempo=164,
features=features_all,
)