JavaScript 函式筆記
喔要做法令易讀器於是翻了JavaScript的文章,筆記一些如下:
......
... read more
我不了解瞎子,因為未曾閉眼欣賞煙火。

我沒在玩這個,不過剛好前幾天想到AI的人道議題。
起因是想到「一個上市或供免費下載的程式,在推出之前,被編譯過多少次、又被刪掉了多少個不同版本的可執行檔」。
......
... read more
雖然魯班尺的吉凶論定一般是指家宅、傢俱之用,不過既然傳藝中心舉人宅正門牆上也有相同的東西,我想就不用那麼計較了,人生也不是用長度定論的。(註:華人用的捲尺除了魯班尺的吉凶論定之外,也有量陰宅、祖先牌位之用的丁蘭尺,詳見參考資料)
原本是想要看看PHP Plurk API,在亂點roga部落格的MySQL分類時看到了roga大在去年六月有在想SQL的問題,於是心血來潮地試了一下。
DELETE FROM tbl
USING tbl INNER JOIN (
SELECT id, count(*) AS place
FROM (
SELECT t1.id
FROM tbl AS t1, tbl AS t2
WHERE t1.url_id = t2.url_id
AND t1.id <= t2.id
) AS t3
GROUP BY id
) AS t4
WHERE tbl.id = t4.id
AND t4.place > 1500其中tbl是roga大大的url_detail_history,單純是名字太長所以被我換掉。此法受限於資料庫系統對Multiple-table DELETE的支援度,已知MySQL支援。SELECT MAX(id) FROM tbl WHERE url_id = 'XXXX'SELECT url_id, COUNT(*)
FROM tbl
GROUP BY url_id雖然沒什麼困難,不過我們稍比較一下這個和前一個SQL後會發現:SELECT id
FROM tbl
WHERE url_id = 'XXXX'
ORDER BY id DESC
LIMIT n+---------+-------+
| student | score |
+---------+-------+
| 1 | 7 |
| 2 | 5 |
| 4 | 3 |
| 5 | 4 |
+---------+-------+而我們要產出的結果為:+---------+-------+-------+
| student | score | place |
+---------+-------+-------+
| 1 | 7 | 1 |
| 2 | 5 | 2 |
| 4 | 3 | 4 |
| 5 | 4 | 3 |
+---------+-------+-------+也就是學生1是第一名;學生5是第三名;...SELECT t1.student, t2.student
FROM ss AS t1, ss AS t2
WHERE t1.score <= t2.score結果為:+------------+------------+
| t1.student | t2.student |
+------------+------------+
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
| 4 | 1 |
| 4 | 2 |
| 4 | 4 |
| 4 | 5 |
| 5 | 1 |
| 5 | 2 |
| 5 | 4 |
+------------+------------+SELECT t1.student
FROM ss AS t1, ss AS t2
WHERE t1.score <= t2.score假設這張表叫做t3,那麼「列出分數不比自己低的人的總數」,SQL指令就是:SELECT student, COUNT(*)
FROM t3
GROUP BY student(有沒有覺得最後的指令簡潔到令人吐血?)SELECT student, COUNT(*) AS place
FROM (
SELECT t1.student
FROM ss AS t1, ss AS t2
WHERE t1.score <= t2.score
) t3
GROUP BY student得出來的就會是名次列表+---------+---------+-------+
| student | subject | score |
+---------+---------+-------+其中Primary Key為(student, subject),那麼題目就變成「各學生在各科目的排名」,SQL指令為:SELECT student, subject, COUNT(*)
FROM (
SELECT t1.student, t1.subject
FROM ss AS t1, ss AS t2
WHERE t1.score <= t2.score
AND t1.subject = t2.subject
) t3
GROUP BY student, subjectDELETE FROM tbl
USING tbl INNER JOIN (
SELECT id, count(*) AS place
FROM (
SELECT t1.id
FROM tbl AS t1, tbl AS t2
WHERE t1.url_id = t2.url_id
AND t1.id <= t2.id
) AS t3
GROUP BY id
) AS t4
WHERE tbl.id = t4.id
AND t4.place > 1500至於哪邊用大於,哪邊用小於,可得想清楚了....前置作業:
連線到資料庫通常都很好解決(如果MySQL Server有設定好的話):mysql_connect('localhost', 'username', 'password');
mysql_select_db('myDB');
這段程式碼通常會寫在一個給所有頁面引入的檔,假設上面兩行被我們存檔為"database.php",那麼遇到需要對資料庫連線的時候只要PHP呼叫:require_once 'database.php';就可以了。這個方法也可以應用在其他想要在每個頁面上做的事情(像是紀錄IP、檢查是否已登入之類的)。
不過只是這樣子有時會有點風險,比方說如果資料庫不是自己設定的,但我們又必須指定編碼(目前的趨勢是使用UTF-8)的話,就得加上一句"SET NAMES 'UTF8'"的SQL,以防止一些亂碼的狀況發生,當然這個前提是你的網頁也是用UTF-8編碼。連線的設定可能就會變成: $db_server = 'db.mycom.com'; 你可能會覺得先把帳號密碼寫在變數裡這件是有點多餘,不過實務面上我們很有可能還會把「帳號資料」和「連線」這兩個區塊分開--通常是做很大的站台的時候。比方說我可能某個頁面同時要跟Google、Yahoo!和FaceBook做連線,那麼我就會分開寫兩個檔:
$db_user = 'kong0107';
$db_password = '********';
$db_name = 'test';
mysql_connect($db_server, $db_user, $db_password);
mysql_select_db($db_name);
mysql_query("SET NAMES 'UTF8'"); /* 這個檔叫做config.php */
$db_server = 'db.mycom.com';
$db_user = 'kong0107';
$db_password = '********';
$db_name = 'test';
$google_user = 'kong0107';
$google_password = 'hahaha';
$yahoo_user = 'kong_crazykid';
$yahoo_password = 'oh my god';
$fb_user = 'kong0107@gmail.com';
$fb_password = 'this is longer'; /* 這個檔叫做service_connection.php */ 看吧,只是連線而已就已經開始讓人頭昏眼花,而且我們根本還沒有開始真正操作什麼呢!所以還是把一些設定(諸如帳號、密碼)通通寫在同一區,這樣子之後要改才比較方便。(註:那些API的實際使用方法應該不是這樣子,我只是隨便舉個例子。但總之通常只會更複雜)
require 'config.php'; /*就會把上面那個檔案叫進來*/
mysql_connect($db_server, $db_user, $db_password);
mysql_select_db($db_name);
mysql_query("SET NAMES 'UTF8'");
require_once 'google_api.php'; /*把google的API(最重要的是連線function)叫進來*/
$google = new GoogleAPI();
$google->connect($google_user, $google_password);
require_once 'yahoo_api.php';
$yahoo = new yahooAPI();
$yahoo->connect($yahoo_user, $yahoo_password);
require_once 'facebook_api.php';
$fb = new facebookAPI();
$fb->connect($fb_user, $fb_password);
SELECT id, name FROM studentSELECT * FROM student
ORDER BY id ASC其中"ASC"是表示遞增排序(遞減排序則是DESC)在這邊要注意幾點事情:
SELECT `id`, `name`
FROM `student`
WHERE `id` < 10
ORDER BY `id` DESC SELECT * FROM student WHERE name = '高睿甫' SELECT *
FROM message
WHERE content = '野村克也說\'要讓一個選手墮落很簡單啊,只要稱讚他就行了!\'他說的真是太忠肯了' PHP執行SQL的指令是mysql_query()(注意:當然要先對資料庫連線,再執行mysql_query()才有意義),有時我們會把SQL直接寫在裡面:$res = mysql_query("SELECT * FROM student");
不過如果是像上面有比較長的SQL,我倒是比較建議先另外丟進變數裡:$sql = "SELECT `id`, `name` 也別忘了PHP的字串裡面是可以直接換行的(題外話:如果你有在寫JavaScript的話,請注意JavaScript並不能直接這樣做喔)
FROM `student`
WHERE `id` < 10
ORDER BY `id` DESC";
$res = mysql_query($sql);
有注意到我都把mysql_query()回傳的東西丟給$res變數嗎?那就是我們接下來要操作的東西囉
$res = mysql_query("SELECT * FROM student");
$row1 = mysql_fetch_assoc($res); /*第一列*/
$row2 = mysql_fetch_assoc($res); /*第二列*/
$row3 = mysql_fetch_assoc($res); /*第三列*/ 注意我們其實是在執行同一個function,但是每次卻回傳不同的結果喔!當然你應該不會想這麼呆呆的把整張資料表取完,這種時候就得用上迴圈啦。但是面對不知道SQL回傳的結果有幾筆資料的時候,回圈應該要在什麼時候停止呢? $res = mysql_query('SELECT * FROM student');
while($row = mysql_fetch_assoc($res)) {
/* 這裡就看你想對這一筆資料幹嘛*/
echo $row['id']; /*像這樣就可以印出該學生的學號*/
} $res = mysql_query('SELECT `id`, `name` FROM `student`');
echo '<table>';
while($student = mysql_fetch_assoc($res)) {
echo '<tr>';
echo '<td>';
echo $student['id'];
echo '</td>';
echo '<td>';
echo $student['name'];
echo '</td>';
echo '</tr>';
}
echo '</table>'; 像是這樣,不過輸出的部份我自己比較喜歡另一個方式:<table>
<?php
while($student = mysql_fetch_assoc($res)) {
?>
<tr>
<td><?=$student['id']?></td>
<td><?=$student['name']?></td>
</tr>
<?php
}
?>
<table>就是這樣囉,或是看你想怎麼顯示都可以。 $id = 9646515;
$res = mysql_query("SELECT * FROM student WHERE id = $id");
$kong = mysql_fetch_assoc($res);
$name = $kong['name'];
echo "學號$id 的學生,他的名字是$name"; $res = mysql_query("SELECT id FROM student");
$row1 = mysql_fetch_assoc($res);
echo $row1['id'];
$row2 = mysql_fetch_row($res);
echo $row2[0];
$row3 = mysql_fetch_array($res);
echo $row3['id'];
echo $row3[0];$txt = $_GET['search'];
$sql = "SELECT * FROM message WHERE content = '$txt'";
// 還記得字串要加上單引號吧.. 不過以這個例子來說,我們又必須小心使用者輸入的東西本身就有單引號。比方說使用者輸入了"我好傷心喔 T_T'",那麼整個SQL丟給MySQL的時候就會變成SELECT * FROM message WHERE content = '我好傷心喔 T_T''然後就發生錯誤啦(因為MySQL看不懂那些引號是怎麼回事)$txt = str_replace("'", "\\'", $_GET['search']);
/* 如果你看不懂那個"\\'",就先照做吧....*/
$sql = "SELECT * FROM message WHERE content = '$txt'"; $id = $_GET['id'];
$sql = "SELECT * FROM message WHERE id = $id"; 可是,如果使用者在表單中,根本不是打數字的話(比方說使用者什麼都沒打),SQL就會變成SELECT * FROM message WHERE id = 於是就產生錯誤了(因為等號後面不是數字)。$id = str_replace("'", "\\'", $_GET['id']);
$sql = "SELECT * FROM message WHERE id = '$id'"; $sql = "SELECT * FROM message WHERE id = %d";
$sql = sprintf($sql, $_GET['id']); 以上兩個方法都可以應付使用者亂打的狀況 SELECT * FROM car
WHERE brand = 'BMW'
AND oilCart > 2000
AND price < 700000如果我們是使用sprintf()的話,就可以用比較容易懂得簡短程式碼來執行(簡潔易懂的程式碼可以幫助自己或他人後續的除錯和更新):$sql = "
SELECT * FROM car
WHERE brand = '%s'
AND oilCart > %d
AND price < %d
";
$sql = sprintf($sql, $_GET['brand'], $_GET['oilCart'], $_GET['price']);這只是個比較簡單的例子,但如果是遇到像是需要報表、統計這一類需要跨多的資料表的SQL,使用sprintf()的替代方式可以讓你快速的編輯和除錯。
http://www.box.net/rssdownload/122326921/MaxAC20080108.zip
不過怎地到了昨天才想到這種模組的方法
分三部份
1. Chord Progression: 用前一個和弦來決定下個調性和和弦
2. Accompaniment
3. Melody (w/o resolution)
如果後續要做的話都可以分開改:P
作者: kong (Life of Music) 看板: P_LifeOMusic
標題: Re: [音樂] 自動作曲
時間: Fri Dec 14 03:40:34 2007
※ 引述《kong (Life of Music)》之銘言:
> http://kong.dorm7.nctu.edu.tw/ac/
(請找PHP檔)
> 還好目前還很難聽
http://kong.dorm7.nctu.edu.tw/ac/20071214.php
不過加了點伴奏之後增加了不少可聽性
...至少可以平心靜氣地把100個小節聽完
本學期(就課業要求上)應該就到此為止吧
--
就算是這個世界 把我拋棄
而至少快樂傷心我自己決定
[1;30mhttp://www.streetvoice.com.tw/kong0107/music[m
MP3下載
這次的比較能聽了..../*......
Csound - Final Project
Author: Kong Kao
Advisor: Prof. James Ma
This project uses pre-entered chords to implement auto-composition.
Chords are stored by their roots in tables.
Instr 1 decides how the chord goes, and store the way the music would go
into a function table (giftMelody).
Instr 2 does 3 part of music:
1. The root of the chord.
2. A melody generated by an algorithm with random.
3. Accompaniment
*/
<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
; Global a-rate variabe used for reverberation
gaSig init 0
; Some constant for convenience
giSemiTone init 2^(1/12)
giLoopLength init 8 ; Seconds a period would use.
; Function tables
giftScale init 2
giftMelody ftgen 0, 0, 8192, -2, 0, 8192, 0 ; Overall roots of chords
; Function tables that stores the chords.
; The name of them is only meaningful for me, so don't mind it...XD
giftBallad init 1
giftHappy init 4
giftToDearYou init 5
instr 1
/*
No signal output, but need to have the same length with i2.
Used to assign the overall roots to the function table giftMelody
Note that only the value is neither semitones nor intervals, but the
index of the tone in giftScale.
*/
aPhasor phasor 1/giLoopLength
INIT0:
iSwitch = floor(rnd(3))
if( iSwitch == 0 ) then
iFt = giftBallad
elseif( iSwitch == 1 ) then
iFt = giftHappy
else
iFt = giftToDearYou
endif
aMelody table aPhasor, iFt, 1
timout 0, giLoopLength, CONT0
reinit INIT0
CONT0:
rireturn
aPhasor phasor 1/p3
tablew aMelody, aPhasor, giftMelody, 1
endin
instr 2
iUnit = 0.25 ; The shortest length of a note, measured in seconds
iAmp = ampdb( p4 )
iBaseFreq = p5
kPhasor phasor 1/p3
kMelody table kPhasor, giftMelody, 1
kPitch table kMelody, giftScale
kFreq = iBaseFreq * giSemiTone ^ kPitch / 2
aSig1 oscil iAmp, kFreq, 11
; ----------------------------------------------------------
iPrevPitch = 3
iPrevInterval = 0
iPosition = 0
/*
Use a variable to store the position of the current note in the period.
This is used to decide which chord it is for the note.
*/
INIT2:
/*
Decide the interval of this note with the root of the chord.
If the previous interval tends to be balanced (such as 4th tends to
3rd, and 7th tends to octave), set the interval to the tension. (Note
that this may go wrong as the chord changes)
Note that the "interval" is stored one less than what we call it.
*/
if( iPrevInterval == 3 ) then
iInterval = 2
elseif( iPrevInterval == 6 ) then
iInterval = 7
else
INTERV2:
iInterval table rnd(ftlen(3)), 3
cigoto ( iInterval < 0 ), INTERV2
endif
/*
Fetch what the chord here it is and calculate the tone to be played.
If the interval with the previous note is bigger than octave,
then choose the interval again randomly.
*/
iRootIndex table iPosition/p3, giftMelody, 1, 0, 1
iPitch table iRootIndex + iInterval, giftScale
cigoto ( abs( iPitch - iPrevPitch ) > 12 ), INTERV2
/*
Decide the length of this note.
For disonant tones (those not in the triad chord of the given root),
set the length of it short.
*/
if( iInterval != 0 \
&& iInterval != 2 \
&& iInterval != 4 \
&& iInterval != 7 \
) then
iDur = iUnit
else
iDur = (int(rnd(3))+1)*iUnit
endif
kAmp expseg 0.01, 0.1, 1, iDur-0.2, 0.25, 0.1, 0.01
iFreq = iBaseFreq * giSemiTone ^ iPitch
kVibEnv linseg 0, 0.3, 0, iDur-0.3, 0.5
kVibAmp lfo kVibEnv, 10
kFreq = iFreq * ( 1 + kVibAmp )
kForm line 600, iDur, 800
kBand line 60, iDur, 80
aSig2 fof iAmp * kAmp, kFreq, kForm, 0, kBand, \
0.005, 0.02, 0.07, 64, 14, 15, iDur
if( iDur > 0.3 ) then
gaSig = gaSig + aSig2 / 2
endif
iPosition = iPosition + iDur
iPrevPitch = iPitch
iPrevInterval = iInterval
timout 0, iDur, CONT2
reinit INIT2
CONT2:
rireturn
; ---------------------------------------------------------------------
iPosition3 = 0
iPrevPitch31 = 0
iPrevPitch32 = 0
INIT3:
/*
Decide 2 tones to play.
floor(rnd(3))*2 is used to decide the semitones with the root would be,
that is, they're deciding whether the the interval is 1st, 3rd, or 5th.
*/
iRootIndex3 table iPosition3/p3, giftMelody, 1, 0, 1
iPitch31 table iRootIndex3 + floor(rnd(3))*2, giftScale
iPitch32 table iRootIndex3 + floor(rnd(3))*2, giftScale
iFreq31 = iBaseFreq * giSemiTone ^ iPitch31 * 2 ^ floor(birnd(1))
iFreq32 = iBaseFreq * giSemiTone ^ iPitch32 * 2 ^ floor(rnd(2))
kAmp3 linseg 0, 0.2, 1, iUnit-0.2, 0
aSig31 oscil iAmp*kAmp3, iFreq31/2, 13
aSig32 oscil iAmp*kAmp3, iFreq32/2, 12
if( iFreq31 < 220 ) then
gaSig = gaSig + aSig31 * abs( 220 - iFreq31 ) / 220
endif
iPrevPitch31 = iPitch31
iPrevPitch32 = iPitch32
iPosition3 = iPosition3 + iUnit
timout 0, iUnit, CONT3
reinit INIT3
CONT3:
rireturn
aSig3 = ( aSig31 + aSig32 ) / 2
aSig sum aSig1/2, aSig2, aSig3
kAmp linseg 1, p3-4, 1, 4, 0.01
aSig = aSig * kAmp
out aSig
endin
instr 101
aSig reverb gaSig, 0.5
out aSig
gaSig = 0
endin
</CsInstruments>
<CsScore>
/*
Function table 1 and 4:
Stores the roots of the chords by the index of the note in f2.
By using GEN7 and big enough table, we can then set the chord to change
in a nonregular way, that is, chord may change not only at the 1st beat
of a bar.
*/
f 1 0 64 -7\
3 8 3 0 \
7 8 7 0 \
8 8 8 0 \
7 8 7 0 \
6 8 6 0 \
5 8 5 0 \
6 8 6 0 \
7 4 7 0 \
0 4 0
f 4 0 16 -7\
3 4 3 0 \
1 4 1 0 \
6 4 6 0 \
7 2 7 0 \
0 2 0
f 5 0 32 -7\
6 4 6 0 \
7 4 7 0 \
3 2 3 0 \
2 2 2 0 \
1 4 1 0 \
6 4 6 0 \
7 4 7 0 \
3 8 3
/*
Function table 2
Stores major scale in numbers of semitones
between the tonic and each one.
*/
f 2 0 16 -2 \
-5 -3 -1 0 2 4 5 7 \
9 11 12 14 16 17 19 21
/*
Function table 3
Stores the probability of an interval to be used.
More a number appears, more the inteval would be used.
*/
f 3 0 64 -7 \
0 5 0 0 \
1 5 1 0 \
2 10 2 0 \
3 3 3 0 \
4 7 4 0 \
5 12 5 0 \
6 2 6 0 \
7 8 7 0 \
-1 64 -1
/*
Function tables for timbre
*/
f 11 0 8193 10 1 0.5 0.25
f 12 0 8193 10 1 0.1 0.2 0.3 0.4 0.3 0.2 0.1
f 13 0 8193 10 1 0.4 0.3 0.2 0.1
f 14 0 8193 10 1
f 15 0 8192 19 0.5 0.5 260 0.5
i 1 0 16
i 2 0 16 75 220
i 101 0 17
e
</CsScore>
</CsoundSynthesizer>
... read more
/*......
Csound Exercise 05
Author: Kong Kao
Advisor: Prof. James Ma
This exercise focuses on conditional branch, including opcodes such as
reinit, rireturn, and timout....
The basic idea of this piece is an algorithm to compose in a single mode.
The function table stores different data and may be used in different way.
For future work, I'd like to add other possibility parameters to make the
piece has a feeling of tonic and some rhythm.
*/
<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2
; Some constant for convenience
giScale init 1
giInterval init 2
giSemiTone init 2^(1/12)
gaSig1 init 0
instr 1
iBaseFreq = p4
iAmp = p5
iAmp2 = p6
iAmp3 = p7
iPrevPitchIndex init 9
INIT:
;seed rnd(2^32)
; Randomly choose an interval to decide the next note
iTemp = rnd( ftlen(giInterval) )
iInterval table iTemp, giInterval
cigoto ( iInterval < 0 ), INIT
; Decide the melody would go up or down
if( birnd(1) > 0 ) then
iPitchIndex = iPrevPitchIndex + iInterval
else
iPitchIndex = iPrevPitchIndex - iInterval
endif
cigoto ( iPitchIndex < 0 ), INIT
cigoto ( iPitchIndex >= ftlen(giScale) ), INIT
iPitch table iPitchIndex, giScale
; Decide other tones
; 3rd, 4th, 5th, 6th would be consonant. Care about neither A4 nor d5.
; The 3 tones would be a triad.
iVerticalInterval = floor( rnd(4) ) + 3
if( iVerticalInterval == 3 ) then
iVerticalInterval2 = 5 + floor( rnd(2) )
elseif( iVerticalInterval == 4 ) then
iVerticalInterval2 = 6
elseif( iVerticalInterval == 5 ) then
iVerticalInterval2 = 3
elseif( iVerticalInterval == 6 ) then
iVerticalInterval2 = 3 + floor( rnd(2) )
endif
if( iPitchIndex < ftlen( giScale ) / 2 ) then
iPitch2 table iPitchIndex + iVerticalInterval, giScale
iPitch3 table iPitchIndex + iVerticalInterval2, giScale
else
iPitch2 table iPitchIndex - iVerticalInterval, giScale
iPitch3 table iPitchIndex - iVerticalInterval2, giScale
endif
iFreq = iBaseFreq * giSemiTone^iPitch
iFreq2 = iBaseFreq * giSemiTone^iPitch2 / 4 ; Bass melody
iFreq3 = iBaseFreq * giSemiTone^iPitch3
; Choose a duration
iDur = (int(rnd(4))+1)*0.25
; Amplitude
kPhase phasor 1/iDur
kTableIndex = kPhase * ftlen(21)
kAmp table3 kTableIndex, 21 + floor( rnd(4) )
kAmp2 table3 kTableIndex, 21 + floor( rnd(4) )
kAmp3 table3 kTableIndex, 21 + floor( rnd(4) )
kAmp = kAmp * iAmp
kAmp2 = kAmp2 * iAmp2
kAmp3 = kAmp3 * iAmp3
/*
Since I'd like to assign the timbre of the bass dynamically
The signal processing would be here, instead of after label CONT
*/
aSig2S oscili kAmp2, iFreq2, 12
aSig2E oscili kAmp2, iFreq2, 14 + floor(rnd(3))
kLine line 0, iDur, 1
aSig2 = aSig2S * kLine + aSig2E * ( 1 - kLine )
; Store the pitch index for next note to use.
iPrevPitchIndex = iPitchIndex
timout 0, iDur, CONT
reinit INIT
CONT:
aSig1 oscili kAmp, iFreq, 11
aSig3 oscili kAmp3, iFreq3, 13
aSig = aSig1 + aSig2 + aSig3
rireturn
kAmpOverAll linseg 0, p3/6, 0.7, p3*2/3, 0.9, p3/6, 0
aSig = aSig * kAmpOverAll
outs aSig, aSig
endin
</CsInstruments>
<CsScore>
/*
Function table 1
Stores a scale in numbers of semitones between the tonic and each one.
It must be a diatonic scale in this exercise to let the contrapound
consonant tone to go right..(in natural 3rd, 4th, 5th, 6th,
instead of any other dissonant intervals.)
For now, this table stores a harmonic minor.
*/
f 1 0 16 -2 \
-4 -1 0 2 3 5 7 8 11 12 14 15 17 19 21 22
/*
Function table 2
Stores the possibility of each interval, which would be used randomly.
For example, if the number denoting an interval has the amount of
appearance to be 6, then the possibility of the interval to be used
would be "6 / ftlen(thisTable)"
For simplicity, 0 would mean the interval to be perfect 1st, but -1 is
also used for the random procedure to goes again.
*/
f 2 0 64 -7 \
0 4 0 0 \
1 8 1 0 \
2 7 2 0 \
3 6 3 0 \
4 5 4 0 \
5 4 5 0 \
6 3 6 0 \
7 2 7 0 \
8 1 8 0 \
-1 64 -1 \
; Function tables for timbre....
f 11 0 8193 10 \
8 4 2 1
f 12 0 8193 10 \
1 2 3 4
f 13 0 8193 10 \
4 3 2 1
f 14 0 8193 11 10 1 0.5
f 15 0 8193 11 8 1 1.5
f 16 0 8193 11 12 1 -0.5
; Envelopes
f 21 0 8193 5 \
0.1 1024 1 1024 0.7 4096 0.4 2048 0.01
f 22 0 8193 8 \
0 1024 1 1024 0.7 4096 0.4 2048 0
f 23 0 8193 5 \
0.1 1024 1 6144 0.7 1024 0.01
f 24 0 8193 8 \
0.1 1024 1 6144 0.7 1024 0.01
i 1 0 60 220 12000 16000 8000
e
</CsScore>
</CsoundSynthesizer>
... read more