- Create a virtualenv
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
Note: Developed and tested on Python 3.7.4
- Run
python3 xsynth.py
Outputs can be found in xsynth/out
- [Optional] Use custom samples
- Move audio samples (e.g. .wav files) to
xsynth/samples
- Change the
sound1
andsound2
arguments tomain
- [Optional] Use your own configuration by creating a
Config
instance and passing it intomain
- Read in two sound files,
s1
ands2
, as numpy arrays - Pad numpy arrays to handle mismatching dimensions (samples of unequal length)
- Shorter sample is looped to match the length of the longer sample
- Run FFT on
s1
ands2
, returning their spectrum with amplitude and frequency information in the frequency domain. The data is in cartesian (complex) coordinates,s1_cart
ands2_cart
- Convert to polar to extract the amplitude and phase individually, returning
s1_amp
,s1_phase
,s2_amp
,s2_phase
. - Filter noise based on threshold,
noise_threshold
- Apply cross-synthesis combination to produce the output spectrum,
out_amp
andout_phase
using the weightsX
,x
,Q
,Y
,y
:
-
Convert output spectrum from polar to cartesian (complex) coordinates,
out_cart
. -
Transform the output specturm from the frequency domain to a signal in the time domain using inverse FFT.
-
Write the resulting numpy array into a .wav file. We are done!
- All the high-level algorithm steps are executed in
xsynth.py
- The nitty-gritty of the specific steps such as coordinate conversion and noise filtration is handled in
utils.py
- Originally wrote a lot of the mathematical conversion functions myself and vectorized them to apply to numpy arrays, but deprecated them in favor of using the built-in
np.abs
andnp.angle
(for amplitude and phase respectively)
- Originally wrote a lot of the mathematical conversion functions myself and vectorized them to apply to numpy arrays, but deprecated them in favor of using the built-in
- The configuration system is also handled in
utils.py
. Users can create new configurations for the cross-synthesis by creating newConfig
objects and passing them intomain
.utils.py
also exports a few default configurations:SOUND_1
,SOUND_2
,HYBRID_1
,HYBRID_2
,HYBRID_3
.
- Lastly, auxiliary tasks such as file writing is done
utils.py
- See the
xsynth/examples
directory (link)