forked from YeraySG/BinauralUpmixAmbienceBased
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
111 lines (80 loc) · 3.66 KB
/
Main.py
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
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 24 18:29:47 2019
Main file used to call the functions to run the code
@author: u114293
"""
import matplotlib.pyplot as plt
from Functions import readwav, STFTcomputation,InverseSTFT, AutoCorr, CrossCorr, CrossCorrCoeff, AlphaCom, EqualRatios,AddNoise,CnstPwrPanning,Audiowrite,AmbienceEqualLevels,EqLevelMask,EqualLevels
import numpy as np
import scipy.signal as sp
AmbiencePath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\AudioResults\\EqualRatios\\Ambience\\Ambience - Jambú.wav'
DirectPath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\AudioResults\\EqualRatios\\Direct\\Direct - Jambú.wav'
AmbienceElPath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\AudioResults\\EqualLevels\\Ambience\\AmbienceEL - Jambú.wav'
DirectElPath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\AudioResults\\EqualLevels\\Direct\\DirectEL - Jambú.wav'
SongPath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\Music\\JungleFire-Jambú.wav'
MusicPath = 'C:\\Users\\Yeray\\Documents\\GitHub\\TFG\\Music\\Jambú_Cut.wav'
#Xl,Xr,Samplerate= readwav('speech-female_Stereo_Lowered.wav')
# Xl,Xr,Samplerate= readwav('R&T.wav')
Xl,Xr,Samplerate= readwav(SongPath)
Xl = Xl[:40*Samplerate]
Xr = Xr[:40*Samplerate]
'Check for zeros'
NewXl = AddNoise (Xl)
NewXr = AddNoise (Xr)
plt.figure()
plt.plot(NewXl, label='Left Chanel Signal')
plt.plot(NewXr, label='Right Chanel Signal')
plt.title('Input signal')
plt.xlabel('Samples')
plt.ylabel('Amplitude')
plt.legend()
plt.show()
'Panning'
#PAudio,PXl,PXr = CnstPwrPanning(NewXl,0)
#
#
#plt.figure()
#plt.plot(PXr, label='Panned Right Chanel Signal')
#plt.plot(PXl, label='Panned Left Chanel Signal')
#plt.title('Panned signal')
#plt.xlabel('Samples')
#plt.ylabel('Amplitude')
#plt.legend()
#plt.show()
#PannedAudio = Audiowrite(PXr,PXl,Samplerate,'PannedAudio_45.wav')
'STFT and Correlation'
#STFTXl, STFTXr = STFTcomputation(PXl,PXr,Samplerate)
STFTXl, STFTXr = STFTcomputation(NewXl,NewXr,Samplerate)
Rll = AutoCorr (STFTXl,0.7)
Rrr = AutoCorr (STFTXr,0.7)
CrossCorrLR = CrossCorr (STFTXl,STFTXr,0.7)
CCCoefficient = CrossCorrCoeff (CrossCorrLR,Rll,Rrr)
'Equal Ratios of Ambience'
AlphaC = AlphaCom (CCCoefficient)
#np.min(AlphaC)
#np.max(AlphaC)
AmbienceL,DirectL = EqualRatios(AlphaC,STFTXl)
AmbienceR,DirectR = EqualRatios(AlphaC,STFTXr)
plt.figure(),plt.pcolormesh(np.power(np.abs(AmbienceL),2)),plt.colorbar(),plt.show()
plt.figure(),plt.pcolormesh(np.power(np.abs(AmbienceR),2)),plt.colorbar(),plt.show()
plt.figure(),plt.pcolormesh(np.power(np.abs(DirectL),2)),plt.colorbar(),plt.show()
plt.figure(),plt.pcolormesh(np.power(np.abs(DirectR),2)),plt.colorbar(),plt.show()
IAmbienceL,IAmbienceR = InverseSTFT(AmbienceL,AmbienceR,Samplerate)
IDirectL,IDirectR = InverseSTFT(DirectL,DirectR,Samplerate)
Ambience = Audiowrite(IAmbienceL[1],IAmbienceR[1],Samplerate,AmbiencePath)
Direct = Audiowrite(IDirectL[1],IDirectR[1],Samplerate,DirectPath)
plt.figure(),plt.pcolormesh(np.power(np.abs(AmbienceL),2)),plt.colorbar(),plt.show()
'Equal Levels of Ambience'
Ia = AmbienceEqualLevels(Rll,Rrr,CrossCorrLR)
MaskL = EqLevelMask(Ia,Rll)
MaskR = EqLevelMask(Ia,Rrr)
plt.figure(),plt.pcolormesh(MaskL),plt.colorbar(),plt.show()
plt.figure(),plt.pcolormesh(MaskR),plt.colorbar(),plt.show()
AmbienceElL, PrimaryElL = EqualLevels(MaskL,STFTXl)
AmbienceElR, PrimaryElR = EqualLevels(MaskR,STFTXr)
IAmbienceElL,IAmbienceElR = InverseSTFT(AmbienceElL,AmbienceElR,Samplerate)
IPrimaryElL,IPrimaryElR = InverseSTFT(PrimaryElL,PrimaryElR,Samplerate)
AmbienceEl = Audiowrite(IAmbienceElL[1],IAmbienceElR[1],Samplerate,AmbienceElPath)
PrimaryEl = Audiowrite(IPrimaryElL[1],IPrimaryElR[1],Samplerate,DirectElPath)
SongCut = Audiowrite(NewXl,NewXr,Samplerate,MusicPath)