在最初通知事件后,vmstat 中的 bi(磁盤塊入)和 bo(磁盤塊出)數據字段將被聚結為范圍在 0 到 1,000 的一個字段。請注意,這些值十分適于測試計算機的標準 IDE 磁盤設置。如果在整個磁盤子系統中有一個高磁盤配置或低磁盤配置,則可能需要修改最大值,以便更準確地表示可用帶寬。一旦總磁盤使用量的范圍落在 0 到 1,000 的范圍內,就會被除以 10 以獲得 0 到 100 之間的值。然后將在通道 8 中使用通常的最小值和最大值把此值作為通知速率發送。
getNetworkStats 部分略微更復雜,但正如您所見,返回的數據庫值范圍在 0 到 100 之間,并作為另一個 noteon 事件發送出去。注意此最后一個通知事件的最大值是 84。這是由于 SoundFont 僅在通道 5 中創建音頻通知,音頻速率范圍從 0 到 84。這可以證明足以檢測在最大負荷狀態下和聲中的變化的那些音頻通知是表示有問題的。
在圈選循環括號和計時代碼后,它就成為了子例程。
清單 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 之間的通知速率,并將把該通知速率轉換為基本通知中最接近 12 的通知步驟。在這種情況下,基本通知是 12,并且所有通知都將使用該值作為其 0 狀態。這就為系統處于低負載狀態時提供了頻率相當低的 “跳動”(如果為令人滿意的固定狀態賦予人性的話)。為簡單起見,所有通知都是以音量級別 100 輸出的。根據其他系統元素修改音量級別會是添加信息的直觀方法,而無需添加通知或和聲變化。
清單 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 方法接近網卡的負載,則這段代碼是簡單的。/sbin/ifconfig/eth0 命令的輸出將列出收到和傳輸的所有信息包總數。在網絡連接速度為 100Mbit/sec 的測試計算機上,超過 1000,000 個傳輸或接收信息包的所有情況都被視為完全飽和。該值的范圍隨后會被調整為 0 到 100 之間的通知速率,并作為電子鋼琴通知播放。