<CsoundSynthesizer>

;
; Bohlen-Pierce Scale
; -------------------
; a Pitch Class Converter
; implemented using Csound's Python opcodes
;
; version 1.1.0
; 
; Bruce H. McCosar
; 
; $Id: cpsbpconv.csd 34 2008-04-25 23:03:39Z mccosar $
;
; Changes:
;
; -- 1.1.0: Changed pitch correlation standard to that
; suggested on the Bohlen-Pierce site (see below). Also
; a new demo, featuring the modes of the Lambda scale.
;
 
<CsOptions>
-d -W -o bpdemo.wav
</CsOptions>
 
<CsInstruments>

; ------------------------------------------------------------ HEADER
sr	=	44100
kr	=	4410
ksmps	=	10
nchnls	=	2

pyinit	; The quicker picker upper.

pyruni {{

"""
The pitch correlation standard suggested on the Bohlen-Pierce
Site[1] is that the tritave below 'middle A' (BP pitch class 10)
should correspond to the lowest 'E' on the guitar, about 82.4 Hz.

Compositionally, it might be useful to redefine the tritave
names in the following manner:

T.pc
----
0.10 = BP contrabass A, two tritaves below BP middle A, 27.46896 Hz:
       equivalent to lowest 'A' on the piano (A0).
1.10 = BP bass A, one tritave below BP middle A, 82.40689 Hz:
       exactly equal to low 'E' on the guitar (E2).
2.10 = BP middle A, 247.22066 Hz:
       just above the B below middle C on the piano (B3)
3.00 = BP middle C, 318.5588537 Hz (used as the definition below)
3.10 = BP treble A, one tritave above BP middle A, 741.66200 Hz.

These, then, are the note names and corresponding pitch classes
for each tritave (Lambda scale[2] shown)

                                           (10)(11)(12)
    0   1   2   3   4   5   6   7   8   9   A   B   C
   --- --- --- --- --- --- --- --- --- --- --- --- ---
    C       D   E   F       G   H       J   A       B

[1] http://members.aol.com/bpsite/tuning.html#anchor56508
[2] http://members.aol.com/bpsite/modes.html#anchor194521
"""

REFERENCE_FREQUENCY = 318.5588537 # BP middle C

def cpsbpet(tritave,pitchclass):
	"""
	Return cycles-per-second given the tritave and
	the pitch class for a note in the Bohlen-Pierce
	scale (equal tempered version) -- 00 to 12.
	"""
	t = tritave - 3
	n = t + pitchclass / 13.0
	cps = REFERENCE_FREQUENCY * (3**n)
	return cps

INTONATION = """
1/1
27/25
25/21
9/7
7/5
75/49
5/3
9/5
49/25
15/7
7/3
63/25
25/9
""".split()

def cpsbpji(tritave,pitchclass):
	"""
	Return cycles-per-second given the tritave and
	the pitch class for a note in the Bohlen-Pierce
	scale (just intonation version) -- 00 to 12.
	"""
	t = tritave - 3
	f = REFERENCE_FREQUENCY * (3**t)
	a,b = INTONATION[int(pitchclass)].split('/')
	cps = f * int(a) / int(b)
	return cps

}}

; ------------------------------------------------------- INSTRUMENTS

garvL	init	0
garvR	init	0

	instr	101
iamp	=	ampdbfs(p4)*1.1
icps	pycall1i "cpsbpji", int(p5), frac(p5)*100
ipan	=	0.5+(log(icps)-6.10)/3
;
asig	vibes	iamp, icps, 0.5, 0.5, 1, 6.08, 0.03, 1, 0.1
kenv	linen	1, 0.01, p3, 0.01
aL, aR	pan2	asig*kenv, ipan
;
	outs	aL, aR
garvL	=	aL + garvL
garvR	=	aR + garvR
	endin

	instr	201
