Fortran · 1247 bytes Raw Blame History
1 module mid_side
2 implicit none
3 contains
4
5 subroutine mid_side_sub(inbuf, outbuf, vocal_gain, n)
6 ! inbuf : real(8) array of length 2*N (interleaved stereo:
7 ! L,R,L(ol),R,...)
8 ! outbuf : real(8) array, same length, to receive processed sam-
9 ! -ples
10 ! vocal_gain : real(8) scalar in [0,1]
11 !
12 !f2py intent(in) :: inbuf, vocal_gain, n
13 !f2py intent(out) :: outbuf
14 !f2py depend(n) :: inbuf, outbuf
15 integer, intent(in) :: n
16 real(8), intent(in) :: inbuf(2*n)
17 real(8), intent(out) :: outbuf(2*n)
18 real(8), intent(in) :: vocal_gain
19 integer :: i
20 real(8) :: L, R, mid, side, out
21
22 do i = 1, n
23 ! extract left and right channels of frame i
24 L = inbuf(2*(i-1) + 1)
25 R = inbuf(2*(i-1) + 2)
26
27 ! capture the mids and stereo-only shite
28 mid = 0.5d0 * (L + R)
29 side = 0.5d0 * (L - R)
30
31 ! if gain is 1.0, both instrumentals and vocals (as mid)
32 ! otherwise 0.0, just instrumental, hope all goes well ;)
33 out = side + vocal_gain * mid
34
35 ! writeback the mixed sample to the bout uffa
36 outbuf(2*(i-1) + 1) = out
37 outbuf(2*(i-1) + 2) = out
38 end do
39 end subroutine mid_side_sub
40
41 end module mid_side