Friday, August 2, 2013

Android Audio Arduino: Cross compiling native audio libraries for Android...

Android Audio Arduino: Cross compiling native audio libraries for Android...: Update July, 31 2013: Use more recent libs and NDK Preface In my science shows I'm using many sound cues - like playing an intro whe...

Saturday, July 20, 2013

CRFSC 笔记

ACTS —— The Vital Four ACTS of Firearm Safety

A:    Assume every firearm is loaded.
C:    Control the muzzle direction at all times.
T:    Trigger finger must be kept off the trigger and out of the trigger guard.
S:     See that the firearm is unloaded——PROVE it safe.

"PROVE" Safe

P:      Point the firearm in the safest available direction.
R:     Remove all ammunition.
O:     Observe the chamber.
V:     Verify the feeding path.
E:     Examine the bore for obstructions. 

Monday, July 15, 2013

Android NDK 基本概念及注意事项


  1. 必须作为原生动态链接库(native shared library) 提供。文件名必须符合Unix库文件命名规范,必须包含标准的JNI入口函数。例:

    libname.so 
  2. 应用必须显式加载该库。通常在应用启动时加载。例:
  3. static {
    System.loadLibrary("FileLoader");
    }

    注意:不能包含"lib"前缀和.so 后缀。

Saturday, July 13, 2013

流水帐

完成sndfile 学习。

gcc -l 参数 要把前缀lib去掉 。比如要库文件名是libsndfile.a 则:

gcc -lsndfile

Friday, June 25, 2010

Linux 系统 C++ 开发工具概述

本文转自 http://www.linuxidc.com/Linux/2009-02/18381.htm


概述
就C++开发工具而言,与Windows下微软(VC, VS2005等)一统天下相比,Linux/Unix下C++开发,可谓五花八门,各式各样。Emacs, vi, eclipse, anjuta,kdevelop等层出不穷。
Windows下,开发工具多以集成开发环境IDE的形式展现给最终用户。例如,VS2005集成了编辑器,宏汇编ml,C /C++编 译器cl,资源编译器rc,调试器,文档生成工具, nmake。它们以集成方式提供给最终用户,对于初学者而言十分方便。但是,这种商业模式,直接导致用户可定制性差,不利于自动化,集成第三方工具的能力 弱。例如,无法定制一些宏来处理一些重复操作;体会不到自动化makefile一步到位快感;无法远程登录到服务器上进行开发;无法使用某种”粘合剂”来 把第三方工具(例如,文本工具,字符串工具)有效地调用起来。可以说,良好的商业支持和傻瓜式开发,是它们主要的优点。
在Linux下, 开发工具被切割成一个个独立的小工具。各自处理不同的问题。例如,编辑器(emacs, vim)用来进行编辑程序的,调试器(gdb)用来调试程序,编译器(GCC)用来编译和链接程序的,性能分析工具(gcov, gprof)用来优化程序的,文档生成器(doxygen)用来生成文档的。同时,还有一些系统工具和系统知识,我们是很有必要了解的:程序自动化机制 makefile,系统粘合剂shell,系统查找工具grep, locate, find。其它的工具(例如ctags, OCI公司的MPC等等),一旦熟练掌握,它们将成为你手中的利器。
本文主要是一些针对Linux下开发工具使用的经验之谈。由于,工具品种繁多,我们没有能力也没有必要一一介绍。对于Linux下IDE工具,例如 eclipse, anjuta等,它们虽然也很实用,但是使用起来比较简单,而且目前还算不上主流。所以,它们将不被着重介绍。同时,本文也不打算写成各个工具的操作手 册,只着眼于介绍各个工具的想要解决的问题、运行机理和主要特性。