ifblvl	=	p4
ifco	=	p5
aL, aR	reverbsc garvL, garvR, ifblvl, ifco
	outs	aL, aR
garvL	=	0
garvR	=	0
	endin

</CsInstruments>

<CsScore>

; ---------------------------------------------------------- F-TABLES

; Table #1, the "marmstk1.wav" audio file.
f 1	0	256	1	"marmstk1.wav"	0	0	0
; Table #2, a sine wave for the vibrato.
f 2	0	128	10	1

; ------------------------------------------------------------- SCORE

; inst	time	dur	fblvl	fco
i 201	0	58	0.605	10000

; inst	time	dur	dBfs	T.pc
i 101	0.0016	0.4752	-4.99	3.06
i 101	0.0166	0.7693	-5.02	3.00
i 101	0.5370	0.2607	-8.04	3.07
i 101	0.7503	0.5004	-5.99	3.04
i 101	0.7574	0.7484	-7.02	3.00
i 101	1.2794	0.2734	-9.04	3.07
i 101	1.5110	0.5046	-5.00	3.03
i 101	1.5069	0.7289	-6.00	3.00
i 101	2.0010	0.5058	-5.97	3.02
i 101	2.2666	0.7397	-7.97	3.00
i 101	2.5394	0.2380	-11.97	3.03
i 101	2.7674	0.2715	-9.96	3.04
				
; inst	time	dur	dBfs	T.pc				
i 101	3.0321	0.4844	-5.03	3.06
i 101	3.0379	0.7341	-4.98	3.00
i 101	3.5176	0.2268	-8.03	3.07
i 101	3.7828	0.4974	-6.03	3.04
i 101	3.7884	0.7364	-6.99	3.00
i 101	4.2613	0.2294	-9.00	3.07
i 101	4.5372	0.4784	-4.96	3.03
i 101	4.5255	0.7618	-5.99	3.00
i 101	5.0137	0.5224	-6.01	3.02
i 101	5.2517	0.7550	-8.01	3.00
i 101	5.5454	0.2729	-12.02	3.03
i 101	5.7535	0.2350	-10.04	3.04
				
; inst	time	dur	dBfs	T.pc				
i 101	6.0361	0.5174	-5.05	3.06
i 101	6.0454	0.7717	-5.03	3.00
i 101	6.5404	0.2426	-8.03	3.07
i 101	6.7796	0.5169	-5.98	3.04
i 101	6.7562	0.7606	-6.97	3.00
i 101	7.2788	0.2666	-8.96	3.07
i 101	7.5182	0.4931	-4.97	3.03
i 101	7.5375	0.7310	-5.96	3.00
i 101	8.0401	0.4786	-6.02	3.02
i 101	8.2638	0.7557	-8.03	3.00
i 101	8.5149	0.2253	-12.05	3.03
i 101	8.7773	0.2676	-10.04	3.04
				
; inst	time	dur	dBfs	T.pc
i 101	9.0104	0.4937	-5.05	3.06
i 101	9.0114	0.7273	-5.03	3.00
i 101	9.5028	0.2619	-8.02	3.07
i 101	9.7736	0.4972	-5.95	3.04
i 101	9.7933	0.7415	-7.03	3.00
i 101	10.2665	0.2711	-8.97	3.07
i 101	10.5261	0.5247	-4.97	3.03
i 101	10.5121	0.7731	-6.02	3.00
i 101	11.0182	0.4801	-5.98	3.02
i 101	11.2961	0.7518	-8.02	3.00
i 101	11.5345	0.2713	-12.03	3.03
i 101	11.7636	0.2419	-9.97	3.04

