Csound Csound-dev Csound-tekno Search About

[Csnd] [perti@telefax.com.ar: ambisonics orcs]

Date1999-11-08 17:26
Fromjpff@maths.bath.ac.uk
Subject[Csnd] [perti@telefax.com.ar: ambisonics orcs]
------- Start of forwarded message -------
Date: Mon, 08 Nov 1999 12:02:41 -0300
From: "M. Perticone" 
To: rwd@cableinet.co.uk, Csound List 
Subject: ambisonics orcs
Content-Type: text/plain; charset=us-ascii

hello mr. dobson and csound-list,
this is a long post, sorry about that. there are three orcs included.

Richard Dobson wrote:

> Re Ambisonics - I ~can~ use a quad output (either for B-Format signals,
> or a first-order horizontal decode - there is a Csound Score and
> instrument available to demonsrate this somewhere (Bath server?).

here is malham & myatt's encoder and decoder orcs for ambisonics, 
i hope they doesn't mind. they are taken from their "3-D Sound 
Spatialization using Ambisonic Techniques" article from Computer Music 
Journal, pp 58-70, Winter 1995. 
just horizontal plane

;--------------------------------------------------------------------
;*************************************
;*   Ambisonic Encoding Orchestra    *
;* p4 = pitch; p5 = amplitude        *
;* p6 = start angle from center front*
;* p7 = end angle from center front  *
;* p8 = start angle from horizontzal *
;* p9 = end angle from horizontal    *
;* (all angles expressed in radians) *
;*************************************

sr=	44100
kr=	441
ksmps=	100
nchnls= 4

instr 1
	; Linear transformation
	;between start and end angles
kone line p6, p3, p7
ktwo line p8, p3, p9

	; envelope for sound source
kenv linen p5, 0.008, p3, 0.02
a5 oscili kenv, cpspch(p4), 1		

	; calculate cos and sin of
	; time-varying angles
kca = cos(kone)
ksa = sin(kone)
kcb = cos(ktwo)
ksb = sin(ktwo)	

	; B-format encoding equations
ax = a5 * kca * kcb
ay = a5 * ksa * kcb
az = a5 * ksb
aw = a5 * 0.707

	; B-format output
outq ax, ay, az, aw		

endin
;--------------------------------------------------------------------
;*************************************
;*   Ambisonic Decoding Orchestra    *
;*************************************

sr=	44100
kr=	441
ksmps=	100
nchnls= 4

instr 2
	; Read sound in from file
	
ax, ay, az, aw		soundin "your encoded file here"


	; Decode equatios producing 4
	; speaker feed signals for
	; horizontal-only playback
a1 = aw + (ax * 0.707) + (ay * 0.707)
a2 = aw + (ax * 0.707) - (ay * 0.707)
a3 = aw - (ax * 0.707) - (ay * 0.707)
a4 = aw - (ax * 0.707) + (ay * 0.707)

	; output speaker signals
outq a1, a2, a3, a4

endin
;--------------------------------------------------------------------

> However, it can also use many more, e.g a cube of eight speaker for full
> 3D periphony including height. Strictly speaking, audio presented on the
> horizontal plane is 2D, "3D" should be reserved for representations
> including height. However, most manufactures and developers are tending
> to use the term 3D for just horizontal presentation!

well, i'm trying to do "with-height" enc-decoding in csound. and i will
need some help here. if anyone with better knowledge on maths and
csound can check the following orc i shall be very grateful.
note that i tried to merge both encoding and decoding in only one file,
and it's not fully tested. any advice is gratefully welcome.

;----------------------------------------------------------------------
;*************************************
;*   Ambisonics Enc-Dec Orchestra    *
;*     (with-height decoding)        *
;*  written by marcelo perticone     *
;* after d.g. malham & a. myatt's    *
;*       ambisonics orcs             *
;*                                   *
;* p4 = pitch; p5 = amplitude        *
;* p6 = start angle from center front*
;* p7 = end angle from center front  *
;* p8 = start angle from horizontzal *
;* p9 = end angle from horizontal    *
;* (all angles expressed in radians) *
;*************************************

sr=	44100
kr=	2205
ksmps=	20
nchnls= 8

instr 1
	; Linear transformation
	;between start and end angles
kHorizAng line p6, p3, p7
kVertAng  line p8, p3, p9

	; sound source just for testing
kenv linen p5, 0.008, p3, 0.02 ; envelope
aSource oscili kenv, cpspch(p4), 1 ; write any gen10 table to .sco	

	; calculate cos and sin of
	; time-varying angles
kcH = cos(kHorizAng)
ksH = sin(kHorizAng)
kcV = cos(kVertAng)
ksV = sin(kVertAng)	

	
	; B-format encoding equations

ax = aSource * kcH * kcV
ay = aSource * ksH * kcV
az = aSource * ksV
aw = aSource * 0.707106

	; B-format decoding equations
	
a1 = aw + (ax * 0.707106) + (ay * 0.707106) + (az * 0.707106) ;Upper Front Left
a2 = aw + (ax * 0.707106) - (ay * 0.707106) + (az * 0.707106) ;Upper Front Right
a3 = aw - (ax * 0.707106) + (ay * 0.707106) + (az * 0.707106) ;Upper Back  Left
a4 = aw - (ax * 0.707106) - (ay * 0.707106) + (az * 0.707106) ;Upper Back  Right
a5 = aw + (ax * 0.707106) + (ay * 0.707106) - (az * 0.707106) ;Lower Front Left
a6 = aw + (ax * 0.707106) - (ay * 0.707106) - (az * 0.707106) ;Lower Front Right
a7 = aw - (ax * 0.707106) + (ay * 0.707106) - (az * 0.707106) ;Lower Back  Left
a8 = aw - (ax * 0.707106) - (ay * 0.707106) - (az * 0.707106) ;Lower Back  Right


	; output speaker signals
;	UFL	UFR	UBL	UBR	LFL	LFR	LBL	LBR (map)
outo 	a1, 	a2, 	a3, 	a4, 	a5, 	a6, 	a7, 	a8

endin
;--------------------------------------------------------------

interested people in the list may also check mr. richard furse's
webpage. 
he wrote an ambisonics player for b-format file decoding with many 
speaker-array options, and a command-line decoder program.
go to http://www.muse.demon.co.uk/3daudio.html for lots of updated 
ambisonics info.

thanks,
marcelo
------- End of forwarded message -------
--