编辑器
要进行开发,第一件事情就是选择一个合适的编辑器。编辑器选择有几个要素:
1)减少不必要的编辑动作,减少编辑的时间。
一切能够无二义性描述出来的编辑任务,都可以而且应该能被自动化。例如,每一个C++程序都会有一个main函数;我们在定义.h文件时,都希望加入一些 预处理指令#define来帮我们解决重复引用同一个头文件而带来的麻烦。鼠标操作总是比键盘操作要慢的。这方面EMACS做得可算是到了极致。所以, EMACS用户经常会吹嘘:他们编辑的速度等同于他们思考的速度。

2)可扩展性高。
程序员预期的编辑器应该能提供一些编程的帮助,例如,语法高亮,自动补齐,自动排版,语法检查等等。留心观察一下gedit, vim, emacs, ultraEdit,就会发现它们提供的远不是windows 记事本,写字板提供的那么简陋的功能。对于一种新的语言,新的语法,它们应该能很方便地提供支持,而不停留在一种或几种固定的语言上。
3)用户可定制性高。
如果想长期从事研发,特别是Linux/unix下研发的话,那么你很有必要学好一个功能足够的编辑器。有这么一句话:Linux下程序员分为三种,使用emacs的,使用vi的,还有其它。
EMACS是Stallman用lisp语言写的一个GPL的编辑器。我们这里所说的emacs指的是GNU emacs,而非Xemacs。由于它的开放性,我们可以把它打造成一个功能强大的IDE。我们在安装好CGYwin之后,也可以在Windows系统下 使用 EMACS。CGYwin和MINGW是第三方写的一个在Windows系统上模拟POSIX系统的工具。
EMACS与其说的是一个编辑器,倒不如说它是一个操作系统。我们可以用它来写编程,写wiki,收发邮件等等。EMACS主要是通过两种方式来进行扩 展:el脚本(elisp是lisp的一种方言)和第三方扩展包。EMACS的入门成本很高。由于是纯键盘操作,所以需要记忆大量的快捷键;功能强大是通 过用户添加一些扩展包,lisp脚本来实现的。如何正确配置和修改是很需要耐心和技巧的。


编译器
编译器首选GCC(GNU COMPILER COLLECTION)。原因有两个,它是GNU开源的,同时它对标准C++的 支持度高达96.15%。而VC++6.0的支持度只有83.43%。 GCC不仅是通常意义上的C或C++的编译器,它还可以编译java等其它语言。gcc是gnu c的编译器,g++是gnu c++的编译器, 而EGCS(Enhanced GNU Compiler Suite)可以认为是gcc的改进版。

编译语言从源程序到目标代码会经过如下几个阶段:源程序->汇编程序->编译成obj程序->链接成最终可执行程序。我们可以通过一条编译指令来完 成所有步骤。也可以分步执行。gcc有三个重要选项-E(只进行预处理), -S(生成汇编代码), -g(生成带原代码调试符号的可执行文件,如果想用gdb调试的话,就应该在编译时打开这个选项)。
GCC可以看作一个软件包,除了编译工具,它还集成了调试器gdb,性能分析工具gcov, gprof。只要我们装好了GCC,这些强大工具就可以直接使用了。
通过gcov,我们可以查看一个程序,源代码中每行代码的运行次数。我们优化运行次数最多的代码,那么就可以大大优化程序。使用gcov时,需要打开 GCC的fprofile-arcs和ftest-coverage两个选项。gcov中常用的选项有-b分支统计信息。
通过gprof工具,我们可以查看函数之间的调用顺序,及各个函数运行的时间。我们可以将gprof理解为Linux/unix自带工具time的加强版。使用gprof时,需要打开GCC的pg选项。
gcov和 gprof的共同点是在编译程序时,加入自己的一些辅助信息,由此来进行程序诊断。除了,这些优化手段,我们还可以使用一些内存泄漏工具,来减少野指针,未释放的内存空间。