; inst	time	dur	dBfs	T.pc
i 101	12.0482	0.5186	-4.96	3.10
i 101	12.0475	0.7256	-5.01	3.03
i 101	12.5170	0.2670	-7.99	3.12
i 101	12.7882	0.4767	-6.04	3.09
i 101	12.7512	0.7266	-7.04	3.03
i 101	13.2532	0.2304	-9.04	3.12
i 101	13.5458	0.4832	-4.96	3.07
i 101	13.5033	0.7610	-6.00	3.03
i 101	14.0485	0.4771	-6.02	3.06
i 101	14.2862	0.7508	-8.05	3.03
i 101	14.5329	0.2529	-12.02	3.07
i 101	14.7547	0.2627	-10.04	3.05

; inst	time	dur	dBfs	T.pc
i 101	15.0150	0.4923	-4.96	3.10
i 101	15.0011	0.7710	-5.05	3.03
i 101	15.5422	0.2686	-7.95	3.12
i 101	15.7551	0.4960	-6.03	3.09
i 101	15.7649	0.7517	-7.03	3.03
i 101	16.2571	0.2689	-8.95	3.12
i 101	16.5324	0.4886	-5.02	3.07
i 101	16.5253	0.7704	-6.03	3.03
i 101	17.0185	0.5213	-6.03	3.06
i 101	17.2852	0.7254	-7.99	3.03
i 101	17.5489	0.2426	-12.03	3.07
i 101	17.7618	0.2377	-10.01	3.05
				
; inst	time	dur	dBfs	T.pc
i 101	18.0016	0.5216	-5.02	3.10
i 101	18.0250	0.7422	-4.95	3.03
i 101	18.5239	0.2358	-7.97	3.12
i 101	18.7698	0.4767	-6.04	3.09
i 101	18.7711	0.7691	-7.02	3.03
i 101	19.2585	0.2322	-8.95	3.12
i 101	19.5334	0.4935	-4.97	3.07
i 101	19.5192	0.7627	-6.03	3.03
i 101	20.0059	0.4828	-6.01	3.06
i 101	20.2504	0.7355	-8.00	3.03
i 101	20.5075	0.2644	-12.01	3.07
i 101	20.7572	0.2344	-10.00	3.05

; inst	time	dur	dBfs	T.pc
i 101	21.0036	0.4909	-5.00	3.10
i 101	21.0033	0.7726	-5.03	3.03
i 101	21.5104	0.2704	-8.05	3.12
i 101	21.7521	0.4930	-5.96	3.09
i 101	21.7895	0.7483	-7.03	3.03
i 101	22.2933	0.2484	-9.02	3.12
i 101	22.5068	0.4806	-4.95	3.07
i 101	22.5045	0.7656	-6.04	3.03
i 101	23.0444	0.4944	-6.02	3.06
i 101	23.2991	0.7743	-7.95	3.03
i 101	23.5096	0.2366	-12.02	3.07
i 101	23.7593	0.2711	-10.00	3.05

; inst	time	dur	dBfs	T.pc
i 101	24.0061	0.5182	-3.95	3.06
i 101	24.0420	0.7502	-5.99	3.00
i 101	24.5347	0.2665	-6.98	3.07
i 101	24.7746	0.5144	-5.03	3.04
i 101	24.7772	0.7506	-8.03	3.00
i 101	25.2835	0.2340	-7.96	3.07
i 101	25.5364	0.4772	-4.99	3.03
i 101	25.5288	0.7472	-6.00	3.00
i 101	26.0085	0.5013	-6.96	3.02
i 101	26.2604	0.7380	-9.01	3.00
i 101	26.5486	0.2488	-10.00	3.03
i 101	26.7796	0.2453	-9.03	3.04

; inst	time	dur	dBfs	T.pc
i 101	27.0188	0.4952	-4.01	3.06
i 101	27.0320	0.7674	-6.01	3.00
i 101	27.5488	0.2330	-7.01	3.07
i 101	27.7748	0.5030	-4.97	3.04
i 101	27.7824	0.7279	-7.97	3.00
i 101	28.2563	0.2724	-7.97	3.07
i 101	28.5319	0.5124	-5.02	3.03
i 101	28.5360	0.7437	-6.01	3.00
i 101	29.0096	0.5200	-6.95	3.02
i 101	29.2923	0.7578	-9.02	3.00
i 101	29.5381	0.2617	-10.03	3.03
i 101	29.7991	0.2433	-9.03	3.04

