MCPcopy
hub / github.com/ibab/tensorflow-wavenet / mu_law_encode

Function mu_law_encode

wavenet/ops.py:64–75  ·  view source on GitHub ↗

Quantizes waveform amplitudes.

(audio, quantization_channels)

Source from the content-addressed store, hash-verified

62
63
64def mu_law_encode(audio, quantization_channels):
65 '''Quantizes waveform amplitudes.'''
66 with tf.name_scope('encode'):
67 mu = tf.to_float(quantization_channels - 1)
68 # Perform mu-law companding transformation (ITU-T, 1988).
69 # Minimum operation is here to deal with rare large amplitudes caused
70 # by resampling.
71 safe_audio_abs = tf.minimum(tf.abs(audio), 1.0)
72 magnitude = tf.log1p(mu * safe_audio_abs) / tf.log1p(mu)
73 signal = tf.sign(audio) * magnitude
74 # Quantize signal to the specified number of levels.
75 return tf.to_int32((signal + 1) / 2 * mu + 0.5)
76
77
78def mu_law_decode(output, quantization_channels):

Callers 12

create_seedFunction · 0.90
testDecodeEncodeMethod · 0.90
testEncodeDecodeShiftMethod · 0.90
testEncodeDecodeMethod · 0.90
testEncodePrecomputedMethod · 0.90
testEncodeRampMethod · 0.90
testEncodeZerosMethod · 0.90
lossMethod · 0.85

Calls

no outgoing calls

Tested by 10

testDecodeEncodeMethod · 0.72
testEncodeDecodeShiftMethod · 0.72
testEncodeDecodeMethod · 0.72
testEncodePrecomputedMethod · 0.72
testEncodeRampMethod · 0.72
testEncodeZerosMethod · 0.72