调试器
GDB即GNU的调试器,它是GCC附带的一个性能优质的调试器。通过GDB和脚本结合,我们可以很好的实现回归测试。
GDB可以运行于CLI和GUI两种模式。默认GDB是CLI模式的,我们可以去下载和安装GUI模式的GDB,例如xxgdb, ddd等。一个更好的方式是在 EMACS中使用GDB。GDB包括visual studio工具的所有调试功能,还 包括它没有的功能。它除了支持,我们一般的设置断点,单步跟踪,step in, step out, step over等,还有一些强大的功能。在gdb中,我们可以有以下几种暂停方式:断点(BreakPoint)、观察点(WatchPoint)、捕捉点 (CatchPoint)、信号(Signals)、线程停止(Thread Stops)。

下面列举几个让我印象深刻的功能。1)通过 watch指令,可以让程序在某个变量的值发生变化时,暂停下来。2)通过print指令,在程序运行时,设置变量的值,运行一个程序自身支持的一个方 法。3)通过until指令,我们可以让程序在运行到某个程序时暂停下来。4)通过break.. if指令,使得程序在满足某个bool表达式时,暂停下来。

粘合剂
我想通过”粘合剂”这个词来表达将多个工具粘合起来的”胶水”。例如,通过shell脚本,我们可以把OS命令,sed指令,awk指令,其它脚本文件等 串联起来,发挥它们的合力。在Linux C++编程中,我们不可避免地会使用makefile文件。通过,它我们可以把编译指令,生成文档操作,清除操作等等串联起来。从某种意义上来看,它也相 当于一个粘合剂。

makefile的出发点是,维护好一个项目中众多文件的依赖关系,由此得到一个源程序的拓扑图。当我们只修改图中某个结点时,重新编译时就只需要将拓扑 图中关联的链路进行编译就好了。由此,大大缩短了编译的时间。make有两大概念:dependencies和rules。规则rule即针对每一个依赖 关系 dependency定义一个操作规则。这个细粒度的分离,就可以使我们可以定制软件构建的行为。例如,修改使用的编译器,修改includepath, 修改libpath, 修改编译选项等等。我们常见的VC中的nmake,功能和make是类似的。
make使用的重点和难点是编写Makefile文件。Makefile的语法相对其它语言来说是很不一样的,我们要特别注意TAB键和空格键的区别。有 很多工具可以用来帮助我们生成Makefile。最出名的就是GNU的autoconf了。一个GNU程序的编写,需要autoscan, aclocal, autoconf, automake这四个工具。
我们知道GNU软件安装的三步曲是:./configure, make, make install。其中./configure就是根据autoconf, alocal等工具生成一个makefile文件。make指令就是调用make指令来根据makefile文件的规则来编译源程序。而make install就是执行makefile中的install规则指出的操作(一般是copy操作)。而make clean就是执行makefile中的clean规则指出的操作(一般是rm操作)。我们用Eclispe+CDT开发Managed C++ Project时,它就是通过objects.mk,subdir.mk,sources.mk三个文件来生成Makefile。我们注意观察编译时的输 出信息,就可以看到显示的Makefile文件的内容。
可以说,如果想编译出跨平台的C++程序,那么makefile是一种最方便的机制。
OCI公司为Douglas C.Schmidt的ACE,TAO开源社区编写了一段伟大的perl脚本--MPC。它由平台信息,一个规则文件,源代码,生成用户想要的工程文件,例 如Make, Nmake, Visual C++ 6, Visual C++ 7等等。Google Web Tookit, Celtix做的事情与之类似,不过它们是针对JAVA的,而MPC是针对C++的。


结束语
国内资料太多的低层次的重复,经常是一个网页被多次转载,而且回答问题时深度不够。个人找资料的顺序是:查看quick start或how to文档->自带的帮助(如果看起来不太吃力话)->百度查一下中文网页,来理清一下基本概念->google查一下->几个大的,相关的网站查下资料 ->看自带帮助。再者,面对面的交流是十分重要的,大家可以相互理一下概念,交流一下心得。可惜,我身边这种氛围还是不够。

