Companding (compression and expansion of transfer data) can be found in many different
applications, especially in digital telephone systems. A digital telephone system converts an
analog speech signal to a digital signal. This digital signal is referred to as linear—meaning
without compression. Instead of transmitting this linear digital signal across the telephone
network, this digital signal is usually first compressed before being transmitted to reduce the
transmission bandwidth. The receiver needs to expand this non-linear, compressed signal back
to a linear digital signal. Companding refers to this combined process of compression and
expansion.
Two companding format for G.711 Audio are a law and u law.
Friday, December 16, 2011
Saturday, December 10, 2011
SoX raw audio data converter. wav to/from mulaw
Utility SoX (Sound Exchange)
Convert mulaw to wav:
sox.exe -t ul input_mulaw_file output_wav_file
Convert wav to mulaw:
sox.exe input_wav_file -r 8000 -c 1 -t ul output_mulaw_file
Convert mulaw to wav:
sox.exe -t ul input_mulaw_file output_wav_file
Convert wav to mulaw:
sox.exe input_wav_file -r 8000 -c 1 -t ul output_mulaw_file
Thursday, November 24, 2011
Friday, November 11, 2011
Xcode build setting variables
For Build setting syntax, refers to http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/XcodeBuildSystem/300-Build_Settings/bs_build_settings.html
To reference a build setting value in a build setting specification, use the name of the build setting surrounded by parentheses and prefixed by the dollar-sign character ($). For example, the specification of a build setting that refers to the value of the Product Name build setting could be similar to
The name of this target's product is $(PRODUCT_NAME)
.Friday, October 14, 2011
Prevent SIGPIPE from crashing the program
To do so, add following code to your program.
signal( SIGPIPE, SIG_IGN ) ;
If debugging with GDB, GDB captures it and paused the process. To avoid this, run following command in gdb. For detailed information about handle, type "handle help" in gdb.
handle SIGPIPE nostop print pass
signal( SIGPIPE, SIG_IGN ) ;
If debugging with GDB, GDB captures it and paused the process. To avoid this, run following command in gdb. For detailed information about handle, type "handle help" in gdb.
handle SIGPIPE nostop print pass
Thursday, October 13, 2011
How to convert p12 files to pem files for Push Notification
Example: Development certificate
1. Download the certificate from iOS Provisioning Portal. Double click to install it.
2. Once installed, it should get listed in Certificates of Keychain Access.
3. Locate "Apple Development IOS Push Services:" and right click on it, select "Export xxx" and name it dev-cert.p12 (leave the password blank for exporting)
4. Expand "Apple Development IOS Push Services:" to find the private key. Right click on it, select "Export xxx" and name it dev-key.p12 (leave the password blank for exporting)
5. Convert certificate to pem file format
openssl pkcs12 -clcerts -nokeys -out dev-cert.pem -in dev-cert.p12
6. Convert private key to pem file format (password cannot be left blank, so key in 1234 and we will remove it in next step)
openssl pkcs12 -nocerts -out dev-key-password.pem -in dev-key.p12
7. To remove the password of dev-key-password.pem, run following command. (password will be asked, enter 1234 as we set in step 6)
openssl rsa -in dev-key-password.pem -out dev-key.pem
8. Now we have both the certificate and private key (no password) converted in pem format.
9. That's it!
1. Download the certificate from iOS Provisioning Portal. Double click to install it.
2. Once installed, it should get listed in Certificates of Keychain Access.
3. Locate "Apple Development IOS Push Services:" and right click on it, select "Export xxx" and name it dev-cert.p12 (leave the password blank for exporting)
4. Expand "Apple Development IOS Push Services:" to find the private key. Right click on it, select "Export xxx" and name it dev-key.p12 (leave the password blank for exporting)
5. Convert certificate to pem file format
openssl pkcs12 -clcerts -nokeys -out dev-cert.pem -in dev-cert.p12
6. Convert private key to pem file format (password cannot be left blank, so key in 1234 and we will remove it in next step)
openssl pkcs12 -nocerts -out dev-key-password.pem -in dev-key.p12
7. To remove the password of dev-key-password.pem, run following command. (password will be asked, enter 1234 as we set in step 6)
openssl rsa -in dev-key-password.pem -out dev-key.pem
8. Now we have both the certificate and private key (no password) converted in pem format.
9. That's it!
Monday, August 29, 2011
How to compile FFMPEG in 32 bit mode for Mac OS X
./configure --extra-cflags="-arch i386" --extra-ldflags='-arch i386' --arch=x86_32 --target-os=darwin --enable-cross-compile
Monday, August 22, 2011
My favorite XCode 3 keyboard shortcuts
Keyboard:
. Shift + Option + Command + Left/Rigth arrow key: Move to Previous/Next file
. Command Left/Right arrow key: Go to beginning/end of the line
. Command + [ or ] : Indent selection leftward/rightward
. Command + R : Build and Run (Breakpoints off)
. Command + Y : Build and Debug (Breakpoints on)
. Option + Command + R : Run (Breakpoints off)
. Option + Command + Y : Debug (Breakpoints on)
Touchpad:
. 3 fingers swipe up : Switch between .m and .h files
. 3 fingers swipe Left/Right : Go Back/Forward
. Shift + Option + Command + Left/Rigth arrow key: Move to Previous/Next file
. Command Left/Right arrow key: Go to beginning/end of the line
. Command + [ or ] : Indent selection leftward/rightward
. Command + R : Build and Run (Breakpoints off)
. Command + Y : Build and Debug (Breakpoints on)
. Option + Command + R : Run (Breakpoints off)
. Option + Command + Y : Debug (Breakpoints on)
. Shift + Command + E : Zoom editor out
. Shift + Command + W : Close file
Touchpad:
. 3 fingers swipe up : Switch between .m and .h files
. 3 fingers swipe Left/Right : Go Back/Forward
Monday, July 4, 2011
Launch application at Linux startup
Edit /etc/rc.d/rc.local and add your application
Ex. /usr/src/p2pd/p2pd.sh &
Ex. /usr/src/p2pd/p2pd.sh &
Friday, June 17, 2011
Increase FD_SETSIZE
The maximum number of sockets which a Windows Sockets application can make use of is determined at compile time by the manifest constant FD_SETSIZE. This value is used in constructing the fd_set structures used in select(). The default value in winsock.h is 64. If an application is designed to be capable of working with more than 64 sockets, the implementor should define the manifest FD_SETSIZE in every source file before including winsock.h or winsock2.h. One way of doing this may be to include the definition within the compiler options in the makefile, for example adding -DFD_SETSIZE=128 as an option to the compiler command line for Microsoft C. It must be emphasized that defining FD_SETSIZE as a particular value has no effect on the actual number of sockets provided by a Windows Sockets implementation.
Wednesday, June 15, 2011
Hotkey to switch Japanese input mode
For MS IME:
To Hiragana: Shift + Caps Lock (switch between Hiragana and English)
To Katakana: Alt + Caps Lock
Thursday, June 9, 2011
ldr 12-bit displacement out of range
Somehow I get this error message while compiling my iPhone app.
The way to fix it is...
Go to Project info -> Build tab-> GCC 4.2 - Code Generation section, uncheck "Compile for Thumb".
That's it!
Wednesday, June 8, 2011
Create rounded corner view
1. #import <QuartzCore/QuartzCore.h>
2. Create a view, ex. named v
3. [v.layer setCornerRadius:8.0f] ;
4. [v.layer setMasksToBounds:YES] ;
Make sure you DO include QuartzCore/QuartzCore.h even compiler doesn't complain about it.
2. Create a view, ex. named v
3. [v.layer setCornerRadius:8.0f] ;
4. [v.layer setMasksToBounds:YES] ;
Make sure you DO include QuartzCore/QuartzCore.h even compiler doesn't complain about it.
Debugging with Android native library
To figure out the function that your native library crashed within, use arm-eabi-addr2line which comes with the Android NDK.
How to use:
1. PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so
2. type in the address to look up (the address after pc in exception logs)
or in one command
PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so AddressToLookUp
Reference:
. http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/
How to use:
1. PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so
2. type in the address to look up (the address after pc in exception logs)
or in one command
PATH_TO_ARM_EABI_ADDR2LINE/arm-eabi-addr2line -C -f -e libXXX.so AddressToLookUp
Reference:
. http://www.codexperiments.com/android/2010/08/tips-tricks-debugging-android-ndk-stack-traces/
Memory alignment
Key points:
1. Each data element is stored at an address which is a multiple of its natural size.
2. Total size of the structure or union will be multiple of the natural size of the biggest data type in the structure or union.
To reduce the memory usage (Sets the alignment of all aggregate members to a specified byte boundary), use
. #pragma pack(1) before the declaration of the structure or union for Windows.
. __attribute__ ((packed)) after the } of the declaration for Linux.
Ex1. Windows.
#pragma pack(1)
struct alignment_test
{
char x ;
int y ;
short z ;
} ;
Ex2. Linux
. http://msdn.microsoft.com/en-us/library/aa505951.aspx
. http://www.ohse.de/uwe/articles/gcc-attributes.html#type-packed
. http://www.aleph1.co.uk/chapter-10-arm-structured-alignment-faq
. http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/index.jsp?topic=/com.ibm.xlcpp9.bg.doc/compiler_ref/pragma_pack.htm
1. Each data element is stored at an address which is a multiple of its natural size.
2. Total size of the structure or union will be multiple of the natural size of the biggest data type in the structure or union.
To reduce the memory usage (Sets the alignment of all aggregate members to a specified byte boundary), use
. #pragma pack(1) before the declaration of the structure or union for Windows.
. __attribute__ ((packed)) after the } of the declaration for Linux.
Ex1. Windows.
#pragma pack(1)
struct alignment_test
{
char x ;
int y ;
short z ;
} ;
Ex2. Linux
struct alignment_test
{
char x ;
int y ;
short z ;
} __attribute__ ((packed)) ;
For details:
. http://kezeodsnx.pixnet.net/blog/post/27585076. http://msdn.microsoft.com/en-us/library/aa505951.aspx
. http://www.ohse.de/uwe/articles/gcc-attributes.html#type-packed
. http://www.aleph1.co.uk/chapter-10-arm-structured-alignment-faq
. http://publib.boulder.ibm.com/infocenter/compbgpl/v9v111/index.jsp?topic=/com.ibm.xlcpp9.bg.doc/compiler_ref/pragma_pack.htm
Monday, March 14, 2011
Displaying a video in Flex using the NetConnection, NetStream, and Video classes
Good Adobe Flex articles!
http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/
Also, using VLC and FFMpeg with Flex to accomplish screen recording
http://www.adobe.com/devnet/air/flex/articles/air_screenrecording.html
http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/
Also, using VLC and FFMpeg with Flex to accomplish screen recording
http://www.adobe.com/devnet/air/flex/articles/air_screenrecording.html
Wednesday, March 9, 2011
Excel financial formulas - PMT
Pmt function returns the payment amount for a loan based on an interest rate and a constant payment schedule.
Pmt( interest_rate, number_payments, PV )
PV : Present Value
To find out the monthly payment on a 1,000,000 loan at an annual rate of 7.5%. The loan is paid off in 2 years (ie: 2 x 12). All payments are made at the beginning of the period.
=Pmt(7.5%/12, 2*12, 1000000)
Reference:
http://www.techonthenet.com/excel/formulas/pmt.php
http://www.masterhsiao.com.tw/ExcelFinance/PMT/PMT.htm
Pmt( interest_rate, number_payments, PV )
PV : Present Value
To find out the monthly payment on a 1,000,000 loan at an annual rate of 7.5%. The loan is paid off in 2 years (ie: 2 x 12). All payments are made at the beginning of the period.
=Pmt(7.5%/12, 2*12, 1000000)
Reference:
http://www.techonthenet.com/excel/formulas/pmt.php
http://www.masterhsiao.com.tw/ExcelFinance/PMT/PMT.htm
年化報酬率公式
年化報酬率公式 = ( (期末金額 / 期初金額) ^ (1 / 年期) ) - 1
^ : 冪次方
Ex. 一開始以10萬元去投資, 3年後結束投資, 拿回 14萬. 年化報酬率為:
( 140000 / 100000 ) ^ ( 1 / 3 ) - 1 = 約 11.87%
^ : 冪次方
Ex. 一開始以10萬元去投資, 3年後結束投資, 拿回 14萬. 年化報酬率為:
( 140000 / 100000 ) ^ ( 1 / 3 ) - 1 = 約 11.87%
貸款利率
貸款利率. 用 Excel 套入公式
=RATE( 期數, -月繳款金額, 貸款金額 ) * 12 = 年利率
Ex. 貸款 100 萬, 分4年(48期)攤還, 每個月繳 23000
則年利率是: RATE( 48, -23000, 1000000 ) * 12 = 0.04935 (4.935%)
貸款利息每一期都不一樣,因為貸款利息是以上一期的貸款餘額乘上貸款利率;
由於每一期的貸款餘額會隨著本金的攤還而愈來愈少,每一期的所繳的利息當然也會愈來愈少.
=RATE( 期數, -月繳款金額, 貸款金額 ) * 12 = 年利率
Ex. 貸款 100 萬, 分4年(48期)攤還, 每個月繳 23000
則年利率是: RATE( 48, -23000, 1000000 ) * 12 = 0.04935 (4.935%)
貸款利息每一期都不一樣,因為貸款利息是以上一期的貸款餘額乘上貸款利率;
由於每一期的貸款餘額會隨著本金的攤還而愈來愈少,每一期的所繳的利息當然也會愈來愈少.
Monday, January 3, 2011
Steps to install Bugzilla on CentOS 5.4
1. Disable selinux
vi /etc/selinux/config
set SELINUX=disabled
2. Add one iptables rule to allow TCP port 80 for httpd
vi /etc/sysconfig/iptables
add following rule
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
service iptables restart
3. Install required components
yum install perl
yum install httpd
yum install mysql-server
yum install mysql
yum install php-mysql
yum install gcc
yum install cvs
yum install patchutils
yum install mysql-devel
4. Install bugzilla
cd /var/www
rmdir html
wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.6.3.tar.gz
tar xzvf bugzilla-3.6.3.tar.gz
mv bugzilla-3.6.3 html
5. Apache configuration
vi /etc/httpd/conf/httpd.conf
find < directory "/var/www/html" > section and ..
1. Append ExecCGI to "Optoins"
2. Add "DirectoryIndex index.cgi index.html" under "Options"
Uncomment AddHandler cgi-script .cgi
service httpd start
6. Check if all the required perl modules are installed
./checksetup.pl --check-modules
to install all missing modules, run following command
perl install-module.pl --all
once doen, check modules again to see if it's ok
if DBD-mysql is not ok, run "perl install-module.pl DBD:mysql" to install it
7. Create localconfig
./checksetup.pl
modify the $db_pass of localconfig
vi ./localconfig
$db_pass = "howard"
8. Increase attachment size to 3MB, for example.
vi /etc/my.cnf
add "max_allowed_packet=3M"
service mysqld restart
9. Create mysql user
mysql -u root -p
GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES, CREATE TEMPORARY TABLES, DROP, REFERENCES ON bugs.*TO bugs@localhost IDENTIFIED BY 'howard';
FLUSH PRIVILEGES;
10. Create bugzilla database and administrator account
run ./checksetup.pl and follow the instructions to create the administrator account
once done, run ./checksetup.pl again to make sure everything is ok
Now bugzilla should be ready to go, connect to it via browser and complete the one time setup.
That's all.
Notes:
. To fix "Error when close pipe to /usr/lib/sendmail (while creating account), you have to allow SMTP connection in SELinux by run "setsebool -P httpd_can_sendmail 1" without quotes.
vi /etc/selinux/config
set SELINUX=disabled
2. Add one iptables rule to allow TCP port 80 for httpd
vi /etc/sysconfig/iptables
add following rule
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
service iptables restart
3. Install required components
yum install perl
yum install httpd
yum install mysql-server
yum install mysql
yum install php-mysql
yum install gcc
yum install cvs
yum install patchutils
yum install mysql-devel
4. Install bugzilla
cd /var/www
rmdir html
wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.6.3.tar.gz
tar xzvf bugzilla-3.6.3.tar.gz
mv bugzilla-3.6.3 html
5. Apache configuration
vi /etc/httpd/conf/httpd.conf
find < directory "/var/www/html" > section and ..
1. Append ExecCGI to "Optoins"
2. Add "DirectoryIndex index.cgi index.html" under "Options"
Uncomment AddHandler cgi-script .cgi
service httpd start
6. Check if all the required perl modules are installed
./checksetup.pl --check-modules
to install all missing modules, run following command
perl install-module.pl --all
once doen, check modules again to see if it's ok
if DBD-mysql is not ok, run "perl install-module.pl DBD:mysql" to install it
7. Create localconfig
./checksetup.pl
modify the $db_pass of localconfig
vi ./localconfig
$db_pass = "howard"
8. Increase attachment size to 3MB, for example.
vi /etc/my.cnf
add "max_allowed_packet=3M"
service mysqld restart
9. Create mysql user
mysql -u root -p
GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES, CREATE TEMPORARY TABLES, DROP, REFERENCES ON bugs.*TO bugs@localhost IDENTIFIED BY 'howard';
FLUSH PRIVILEGES;
10. Create bugzilla database and administrator account
run ./checksetup.pl and follow the instructions to create the administrator account
once done, run ./checksetup.pl again to make sure everything is ok
Now bugzilla should be ready to go, connect to it via browser and complete the one time setup.
That's all.
Notes:
. To fix "Error when close pipe to /usr/lib/sendmail (while creating account), you have to allow SMTP connection in SELinux by run "setsebool -P httpd_can_sendmail 1" without quotes.
Subscribe to:
Posts (Atom)
Check clients which connect to Mac OS X Wi-Fi Internet Sharing
arp -i bridge100 -a bridge100 may be different on your Mac OSX
-
For Mac OS: Use lipo. Ex. lipo -info staticLibrary.a For Linux OS: Use file Ex. file staticLibrary.c
-
[轉貼]用GCC自製Library 引用 : PTT 看板 : LinuxDev ( 作者 : cole945) Library 可分成三種, static 、 shared 與 dynamically loaded 。 1. Static libr...
-
1. Create an account on TestFlight ( http://testflightapp.com ) and with "Developer" option checked. 2. Log in to the TestFlight ...