Source code:
tclmpg123
因為 MP3 的專利的關係,所以 libsndfile 的作者沒有寫關於 mp3 格式的部份(因為他開了一家公司來處理 libsndfile 的維護,所以如果 MPEG 組織找上門來索取專利費的話會帶來問題),如果要讀取 mp3,就要使用其它的 library。
所以 tclmpg123 就是用來透過 libmpg123 處理讀取 mp3 檔案的工作,然後再把讀出來的音訊訊號丟給 tcllibao 輸出。
2016-12-13
2016-12-10
Tcllibao and Tclsndfile
Tcllibao:
source code
Tclsndfile:
source code
Tcl/Tk 已經有二個 audio extension 可以使用,一個是 Snack,一個是 SDL_mixer bindings for Tcl。
Snack 其實原作者看起來已經沒有什麼更新,不過 Tcl/Tk 社群仍然有人持續在維護,是一個很普遍的套件。
我寫 tcllibao 和 tclsndfile 只是為了探索 Linux audio library 的使用方式。libsndfile 是讀取檔案以後拿到音訊資料,而 libao 用來將聲音輸出(還有其它的 library 可以用,例如 SDL_mixer)。
要注意的是,libao 使用 GPL 授權,所以我 tcllibao 使用同樣的授權方式。同樣的,libsndfile 使用 LGPL 授權,tclsndfile 我也使用同樣的授權方式。
下面就是我的測試程式:
更新: 我發現 tclsndfile README.md 我有打錯說明,所以刪掉重新建了一個新的上去 github。
2016/12/12
嘗試在 Windows 7 (64bit) 使用 MSYS2/MinGW-W64 編譯與使用測試,我把遇到的問題跟解法記錄在 github README.md。
source code
Tclsndfile:
source code
Tcl/Tk 已經有二個 audio extension 可以使用,一個是 Snack,一個是 SDL_mixer bindings for Tcl。
Snack 其實原作者看起來已經沒有什麼更新,不過 Tcl/Tk 社群仍然有人持續在維護,是一個很普遍的套件。
我寫 tcllibao 和 tclsndfile 只是為了探索 Linux audio library 的使用方式。libsndfile 是讀取檔案以後拿到音訊資料,而 libao 用來將聲音輸出(還有其它的 library 可以用,例如 SDL_mixer)。
要注意的是,libao 使用 GPL 授權,所以我 tcllibao 使用同樣的授權方式。同樣的,libsndfile 使用 LGPL 授權,tclsndfile 我也使用同樣的授權方式。
下面就是我的測試程式:
#!/usr/bin/tclsh
#
# Using libao and libsndfile to play a wav/ogg file
#
package require libao
package require sndfile
if {$argc > 0} {
set name [lindex $argv 0]
} else {
puts "Please input filename."
exit
}
if {[catch {set data [sndfile snd0 $name READ]}]} {
puts "sndfile: read file failed."
exit
}
set encoding [dict get $data encoding]
# only for test seek
snd0 seek 0 SET
libao::ao initialize
set id [libao::ao default_id]
set bits 16
switch $encoding {
{pcm_16} {
set bits 16
}
{pcm_24} {
set bits 24
}
{pcm_32} {
set bits 32
}
{pcm_s8} {
set bits 8
}
{pcm_u8} {
set bits 8
}
default {
set bits 16
}
}
libao::ao open_live $id -bits $bits \
-rate [dict get $data samplerate] \
-channels [dict get $data channels] -byteformat 4
# libao needs use read_short to get data
while {[catch {set buffer [snd0 read_short]}] == 0} {
libao::ao play $buffer
}
snd0 close
libao::ao close
libao::ao shutdown
更新: 我發現 tclsndfile README.md 我有打錯說明,所以刪掉重新建了一個新的上去 github。
2016/12/12
嘗試在 Windows 7 (64bit) 使用 MSYS2/MinGW-W64 編譯與使用測試,我把遇到的問題跟解法記錄在 github README.md。
2016-12-08
tclcubrid v0.9.4
Source code
tclcubridAbout
CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.
tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.
Main changelog
- Add Date/Time types with timezone support
這個版本增加 Date/Time types with timezone 的支援。
2016-12-05
Tclunqlite v0.3.2
檔案放置網頁
Tclunqlite
About
This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL (Key/Value store and Document-store) database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.
Main Change
- Update UnQLite version to 1.1.7
說明
這是一個小更新版本,更新 UnQLite 的版本。
2016-11-29
1-9位數不重複印出來 (練習問題)
使用者輸入1 印1-9
使用者輸入2 印1-98 (11, 22, 33等重複的不印)
使用者輸入3 印1-987 (121, 988, 667等有重複的不印)
也可以使用 lsort -unique 建立 set 來解題。
也可以用 permutations 的方式來解題,下面是 Tcl 的版本:
使用者輸入2 印1-98 (11, 22, 33等重複的不印)
使用者輸入3 印1-987 (121, 988, 667等有重複的不印)
#!/usr/bin/tclsh
#
# Test on Tcl 8.6
#
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0 || $number >= 10} {
puts "The range is 1 - 9."
exit
}
set max [expr 10 ** $number]
puts "\nNow get the result:"
puts "==========="
puts "Start"
puts "==========="
puts -nonewline "1"
for {set i 2} {$i < $max} {incr i} {
set var [regexp "1.*1|2.*2|3.*3|4.*4|5.*5|6.*6|7.*7|8.*8|9.*9|0.*0" $i]
if {$var != 1} {
puts -nonewline ", $i"
}
}
puts "\n==========="
puts "End"
puts "==========="
也可以使用 lsort -unique 建立 set 來解題。
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0 || $number >= 10} {
puts "The range is 1 - 9."
exit
}
set max [expr pow(10, $number)]
set result [list]
puts "\nNow get the result:"
puts "==========="
puts "Start"
puts "==========="
for {set i 1} {$i < $max} {incr i} {
set tmpstring [format %s $i]
set tmpList [lsort -unique [split $tmpstring ""]]
if {[string length $tmpstring] == [llength $tmpList]} {
lappend result $i
}
}
puts [join $result ", "]
puts "\n==========="
puts "End"
puts "==========="
也可以用 permutations 的方式來解題,下面是 Tcl 的版本:
#!/usr/bin/env tclsh
proc permutations { list size } {
if { $size == 0 } {
return [list [list]]
}
set retval {}
for { set i 0 } { $i < [llength $list] } { incr i } {
set firstElement [lindex $list $i]
set remainingElements [lreplace $list $i $i]
foreach subset [permutations $remainingElements [expr { $size - 1 }]] {
lappend retval [linsert $subset 0 $firstElement]
}
}
return $retval
}
puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0 || $number >= 10} {
puts "The range is 1 - 9."
exit
}
set allresult [list]
for {set i 1} {$i <= $number} {incr i} {
set res [permutations [list 0 1 2 3 4 5 6 7 8 9] $i]
set allresult [list {*}$allresult {*}$res]
}
puts -nonewline "1"
set len [llength $allresult]
for {set i 2} {$i < $len} {incr i} {
set r [lindex $allresult $i]
set first [lindex $r 0]
if {[string compare $first "0"]==0} {
continue
}
puts -nonewline ", "
puts -nonewline [join $r ""]
}
puts "\n"
flush stdout
2016-11-18
tcl.mqttc
Source code
tcl.mqttc
About
This Tcl extension is based on Paho MQTT C Client, but only support synchronous API and basic SSL/TLS support (server needs setup needClientAuth to false).
Test server: Apache ActiveMQ
我發現 Apache ActiveMQ 有支援 MQTT,所以使用 Paho MQTT C Client 的實作,包裝了一個 Tcl extension 來測試。
TLS/SSL 只支援 Server authentication/Anonymous connection,Mutual authentication 則有問題(應該說我不知道怎麼正確設定,稍微搜尋了一下網路上的解法,還是設不起來),所以只有放上去關於 Server authentication 的部份。
2016/11/19 更新
我重新檢視了一下 log,發現我好像沒有正確的加入資料到 server 端的 trueStore,重做一次以後就可以正常工作。所以我把 Mutual authentication 相關的部份也推送上去 github 了。
2016-11-14
tclcubrid v0.9.3
Source code
tclcubridAbout
CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.
tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.
Main changelog
- Free memory when connect fail
這是一個小更新的版本。
2016-11-11
MonetDB ODBC (Linux/openSUSE) test
MonetDB ODBC driver 的部份,首先必須要先安裝 unixODBC,然後編譯的時候需要有編譯 ODBC driver。
unixODBC 需要設定二個檔案。/etc/unixODBC/odbc.ini 與 /etc/unixODBC/odbcinst.ini。
首先是 odbcinst.ini 的內容:
再來是 odbc.ini,
我們使用 TDBCODBC 進行驗證:
首先是 odbcinst.ini 的內容:
[MonetDB] Description = ODBC driver for MonetDB server Driver = /usr/local/lib64/libMonetODBC.so Setup = /usr/local/lib64/libMonetODBCs.so FileUsage = 1
再來是 odbc.ini,
[MonetDB] Description = MonetDB Driver = MonetDB Trace = No TraceFile = Database = demo Host = localhost UserName = monetdb Password = monetdb Port = 50000 ConfigFile =
我們使用 TDBCODBC 進行驗證:
package require tdbc::odbc
set connStr "DSN=MonetDB; UID=monetdb; PWD=monetdb;"
tdbc::odbc::connection create db $connStr
set statement [db prepare {create table person (id integer, name varchar(40))}]
$statement execute
$statement close
set statement [db prepare {insert into person values(1, 'leo')}]
$statement execute
$statement close
set statement [db prepare {insert into person values(2, 'yui')}]
$statement execute
$statement close
set statement [db prepare {SELECT * FROM person}]
$statement foreach row {
puts [dict get $row id]
puts [dict get $row name]
}
$statement close
set statement [db prepare {drop table person}]
$statement execute
$statement close
2016-11-06
tclcubrid v0.9.2
Source code
tclcubridAbout
CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.
tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.
Main changelog
- Update Thread_Exit method
這是一個小更新的版本。
2016-11-04
tclcubrid v0.9.1
Source code:
tclcubrid
About:
CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.
tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.
Main changelog:
這是一個小更新的版本,更新 TDBC configure method(加入 -readonly option)。
tclcubrid
About:
CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.
tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.
Main changelog:
- Update TDBC configure method
這是一個小更新的版本,更新 TDBC configure method(加入 -readonly option)。
訂閱:
文章 (Atom)