; inst	time	dur	dBfs	T.pc
i 101	30.0356	0.4812	-3.99	3.06
i 101	30.0449	0.7673	-6.03	3.00
i 101	30.5035	0.2339	-7.02	3.07
i 101	30.7800	0.5006	-4.96	3.04
i 101	30.7940	0.7666	-8.03	3.00
i 101	31.2631	0.2455	-7.99	3.07
i 101	31.5394	0.4967	-5.01	3.03
i 101	31.5001	0.7598	-6.03	3.00
i 101	32.0051	0.5207	-7.03	3.02
i 101	32.2741	0.7381	-9.03	3.00
i 101	32.5247	0.2492	-10.01	3.03
i 101	32.7823	0.2463	-9.01	3.04

; inst	time	dur	dBfs	T.pc
i 101	33.0076	0.4972	-4.04	3.06
i 101	33.0112	0.7514	-6.05	3.00
i 101	33.5111	0.2685	-6.96	3.07
i 101	33.7661	0.5234	-4.96	3.04
i 101	33.7716	0.7644	-8.01	3.00
i 101	34.2597	0.2423	-8.01	3.07
i 101	34.5457	0.4938	-5.04	3.03
i 101	34.5404	0.7346	-5.97	3.00
i 101	35.0417	0.4847	-6.97	3.02
i 101	35.2946	0.7517	-9.00	3.00
i 101	35.5152	0.2627	-9.99	3.03
i 101	35.7741	0.2375	-8.99	3.04

; inst	time	dur	dBfs	T.pc
i 101	36.0009	0.4991	-4.02	3.03
i 101	36.0471	0.7500	-5.96	2.10
i 101	36.5101	0.2563	-6.95	3.04
i 101	36.7605	0.4941	-5.03	3.02
i 101	36.7894	0.7329	-8.03	2.10
i 101	37.2982	0.2430	-8.03	3.04
i 101	37.5095	0.5124	-5.01	3.00
i 101	37.5250	0.7391	-5.97	2.10
i 101	38.0431	0.4853	-7.01	2.12
i 101	38.2630	0.7713	-8.97	2.10
i 101	38.5050	0.2647	-9.98	3.00
i 101	38.7871	0.2269	-8.99	3.02

; inst	time	dur	dBfs	T.pc
i 101	39.0261	0.4918	-4.01	3.03
i 101	39.0444	0.7363	-6.04	2.10
i 101	39.5372	0.2617	-6.97	3.04
i 101	39.7812	0.4875	-4.99	3.02
i 101	39.7685	0.7495	-8.02	2.10
i 101	40.2619	0.2359	-8.03	3.04
i 101	40.5135	0.5089	-5.05	3.00
i 101	40.5261	0.7716	-6.01	2.10
i 101	41.0231	0.5123	-7.03	2.12
i 101	41.2747	0.7523	-8.96	2.10
i 101	41.5422	0.2701	-10.02	3.00
i 101	41.7947	0.2518	-8.99	3.02

; inst	time	dur	dBfs	T.pc
i 101	42.0344	0.5196	-4.02	3.03
i 101	42.0379	0.7388	-6.01	2.10
i 101	42.5351	0.2614	-7.01	3.04
i 101	42.7761	0.4793	-5.05	3.02
i 101	42.7825	0.7656	-7.96	2.10
i 101	43.2502	0.2491	-7.95	3.04
i 101	43.5003	0.4918	-4.99	3.00
i 101	43.5334	0.7397	-6.04	2.10
i 101	44.0473	0.5241	-6.96	2.12
i 101	44.2604	0.7731	-8.99	2.10
i 101	44.5439	0.2588	-10.01	3.00
i 101	44.7867	0.2320	-9.05	3.02

