在最初通知事件后,vmstat 中的 bi(磁盤塊入)和 bo(磁盤塊出)數(shù)據(jù)字段將被聚結(jié)為范圍在 0 到 1,000 的一個(gè)字段。請注意,這些值十分適于測試計(jì)算機(jī)的標(biāo)準(zhǔn) IDE 磁盤設(shè)置。如果在整個(gè)磁盤子系統(tǒng)中有一個(gè)高磁盤配置或低磁盤配置,則可能需要修改最大值,以便更準(zhǔn)確地表示可用帶寬。一旦總磁盤使用量的范圍落在 0 到 1,000 的范圍內(nèi),就會(huì)被除以 10 以獲得 0 到 100 之間的值。然后將在通道 8 中使用通常的最小值和最大值把此值作為通知速率發(fā)送。
getNetworkStats 部分略微更復(fù)雜,但正如您所見,返回的數(shù)據(jù)庫值范圍在 0 到 100 之間,并作為另一個(gè) noteon 事件發(fā)送出去。注意此最后一個(gè)通知事件的最大值是 84。這是由于 SoundFont 僅在通道 5 中創(chuàng)建音頻通知,音頻速率范圍從 0 到 84。這可以證明足以檢測在最大負(fù)荷狀態(tài)下和聲中的變化的那些音頻通知是表示有問題的。
在圈選循環(huán)括號和計(jì)時(shí)代碼后,它就成為了子例程。
清單 5. sendNote 子例程
sub sendNote { my( $noteVal, $noteChan, $min, $max ) = @_; if( $noteVal < $min ){ $noteVal = $min; }else{ # divide it into twelve parts $noteVal = sprintf( "%0.0f", $noteVal/12); # reduce the note to 12 at the very least; $noteVal = ($noteVal * 12); if( $noteVal > $max ) { $noteVal = $max } }#if note is > minimum print "noteon $noteChan $noteVal 100\n"; }#sendNote |
sendNote 子例程將獲得值在 0 到 100 之間的通知速率,并將把該通知速率轉(zhuǎn)換為基本通知中最接近 12 的通知步驟。在這種情況下,基本通知是 12,并且所有通知都將使用該值作為其 0 狀態(tài)。這就為系統(tǒng)處于低負(fù)載狀態(tài)時(shí)提供了頻率相當(dāng)?shù)偷?“跳動(dòng)”(如果為令人滿意的固定狀態(tài)賦予人性的話)。為簡單起見,所有通知都是以音量級別 100 輸出的。根據(jù)其他系統(tǒng)元素修改音量級別會(huì)是添加信息的直觀方法,而無需添加通知或和聲變化。
清單 6. getNetworkStats 子例程
sub getNetworkStats { my $networkCmd = "/sbin/ifconfig eth0 | grep 'RX bytes'"; $networkCmd = `$networkCmd`; my $rxBytes = 0; my $txBytes = 0; chomp($networkCmd); for( $networkCmd ){ $rxBytes = substr($_, 19); $rxBytes = substr($rxBytes,0,index($rxBytes," ")); $txBytes = substr($_, 52); $txBytes = substr($txBytes,0,index($txBytes," ")); my $bothBytes = $rxBytes + $txBytes; if( $totalPackets == 0 ){ $totalPackets = $bothBytes; }else{ # find the difference between measurements, set maximum difference to # 1Mbit, which works well for `saturated' on a 100Mbit/sec network # reduce the value by a factor of 10000, which spreads the usage # nicely over 1-100 my $diffRX = $bothBytes - $totalPackets; if( $diffRX > 1000000 ){ $diffRX = 1000000 } $diffRX = ($diffRX / 10000); $totalPackets = $bothBytes; return( $diffRX ); }# if not first packet check }# packet count check }#getNetworkStats |
如果 obtuse 方法接近網(wǎng)卡的負(fù)載,則這段代碼是簡單的。/sbin/ifconfig/eth0 命令的輸出將列出收到和傳輸?shù)乃行畔倲?shù)。在網(wǎng)絡(luò)連接速度為 100Mbit/sec 的測試計(jì)算機(jī)上,超過 1000,000 個(gè)傳輸或接收信息包的所有情況都被視為完全飽和。該值的范圍隨后會(huì)被調(diào)整為 0 到 100 之間的通知速率,并作為電子鋼琴通知播放。