A-law companding and quantization processing for WAV audio files
Project description
a_law_lib is a Python library designed to perform A-law companding, quantization, and WAV audio processing. It provides core functions for compressing and reconstructing signals, useful in digital audio signal processing and educational simulations.
It mainly comes with four functions: a_law_encode(), a_law_decode(), quantize(), and process_wave_file().
a_law_encode(signal, A=87.6):
Perform A-law companding on the input signal.
Parameters:
- signal (numpy.ndarray): Input signal to be encoded.
- A (float, optional): Companding parameter (default is 87.6).
Returns:
- numpy.ndarray: A-law encoded signal.
a_law_decode(companded_signal, A=87.6):
Decode an A-law companded signal.
Parameters:
- companded_signal (numpy.ndarray): Encoded signal.
- A (float, optional): Companding parameter (same as used in encoding).
Returns:
- numpy.ndarray: Decoded signal approximating the original input.
quantize(signal, num_levels):
Apply uniform quantization to the input signal.
Parameters:
- signal (numpy.ndarray): Input signal to be quantized.
- num_levels (int): Number of quantization levels.
Returns:
- numpy.ndarray: Quantized signal.
process_wave_file(file_path, output_path, A=87.6, num_levels=16):
Read a WAV file, apply A-law encoding, quantization, decoding, and save the output.
Parameters:
- file_path (str): Path to the input WAV file.
- output_path (str): Destination path for the processed WAV file.
- A (float, optional): Companding parameter (default is 87.6).
- num_levels (int, optional): Number of quantization levels (default is 16).
Returns:
- None. Writes processed audio to the specified output path.
Features:
- A-law companding and reconstruction.
- Uniform quantization.
- Works with mono and stereo WAV files.
- Handles both integer and floating-point audio data.
Sample usage:
import a_law_lib as al
import numpy as np
signal = np.linspace(-1.0, 1.0, 100)
encoded = al.a_law_encode(signal)
decoded = al.a_law_decode(encoded)
quantized = al.quantize(decoded, num_levels=16)
al.process_wave_file("input.wav", "output.wav", A=87.6, num_levels=16)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file a_law_lib-0.2.0.tar.gz.
File metadata
- Download URL: a_law_lib-0.2.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
badb21678c0f2d3a4f18ab32d1fd5dc9bbe82b3f26e820f10dbdf3ef229cf0a4
|
|
| MD5 |
4cba9b08df25e8a382c81bba2fbef70d
|
|
| BLAKE2b-256 |
6d7ff1fc81560c0b4f59ed47d091c5c36ce13fa6e09cb211100d569f92f8e308
|
File details
Details for the file a_law_lib-0.2.0-py3-none-any.whl.
File metadata
- Download URL: a_law_lib-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a88e6631c5c23e216adc12c6920b3c0ba2149f76b93e82d443b134de164f9eb6
|
|
| MD5 |
654674c980c65a7fa58d46576e80c993
|
|
| BLAKE2b-256 |
74fbb2d7d9b4eab76a68b8a1c6d1c0074ba398df888b5fbcf501a441a9c139b0
|