Linux下开发还可以更友好一些。个人感觉, Linux开发要在国内普通程序员中大规模普及,还有一段很长的路要走。Ubuntu火 爆的主要原因,就是它帮用户搭好一些默认配置。用户如果想新加一些 服务,它们提供了良好,有效地支持。所以,我想我们可以在IDE和现在Linux这种一个个小部件的这两种状态之间,取一个折衷。也就是针对几种主要需求 的用户,发布一些配置好的环境。尤其是emacs的各种el脚本(例如界面主题的color-theme, C/C++语言编辑策略,代码样式设置脚本,各种emacs系统设置), 第三方扩展包(模板template, 编程支持包cedet等)。每一个用户浪费时间来进行这些配置是十分没有意义的!工具始终只是工具,我们不能沦为工具的奴隶,不能把一大部分精力浪费在配 置工具上。
值得注意的是现在方兴未艾的eclipse有向这方面迈进的趋势。但是,现在emacs已经做得很好了,ecilpse能否超越它,我们还有待观察。我们 可以通过在eclipse上安装SDT插件来进行C++开发。但是,它目前还不支持调试功能,而且不太稳定,功能不够强。例如,有时会无故死掉;如果想通 过eclipse来转向函数原型的话,那么迎接你的将是一个漫长、焦急的等待。
由于本人缺少在Linux下进行实际大规模程序的开发经验,对很多工具和机制的理解还比较肤浅。对它们的熟悉程度离真正实用,还有一段很长的路要走。

Tuesday, May 25, 2010

Scheduling Jobs in Linux

Scheduling one-time jobs
If you want to run one or more commands at a later time, you can use the at command. The atd daemon --- a program designed to process jobs submitted using at --- runs you commands at the specified time and mails the output to you.

Before you try the at command, you need to know that the following configuration files control which users can schedule tasks using the at command:

  • /etc/at.allow contains the names of the users who may submit joibs using the at command.
  • /etc/at.deny contains the names of the users not allowed th submit jobs using the at command.
If these file aren't present or if you find an empty /etc/at.deny file, any user can submit jobs by using the at command. The default in Linux is an empty /etc/at.deny file; with this default in place, anyone can use the at command.

To use at to schedule a one-time job for execution at a later time, follow these steps:

