Mid-Side to stereo Conversion with a width control.
It is a pure function with no side effects.
The ms2st opcode decodes the MS stereo signal, but it also opens up the possibility to adjust the stereo width for every stereo sound; A stereo file can be encoded, using the st2ms opcode, and then decoded by ms2st. It is then possible to adjust the stereo width.
Syntax
aleft,arightms2stam,as,kwidth
Performance
aleft -- left channel output.
aright -- right channel output.
am -- mid signal input.
as -- side signal input.
kwidth -- stereo width (0 to 1). At 0, no side signal is output, and at 1 no mid signal is present. A value of 0.5 restores a stereo to MS conversion (st2ms) exactly.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if RT audio input is needed too; For Non-realtime ouput leave only the line below:; -o ms2st.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1; by Menno Knevel - 2021; sample = ambient sound of waterfall + animals (monkey, birds)instr1; MS sample is interleavedam,asdiskin2"MSjungle_interleaved.wav",1,0,1; interleaved stereo, MS encodedkwidth=p4; left = M, right = Sal,arms2stam,as,kwidthoutsal,arendininstr2; 2 separate samples amdiskin2"MSjungleMid.wav",1; M sound as a separate mono soundasdiskin2"MSjungleSide.wav",1; S sound as a separate mono soundkwidth=p4al,arms2stam,as,kwidthoutsal,arendin</CsInstruments><CsScore>i106.70; M onlyi1+6.7.3; M and a bit of Si1+6.7.5; M + S equal volumei1+6.71; S only i2286.70; M onlyi2+6.7.3; M and a bit of Si2+6.7.5; M + S equal volumei2+6.71; S onlye</CsScore></CsoundSynthesizer>
In instr 1 of the example, the encoded MS stereo file is interleaved. The left channel of this interleaved signal will be decoded as the M (=Mid) signal. The right channel will be decoded as Left and Right. In instr 2 however, two separate channels are used. The user decides which one will be appointed as the middle signal (M) and the side signal (S).
on top the interleaved encoded MS file (instr 1), at the bottom are the two separate files (instr 2)