ms2st

ms2st — Mid-Side to stereo Conversion.

Description

This opcode implements mid-side (MS) 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,aright ms2st as,am,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.

Examples

Here is an example of the ms2st opcode. It uses the files Play ms2st.csd, MSjungle_interleaved.wav, MSjungleMid.wav and MSjungleSide.wav

Example 639. Example of the ms2st opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<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 = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

; by  Menno Knevel - 2021
; sample = ambient sound of waterfall + animals (monkey, birds)

instr 1 ; MS sample is interleaved

am, as    diskin2    "MSjungle_interleaved.wav", 1, 0, 1 ; interleaved stereo, MS encoded
kwidth = p4                                              ; left = M, right = S
al, ar ms2st  am, as, kwidth
outs al, ar
endin

instr 2 ; 2 separate samples 

am    diskin2    "MSjungleMid.wav", 1        ; M sound as a separate mono sound
as    diskin2    "MSjungleSide.wav", 1       ; S sound as a separate mono sound
kwidth = p4     
al, ar ms2st  am, as, kwidth
outs al, ar

endin
</CsInstruments>
<CsScore>

i1 0 6.7 0          ; M only
i1 + 6.7 .3         ; M and a bit of S
i1 + 6.7 .5         ; M + S equal volume
i1 + 6.7 1          ; S only 

i2 28 6.7 0         ; M only
i2 +  6.7 .3        ; M and a bit of S
i2 +  6.7 .5        ; M + S equal volume
i2 +  6.7 1         ; S only
e
</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)

on top the interleaved encoded MS file (instr 1), at the bottom are the two separate files (instr 2)

See Also

More information on MS stereo can be found on the Wikipedia page

st2ms

Credits

Author: Victor Lazzarini
April 2021