本文融合SurfaceView构建一个Android版的手机模拟信号示波器(PS:以前也谈过J2ME版的手机示波器)。最近物联网油炸得很火,作为手机软件开发者,如何在不改动手机硬件电路的前提下构建与第三方传感器融合呢?麦克风就是一个很好的ADC模块,通过麦克风与第三方传感器融合,再行在软件里对模拟信号做到适当的处置,就可以获取更加非常丰富的传教化应用于。
再行来想到本文程序运行的效果图(屏幕视频速度较快,真机实际运营一起不会更为简洁):本文程序用于8000hz的比特率,对X轴方向绘图的实时性拒绝较高,如果不减少X轴的分辨率,程序的实时性较好,因此程序对X轴数据增大区间为8倍~16倍。由于使用16位取样,因此Y轴数据的高度相对于手机屏幕来说也偏高,程序也对Y轴数据做到增大,区间为1倍~10倍。
在SurfaceView的OnTouchListener方法里重新加入了波形基线的方位调节,必要在SurfaceView控件上触碰才可掌控整体波形偏上或偏下表明。main.xml源码如下:viewplaincopytoclipboardprint??xmlversion=1.0encoding=utf-8?LinearLayoutxmlns:android=/apk/res/androidandroid:orientation=verticalandroid:layout_width=fill_parentandroid:layout_height=fill_parentLinearLayoutandroid:id=@+id/LinearLayout01android:layout_height=wrap_contentandroid:layout_width=fill_parentandroid:orientation=horizontalButtonandroid:layout_height=wrap_contentandroid:id=@+id/btnStartandroid:text=开始android:layout_width=80dip/ButtonButtonandroid:layout_height=wrap_contentandroid:text=暂停android:id=@+id/btnExitandroid:layout_width=80dip/ButtonZoomControlsandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:id=@+id/zctlX/ZoomControlsZoomControlsandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:id=@+id/zctlY/ZoomControls/LinearLayoutSurfaceViewandroid:id=@+id/SurfaceView01android:layout_height=fill_parentandroid:layout_width=fill_parent/SurfaceView/LinearLayout?xmlversion=1.0encoding=utf-8?LinearLayoutxmlns:android=/apk/res/androidandroid:orientation=verticalandroid:layout_width=fill_parentandroid:layout_height=fill_parentLinearLayoutandroid:id=@+id/LinearLayout01android:layout_height=wrap_contentandroid:layout_width=fill_parentandroid:orientation=horizontalButtonandroid:layout_height=wrap_contentandroid:id=@+id/btnStartandroid:text=开始android:layout_width=80dip/ButtonButtonandroid:layout_height=wrap_contentandroid:text=暂停android:id=@+id/btnExitandroid:layout_width=80dip/ButtonZoomControlsandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:id=@+id/zctlX/ZoomControlsZoomControlsandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:id=@+id/zctlY/ZoomControls/LinearLayoutSurfaceViewandroid:id=@+id/SurfaceView01android:layout_height=fill_parentandroid:layout_width=fill_parent/SurfaceView/LinearLayoutClsOscilloscope.java是构建示波器的类库,包括AudioRecord操作者线程和SurfaceView绘图线程的构建,两个线程同步操作,代码如下:viewplaincopytoclipboardprint?packagecom.testOscilloscope;importjava.util.ArrayList;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.graphics.Rect;importandroid.media.AudioRecord;importandroid.view.SurfaceView;publicclassClsOscilloscope{privateArrayListshort[]inBuf=newArrayListshort[]();privatebooleanisRecording=false;//线程掌控标记/***X轴增大的比例*/publicintrateX=4;/***Y轴增大的比例*/publicintrateY=4;/***Y轴基线*/publicintbaseLine=0;/***初始化*/publicvoidinitOscilloscope(intrateX,intrateY,intbaseLine){this.rateX=rateX;this.rateY=rateY;this.baseLine=baseLine;}/***开始**@paramrecBufSize*AudioRecord的MinBufferSize*/publicvoidStart(AudioRecordaudioRecord,intrecBufSize,SurfaceViewsfv,PaintmPaint){isRecording=true;newRecordThread(audioRecord,recBufSize).start();//开始录音线程newDrawThread(sfv,mPaint).start();//开始绘制线程}/***暂停*/publicvoidStop(){isRecording=false;inBuf.clear();//清理}/***负责管理从MIC留存数据到inBuf**@authorGV**/classRecordThreadextendsThread{privateintrecBufSize;privateAudioRecordaudioRecord;publicRecordThread(AudioRecordaudioRecord,intrecBufSize){this.audioRecord=audioRecord;this.recBufSize=recBufSize;}publicvoidrun(){try{short[]buffer=newshort[recBufSize];audioRecord.startRecording();//开始录音while(isRecording){//从MIC留存数据到缓冲区intbufferReadResult=audioRecord.read(buffer,0,recBufSize);short[]tmpBuf=newshort[bufferReadResult/rateX];for(inti=0,ii=0;itmpBuf.length;i++,ii=i*rateX){tmpBuf[i]=buffer[ii];}synchronized(inBuf){//inBuf.add(tmpBuf);//加到数据}}audioRecord.|nba下注官网。
本文来源:nba下注官网-www.finanzas4u.com
标签:nba下注官网
上一篇:基于嵌入式Internet技术的通用RTU设计:nba下注官网
下一篇:返回列表
将近有传闻称之为,7月2日,微信半小时内就打压了多达3000万个账号,重点压制私域流量和微商。...
2020-08-291191阅读全文 >>-美国艺术家Villefen Ray在农场里长大,自小就与南瓜结为不解之缘。...
2020-08-132313阅读全文 >>2019年1月份将是北方主产区栽种户大力售粮的高峰时段,再加养殖市场需求萎靡。...
2020-09-092653阅读全文 >>苹果新的iPhone将采行OLED面板爆炸话题,OLED俨然沦为下一代面板技术新势力,然而,OLED本身的技术包袱,只不过无法几乎代替LCD,MicroLED技术在其后虎视眈眈,未来将会超越OLED的局限,沦为几乎代替LCD的确实刺客级应用于,苹果与部分台厂新一波布局早就进行。...
2020-08-112320阅读全文 >>Invsble是一家坐落于总部蒙特利尔,专门从事家具概念设计与有机玻璃家具和装饰配件生产居多,企业正式成立于1976年享有多达30年的行业经验。...
2020-08-212906阅读全文 >>2019年7月11日,WIM组委会在北京宣告,2019世界创新者年会(2019 World Innovators Meet, WIM)将于2019年12月6-8日在北京国贸大酒店举行;预计,来自全球的6000名创新者将齐聚一堂,总结2019年世界科技与产业创意的成果,预测2020年近期创意趋势。...
2020-08-1785阅读全文 >>nba下注官网_特斯拉股价创新高 马斯克嘚瑟:股价真高 哈哈!
基于嵌入式Internet技术的通用RTU设计:nba下注官网
Android提高应用篇之模拟信号示波器|nba下注官网
施工现场安装环境监测仪实时监测PM2.5|nba下注官网
nba下注官网_美国麻省理工研发出毫米波信号技术VR有望完全无线化
nba下注官网|盈动资本项建标:文若其心,「投」如其人