通过J2ME的录音功能实现简易示波器
早就有人通过PC声卡的输入(麦克风孔)来做模拟示波器,但是用手机来实现的比较少。用J2ME的MMAPI实现模拟示波器,具体效果稍逊于智能机,因为智能机可以实时读取麦克风输入流,而J2ME还需要有短暂的缓冲构成了阻塞,不过,实现出来玩一下还是足够了。
先贴出效果图:
左图是程序在WTK
运行的结果,右图是Audition读取音频输入口的波形,信号源是一个经过信号放大的压力传感器。
程序使用NetBeans + LWUIT类库,接下来贴出全部代码:
view plaincopy to clipboardprint?
import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import java.io.ByteArrayOutputStream;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
/**
* @author 张国威
*/
public class Frm_MainMenu extends javax.microedition.midlet.MIDlet implements ActionListener {
public Form form ;
private Command cmdExit = new Command("退出", 1);
private ThreadReceive threadReceive =new ThreadReceive();//接收数据线程
private Cmp_Wave cmp_HeartWave=null;
private Player capturePlayer = null;
private RecordControl recordControl = null;
private ByteArrayOutputStream bos = new ByteArrayOutputStream();
public void startApp() {
Display.init(this);
form = new Form();//达到全屏的效果
cmp_HeartWave=new Cmp_Wave(form.getHeight(),form.getWidth());
form.getStyle().setBgImage(null);//本窗体不需要背景
form.addCommand(cmdExit);
form.setCommandListener(this);
form.setLayout(new BorderLayout());
//设置画板控件
form.addComponent(BorderLayout.CENTER,cmp_HeartWave);//添加控件
form.show();
try {
capturePlayer = Manager.createPlayer("capture://audio?rate=8000&bits=8&channels=1");//PCM,8位,8kH
if (capturePlayer != null) {
capturePlayer.realize();
recordControl = (RecordControl) capturePlayer
.getControl("javax.microedition.media.control.RecordControl");
if (recordControl == null)
&nb
相关新闻>>
- 发表评论
-
- 最新评论 更多>>