EMIPLIB1.0.0的使用(一)

上次已经编译通过了EMIPLIB-1.0.0,下面来学习怎么使用EMIPLIB。先从里面的例子开始。

先编译下最简单的例子。 example文件夹里的simplechain.cpp

新建一个VC2008工程,源文件里添加 simplechain.cpp,在项目属性里设置包含头文件目录,库文件目录,库文件名

这个例子有用到的头文件:jthread-1.2.1, jrtplib-3.7.1, emiplib-1.0.0  用到的三个库也是对应的。 暂时没有用到speex。

编译时提示找不到unistd.h,这个是linux下的系统头文件,注释掉便可以了。

输出结果:

Time: 1301639510.000000
Chain: Simple chain
Iteration: 1
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639510.000000
Chain: Simple chain
Iteration: 2
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639511.000000
Chain: Simple chain
Iteration: 3
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639511.000000
Chain: Simple chain
Iteration: 4
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639512.000000
Chain: Simple chain
Iteration: 5
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639512.000000
Chain: Simple chain
Iteration: 6
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639513.000000
Chain: Simple chain
Iteration: 7
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639513.000000
Chain: Simple chain
Iteration: 8
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639514.000000
Chain: Simple chain
Iteration: 9
MIPMessage type: 1
MIPMessage subtype: 2

Time: 1301639514.000000
Chain: Simple chain
Iteration: 10
MIPMessage type: 1
MIPMessage subtype: 2

本文的例子可以在这里下到:simplechain.rar

EMIPLIB的文档 emiplib-1.0.0文档

摘下文档里面的重点

Design philosophy 设计哲学

库的目标是设计一个可以用很多小组件通过链组合起来实现功能强大的程序;另外,库也封装了很多小组件形成特定功能的类,如voip类,给编程人员提供简单的接口。

Library core 库的核心

基层部分

组件 components                           组件继承自 MIPComponent

组件链 component chains               链继承自 MIPComponentChain

消息 messages   消息继承自 MIPMessage

用法示例

 loopchain.setChainStart(&sndin);
 loopchain.addConnection(&sndin,&sndout);
 loopchain.start();

上面例子链loopchain将两个组件sndin与sndout链接起来。当loopchain start时,创建了一个后台线程,此后台线程进行下面的工作

1.A MIPSystemMessage with subtype MIPSYSTEMMESSAGE_TYPE_WAITTIME开始创建,并被发往链loopchain的第一个组件sndin,在本例中,第一个组件是声卡,声卡接收到这个消息后,会等待直到采集一定量的声音样本数,

2.然后loopchain往链的下面传输数据,在本例中是传给sndout,声卡输出

3.当所有的消息已经被分发(distribute)后,MIPSYSTEMMESSAGE_TYPE_WAITTIME重新发到链的第一个组件声卡处,然后开始循环。当调用loopchain.stop()时,或出现一个错误时,链循环停止。

就像上面所说的,链的计时是链的第一个组件决定的

 

好了,文档的东西到此已经可以解释本例子的东西了,下面将例子贴出来吧

simplechain.cpp
  1. int main(void)
  2. {
  3.     // We'll initialize the timer to generate messages after 0.5 seconds.
  4.     MIPAverageTimer timer(MIPTime(0.5));
  5.     MIPMessageDumper msgDump;
  6.     MyChain chain("Simple chain");
  7.     bool returnValue;
  8.  
  9.     // The timing component and message dumper don't require further
  10.     // initialization, so we'll just add them to the chain.
  11.  
  12.     returnValue = chain.setChainStart(&timer);
  13.     checkError(returnValue, chain);
  14.  
  15.     returnValue = chain.addConnection(&timer, &msgDump);
  16.     checkError(returnValue, chain);
  17.  
  18.     // Now, we can start the chain.
  19.  
  20.     returnValue = chain.start();
  21.     checkError(returnValue, chain);
  22.  
  23.     // We'll wait five seconds before stopping the chain.
  24.     MIPTime::wait(MIPTime(5.0));
  25.  
  26.     returnValue = chain.stop();
  27.     checkError(returnValue, chain);
  28.  
  29.     return 0;
  30. }

 

例子中的第一个组件便是timer,MIPTime(0.5)将它设成每隔0.5秒触发一次。   MIPTime::wait(MIPTime(5.0))等待5s后就stop那个链chain,回头看看上面的输出,明白了吧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值