; inst	time	dur	dBfs	T.pc
i 101	45.0086	0.4910	-3.97	3.03
i 101	45.0034	0.7462	-5.97	2.10
i 101	45.5117	0.2460	-6.97	3.04
i 101	45.7517	0.5013	-5.03	3.02
i 101	45.7664	0.7425	-7.99	2.10
i 101	46.2667	0.2357	-8.00	3.04
i 101	46.5388	0.5032	-4.97	3.00
i 101	46.5426	0.7593	-5.95	2.10
i 101	47.0111	0.4970	-6.99	2.12
i 101	47.2760	0.7399	-8.99	2.10
i 101	47.5238	0.2719	-9.99	3.00
i 101	47.7796	0.2715	-8.96	3.02

; inst	time	dur	dBfs	T.pc
i 101	48.0379	0.5008	-3.97	3.06
i 101	48.0374	0.7557	-5.99	3.00
i 101	48.5057	0.2681	-7.03	3.07
i 101	48.7610	0.4881	-4.95	3.04
i 101	48.7620	0.7330	-8.00	3.00
i 101	49.2979	0.2632	-8.00	3.07
i 101	49.5057	0.5148	-5.00	3.03
i 101	49.5464	0.7276	-5.97	3.00
i 101	50.0359	0.4770	-6.96	3.02
i 101	50.2908	0.7512	-8.96	3.00
i 101	50.5226	0.2319	-9.97	3.03
i 101	50.7684	0.2676	-8.97	3.04
i 101	51.0410	0.4753	-5.96	3.06
i 101	51.0228	0.7487	-8.01	3.00
i 101	51.5018	0.2323	-7.95	3.07
i 101	51.7883	0.5244	-6.97	3.04
i 101	51.7832	0.7468	-10.05	3.00
i 101	52.2957	0.2661	-10.02	3.07
i 101	52.5249	0.4814	-7.97	3.03
i 101	52.5418	0.7629	-7.97	3.00
i 101	53.0491	0.4873	-9.03	3.02
i 101	53.2866	1.5024	-10.99	3.00
i 101	53.5436	0.2392	-13.05	3.03
i 101	53.7655	3.0048	-14.98	3.04

e

</CsScore>

<CsFileB filename=marmstk1.wav>
UklGRiQCAABXQVZFZm10IBAAAAABAAEAIlYAAESsAAACABAAZGF0YQACAAAUAI//CwIt+w0I
lhUI42n9MAIyBJwDlvccDazur/RUEb0E3AP//Hz5bw9n4xweGto7MXPRZBrYCWjePidR0/ot
/NgTFOQC2/c7AiMD6/3L+PgLEvKVG5TSkijr6qkDKgzL6gEcZeFoF6P84P2a+k8KNfApCUH9
7v9DCuTniR3y6UUEPg6t7y8Pje7QCF4F2+8rEdH84PODEfjt3Q+29bD7cxUL52MTk/pW/PMD
0fUbCXQDUPYYDjX2cfoUCEPzoBH39AkG4QIa9A0JUvte/44GjfpkBeL84/qSCujzDQW+BCn4
WQoF98IEIAEA9goMzfk8AZkC2vvMAkb9wPsVDYT0xAbO//32Aw6q8uQOffZv/9oHY/RDBwn+
qv6EAggAyP1gCKnwgA1t+eH8AQs7854PWPPgBGUE3PYPBcr9yP8GBHP8sAG6AUX1Qg0d+HQD
qgTt9W8LbPR3BH8CBvcgDez2FAWfAu/1Uggj+o4DjQGY/QACnv6B+vQHzvueAJoDVvf/Ce73
BgWUAU75hgna92YEwgFX+m4F9fmNAqEC5/o8BrT80/3sBNT44Qcq/gv9owYP950F3/1MAFIE
6vq2Aqv+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA
</CsFileB>

</CsoundSynthesizer>
