Skip to content

A PyTorch implementation of the Modified Discrete Cosine Transform (MDCT) and its inverse for audio processing.

License

Notifications You must be signed in to change notification settings

Kinyugo/torch_mdct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

torch_mdct

A PyTorch implementation of the Modified Discrete Cosine Transform (MDCT) and its inverse for audio processing.

Installation

pip install torch_mdct

Usage

import torchaudio
from torch_mdct import IMDCT, MDCT, kaiser_bessel_derived, vorbis

# Load a sample waveform 
waveform, sample_rate = torchaudio.load("/path/to/audio.file")

# Initialize the mdct and imdct transforms
mdct = MDCT(win_length=1024, window_fn=vorbis, window_kwargs=None, center=True)
imdct = IMDCT(win_length=1024, window_fn=vorbis, window_kwargs=None, center=True)

# Transform waveform into mdct spectrogram
spectrogram = mdct(waveform)

# Transform spectrogram back to audio 
reconst_waveform = imdct(spectrogram)

# Compute the differences
print(f"L1: {(waveform - reconst_waveform).abs().mean()}")

References

[1] Zaf-Python: Zafar's Audio Functions in Python for audio signal analysis.

[2] MDCT: A fast MDCT implementation using SciPy and FFTs.

About

A PyTorch implementation of the Modified Discrete Cosine Transform (MDCT) and its inverse for audio processing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published