1. Run the at command with the date or time when you want your commands executed.
    When you press Enter, the at> prompt appears, as follows:
        at 21:30
        at>

    Simply specify the time in a 24-hour format. In this case, you want to execute the commands at 9:30pm. tonight ( or tomorrow, if it's already past 9:30pm.). 

2. At the at> prompt, type the commands you want to execute as if typing at the shell prompt. After each command, press Enter and continue with the next command. When you finish entering the commands you want to execute, press Ctrl+D to indicate the end.

Here's an example showing how to execute the ps command at a future time:

at> ps
at>
job 1 at 2010-05-24 21:30

After you press Ctrl+D, the at command responds with a job number and the date and time when the job will execute.


Formats for the Time of Execution with the at Command
CommandWhen the Job will Run
at nowImmediately
at now + 15 minutes15 minutes from current time
at now + 4 hours4 hours from the current time
at now + 7 days7 days from the current time
at noonAt noontime today(or tomorrow,if already past noon)
at now next hourExactly 60 minutes from now
at now next dayat the same time tomorrow
at 17:00 tomorrowat 5pm. tomorrow
at 4:45pmAt 4:45pm. today(or tomorrow, if it's already past 4:45pm)
at 3:00 Dec 28,2008At 3:30am on December 28,2008

atq command uses to view current list of scheduled jobs:

The output looks similar to the following:

4         2006-12-28   03:00    a    root
5         2006-12-26   21:57    a    root
6         2007-10-26   16:45    a    root

The first field on each line shows the job number --- the same number that the a command displays when you submit the job. The next field shows the year, month, day, and time of execution. The last filed shows the jobs pending in the a queue.

If you want to cancel a job, use the atrm command to remove that job from the queue. When removing a job with the atrm command, refer to the job by its number, as fllows:

atrm 4


Scheduling recurring jobs


crontab command : used to schedule

You schedule recurring jobs by placing job information in a file with a specific format and submitting this file with the crontab command. The cron daemon --- crond ---- checks the job information every minute and executes the recurring jobs at the specified times. Because the cron daemon processes recurring jobs, such jobs are also referred to as cron jobs.

Any output from a cron job is mailed to the user who submits the job. (In submitted job-information file, you can specify a different recipient for the mailed output.)

Two configuration files control who can schedule cron jobs using crontab:


  • /etc/cron.allow contains the names of the users who may submit jobs using the crontab command.
  • /etc/cron.deny contains the names of users not allowed to submit jobs using the crontab command.
If the /etc/cron.allow file exists, only users listed in this file can schedule cron jobs. If only the /etc/cron.deny file exists, users listed in this file can't schedule cron jobs. If neither file exists, the default Linux setup enables any user to submit cron jobs.

To submit a cron job, follow these steps:

1. Prepare a shell script (or an executable program in any programming language) that can perform the recurring task you want to perform.
    You can skip this step if you want to execute an existing program periodically.

2. Prepare a text file with information about the times when you want the shell script or program (from Step 1) to execute and then submit this file by useing crontab.
    You can submit several recurring jobs with a single file. Each line with timing information about a job has a standard format with six fields --- the first five specify when the job runs, and the sixth and subsequent fields constitute the actual command that runs. For example, here's a line that executes the myjob shell script in a user's home directory at five minutes past midnight each day:
     5 0 * * *  $HOME/mujob
Next table shows the meaning of the first five fields.

3. Suppose the text file jobinfo (in the current directory) contains the job information. Submit this information to crontab with the following command:
    crontab jobinfo
That's it! You're set with the cron job. From now on, the cron job runs at regular intervals ( as specified in the job information file), and you receive mail messages with the output from the job.

Format for the Time of Execution in crontab Files
Field NumberMeaning of FieldAcceptable Range of Values*
1Minute0-59
2Hour of the day0-23
3Day of the month0-31
4Month1-12 or the names of month using the first three letters
5Day of the week0-6 or the three-letter abbreviations of weekdays
*An asterisk in a field means all possible values for that field. For example, if an asterisk in the third field,the job is executed avery day.

To Vereify that the job is indeed scheduled, type the following command:

crontab  -1

The output of the crontab -1 command shows the cron jobs currently installed in your name. To remove you cron jobs, type crontab -r.

Wednesday, May 19, 2010

巴菲特2010年第二季度完全持股名单


  新浪财经讯 “股神”巴菲特旗下的伯克希尔哈萨韦公司(Berkshire Hathaway)刚刚披露了截至2010年3月31日的最新持股名单。这是我们能够了解到的巴菲特最新的持股数据,尽管个别持仓3月份以来可能略有变化。下面这个名单是按照字母顺序从A-Z排列的。
  美国运通(American Express)(AXP) 超过1.5160亿股,与上一季度相同。
  美国银行(Bank of America)(BAC) 500万股,与上一季度相同。
  Becton Dickinson(BDX) 增持至174.4万股,上一季度为150万股,两个季度前为120万股。
  CarMax(KMX) 减持至772.5万股,上一季度为800万股,两个季度前为900万股。
  可口可乐(Coca Cola)(KO) 刚好2亿股,与上一季度相同。
  Comcast(CMCSA) 1200万股,与上一季度相同。
  Comdisco Holdings(CDCO) 大约150万股,与上一季度相同。
  康菲石油(ConocoPhillips)(COP) 减持至3417.9万股,上一季度为3770万股,两个季度前为5743万股,去年6月底为6248.5万股。
  好市多(Costco Wholesale)(COST) 减持至433.3363万股,上一季度为525.4万股。
  埃克森美孚(Exxon Mobil)(XOM) 42.18万股,与上一季度相同,这是两个季度前的新头寸,当时持股为127.6万股。
  Gannett(GCI) 减持至174.0231万股,上一季度为220.2万股,两个季度前为344.7万股。
  通用电气(General Electric)(GE) 777.7万股,与上一季度相同,但没有包括2008年年底的巨额优先股投资。
  高盛(Goldman Sachs)(GS) 高盛不在名单之上,不过这是因为伯克希尔持有的并非高盛普通股,而是优先股和认股权证。巴菲特说他依然持有这些优先股和认股权证。
  葛兰素史克(GlaxoSmithKline PLC)(GSK) 151万股,与上一季度相同。
  哈雷戴维森(Harley-Davidson)(HOG) 不是普通股,但巴菲特仍持有其优先股和认股权证。
  家得宝(Home Depot)(HD) 275.7万股,与上一季度相同。
  英格索兰(Ingersoll-Rand)(IR) 63.66万股,与上一季度相同,但三个季度前为778万股。
  Iron Mountain(IRM) 增持至779.48万股,上一季度为700万股,两个季度前为337.22万股。
  强生(Johnson & Johnson)(JNJ) 减持至2390万股左右,上一季度为2700万股多一点,两个季度前为3691万股,而2008年一度持股高达6200万股。
  卡夫食品(Kraft Foods)(KFT) 减持至1.067亿股,上一季度为超过1.38亿股。巴菲特对于卡夫收购吉百利的交易一直持批评态度。
  Lowe's Companies(LOW) 650万股,与上一季度相同。
  M&T Bank(MTB) 减持至556.3万股,上一季度为671万股。
  穆迪(Moody's)(MCO) 连续减持至3083万股,上一季度为3180万股,两个季度前为3920万股,再往前一个季度则达到4800万股。
  Nalco Holding(NLC) 900万股,与上一季度相同。
  雀巢(Nestle)美国存托凭证(ADR) 340万股,与上一季度相同。
  耐克(Nike)(NKE) 764.1万股,与上一季度相同。
  宝洁(Procter & Gamble)(PG) 连续减持至7831.7万股,上一季度大约为8750万股,两个季度前为9630万股。
  Republic Services(RSG) 增持至1082.7万股,上一季度为829万股。该股为巴菲特两个季度前跟随比尔·盖茨的投资步伐开始持有。
  赛诺菲-安万特(Sanofi Aventis)(SNY) 超过390万股,与上一季度相同。
  蒂芙尼(Tiffany & Co)(TIF) 不是普通股,但巴菲特依然持有其优先股和认股权证。
  Torchmark(TMK) 大约282万股,与上一季度相同。
  US Bancorp(USB) 大约6900万股,与上一季度相同。
  USG Corp(USG) 1707.2万股,与上一季度相同。
  United Parcel Service(UPS) 142.9万股,与上一季度相同。
  沃尔玛(Wal-Mart Stores)(WMT) 略超3900万股,与上一季度相同,上一季度增持之前为3780万股,远高于3个季度之前的1990万股。
  华盛顿邮报(Washington Post)(WPO) 超过172万股,与上一季度相同。
  富国银行(Wells Fargo)(WFC) 大约3.195亿股,与上一季度基本不变,两个季度前为3.133亿股,三个季度前为3.02亿股,再往前一个季度为2.9亿多股。
  Wesco Financial(WSC) 570.3万股,与上一季度相同。
  Sun Trust Bank(STI) 全部出清。上一季度为将近240万股,两个季度前为307.9万股,三个季度前超过320万股。
  Travelers Cos(TRV) 全部出清。不过此前也仅少量持有27336股。
  United Health(UNH) 全部出清。上一季度为117.5万股,此前已经连续三四个季度不断减持。
  Wellpoint(WLP) 全部出清。清仓之前的上一季度为持有134.3万股。
  注:原文来自24/7 Wall St。

Search This Blog