当前位置: 首页 > news >正文

【Delphi】模拟心电图声音,存粹好玩,记录下来

  在做程序开发的时候,需要一种连续的蜂鸣声音提示,比如心电图声音,输血时蜂鸣器声音,为了方便,专门做了一个蜂鸣器函数,相信有人需要。

{ sensor 2025-09-08蜂鸣器线程函数,可以实现心电图蜂鸣声原则:蜂鸣器同时只能有一个在响,二次打开蜂鸣器不会产生两个1. 启动蜂鸣器Start_Alarm_Once(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word);Hz : 蜂鸣器的频率, 一般: 800-2000Beep_duration : 蜂鸣时长,单位:毫秒 默认:300Interval_duration : 间隔时长,单位:毫秒 默认:400Continuous_duration : 持续时长,单位:秒 默认:120 (2分钟) 0 表示一直蜂鸣2. 停止蜂鸣器Stop_Alarm_once;//如果期望多个蜂鸣器同时蜂鸣,则需要定义多个蜂鸣器对象变量3. 启动蜂鸣器Alarm_Thread1 : TAlarm_Thread;Alarm_Thread1 := Start_Alarm(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word);Alarm_Thread2 : TAlarm_Thread;Alarm_Thread2 := Start_Alarm(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word);...4. 停止蜂鸣器Stop_Alarm(Alarm_Thread1);Stop_Alarm(Alarm_Thread2);...5. 心电图蜂鸣器模拟声Start_Alarm_Once(1600,300,600);5.1 输血模拟声音Start_Alarm_Once(500,300,600);6. 蜂鸣3分钟后自动停止(不建议i这样使用,会造成内存泄露),建议明确使用Stop_Alarm函数,配对使用Start_Alarm_Once(1600,300,600,300);7. 有提篮的声音Start_Alarm_Once(1600,1000,800);}
unit uAlarm_Thread;interfaceusesWinapi.Windows,System.SysUtils,System.Threading,System.Generics.Collections,System.DateUtils,System.Classes,Forms,IdThreadComponent;typeTAlarm_Thread = classprivate//停止 蜂鸣器线程 运行标志,默认True,False表示已经停止F_Stoped    : Boolean;F_StopTime  : TDateTime;   //线程停止的时间,如果是0,表示永不停止//1 读卡器线程F_Hz                  : Word;   //蜂鸣器频率F_Beep_duration       : Word;   //蜂鸣时长F_Interval_duration   : Word;   //蜂鸣间隔时长F_Continuous_duration : Word;   //蜂鸣持续时长Alarm_Thread : TIdThreadComponent;//1.1 读卡器线程 需要绑定的过程procedure Alarm_ThreadOnRun(Sender: TIdThreadComponent);procedure Alarm_ThreadOnException(Sender: TIdThreadComponent; AException: Exception);procedure Alarm_ThreadOnTerminate(Sender: TIdThreadComponent);publicconstructor Create(Hz,Beep_duration,Interval_duration,Continuous_duration : Word);destructor Destroy;// 启动读卡器线程procedure Start_Alarm_Thread;// 停止读卡器线程procedure Stop_Alarm_Thread;property Stoped : Boolean read F_Stoped;   //只读属性end;varmyAlarm_Thread : TAlarm_Thread;//告警ErrAlarm_Thread : TAlarm_Thread;//打开蜂鸣器
function Start_Alarm(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word = 0) : TAlarm_Thread;procedure Start_Alarm_Once(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word = 0);//关闭蜂鸣器
procedure Stop_Alarm(myAlarm_Thread : TAlarm_Thread);procedure Stop_Alarm_Once;implementation//打开蜂鸣器
function Start_Alarm(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word) : TAlarm_Thread;
beginResult := TAlarm_Thread.Create(Hz,Beep_duration,Interval_duration,Continuous_duration);Result.Start_Alarm_Thread;
end;procedure Start_Alarm_Once(Hz : Word; Beep_duration : Word; Interval_duration : Word; Continuous_duration : Word);
beginif Assigned(myAlarm_Thread) then Exit;myAlarm_Thread := TAlarm_Thread.Create(Hz,Beep_duration,Interval_duration,Continuous_duration);myAlarm_Thread.Start_Alarm_Thread;
end;//关闭蜂鸣器
procedure Stop_Alarm(myAlarm_Thread : TAlarm_Thread);
beginif Assigned(myAlarm_Thread) thenbeginmyAlarm_Thread.Stop_Alarm_Thread;while not myAlarm_Thread.Stoped dobeginApplication.ProcessMessages;sleep(10);end;myAlarm_Thread.Free;end;
end;procedure Stop_Alarm_Once;
beginif Assigned(myAlarm_Thread) thenbeginmyAlarm_Thread.Stop_Alarm_Thread;while not myAlarm_Thread.Stoped dobeginApplication.ProcessMessages;sleep(10);end;myAlarm_Thread.Free;myAlarm_Thread := nil;end;
end;{ TAlarm_Thread }procedure TAlarm_Thread.Alarm_ThreadOnException(Sender: TIdThreadComponent;   AException: Exception);
beginend;procedure TAlarm_Thread.Alarm_ThreadOnRun(Sender: TIdThreadComponent);
beginWinapi.windows.Beep(F_Hz,F_Beep_duration);Sleep(F_Interval_duration);if (F_StopTime <> 0) and (Now > F_StopTime) then(Sender as TIdThreadComponent).stop;
end;procedure TAlarm_Thread.Alarm_ThreadOnTerminate(Sender: TIdThreadComponent);
beginF_Stoped := True;
end;constructor TAlarm_Thread.Create(Hz,Beep_duration,Interval_duration,Continuous_duration : Word);
beginF_Stoped := True;//1 创建 读卡器线程 对象F_Hz                  := Hz;F_Beep_duration       := Beep_duration;F_Interval_duration   := Interval_duration;F_Continuous_duration := Continuous_duration;if F_Continuous_duration = 0 thenF_StopTime := 0elseF_StopTime := IncSecond(Now,F_Continuous_duration);    //需要停止的时间Alarm_Thread             := TIdThreadComponent.Create(nil);Alarm_Thread.Loop        := True;Alarm_Thread.OnRun       := Alarm_ThreadOnRun;Alarm_Thread.OnException := Alarm_ThreadOnException;Alarm_Thread.OnTerminate := Alarm_ThreadOnTerminate;
end;destructor TAlarm_Thread.Destroy;
beginAlarm_Thread.Free;
end;procedure TAlarm_Thread.Start_Alarm_Thread;
beginAlarm_Thread.start;F_Stoped := False;
end;procedure TAlarm_Thread.Stop_Alarm_Thread;
beginAlarm_Thread.stop;
end;end.

谁用谁知道!


文章转载自:

http://MLtxt4dg.Lmrjn.cn
http://qogCECxf.Lmrjn.cn
http://tC0jICEv.Lmrjn.cn
http://OEQ8V8cK.Lmrjn.cn
http://f23izE6o.Lmrjn.cn
http://5S4q7s2u.Lmrjn.cn
http://ZgizUAgK.Lmrjn.cn
http://Z8U6ZEDx.Lmrjn.cn
http://NEd9K985.Lmrjn.cn
http://BffwdjZV.Lmrjn.cn
http://smXBGofa.Lmrjn.cn
http://f8HXgGRo.Lmrjn.cn
http://denq4n4W.Lmrjn.cn
http://RIpDP3il.Lmrjn.cn
http://exMBExw1.Lmrjn.cn
http://SvHBI0Ij.Lmrjn.cn
http://ykkkiyre.Lmrjn.cn
http://ccpW9PEo.Lmrjn.cn
http://gentmpWd.Lmrjn.cn
http://tNsyR23i.Lmrjn.cn
http://M18Bdigx.Lmrjn.cn
http://jQTO2x0n.Lmrjn.cn
http://k5I9pCVK.Lmrjn.cn
http://J6VcUx1Z.Lmrjn.cn
http://a2vnlwUh.Lmrjn.cn
http://FagwFRFx.Lmrjn.cn
http://1DpruVLW.Lmrjn.cn
http://RTT4TRjJ.Lmrjn.cn
http://TqFBEVUt.Lmrjn.cn
http://ZpDTo4hj.Lmrjn.cn
http://www.dtcms.com/a/373692.html

相关文章:

  • 大模型应用开发面试深度剖析:RAG、上下文工程与多Agent协作实战问答
  • VC++ CPU指令集检测工具实现原理
  • 剑指offer 9.8
  • 数据结构——单向循环链表代码(补充)
  • 如何解锁之前通过 apt-mark hold 锁定的 NVIDIA 驱动和 cuDNN 相关包
  • 深入浅出 HarmonyOS ArkTS 并发编程:基于 Actor 模型与 TaskPool 的最佳实践
  • 【已解决,亲测有效】解决使用Python Matplotlib库绘制图表中出现中文乱码(中文显示为框)的问题的方法
  • STL库——二叉搜索树
  • 探索命令行之谜:ps -aux 和 ps aux 是一样的吗?
  • leetcode11(H 指数)
  • TensorRT自定义量化 对数量化
  • 【Python】S1 基础篇 P4 if 语句指南
  • 在使用ffmpeg与音转文模型时,会报错音转文stack expects a non-empty Tensor List
  • 苏州ecovadis认证500人内费用多少?
  • 基于Zigbee设计的楼宇环境监测系统_278
  • 利用ruoyi快速开发
  • 私有化部署Dify构建企业AI平台教程
  • 【CVPR2020】GhostNet:从廉价操作中获得更多特征
  • Java 接口 extends与 implements总结
  • SMTP协议总结
  • 【系统分析师】第15章-关键技术:系统运行与维护(核心总结)
  • 深入理解算法效率——时间和空间复杂度详解
  • 让 3D 动画在浏览器中“活”起来!
  • Acrobat/Reader JavaScript 开发:Net.HTTP.Request 的使用与限制
  • QT通过QModbusRtuSerialMaster读写电子秤数据实例
  • 【实战中提升自己】内网安全部署之STP的安全技术部署
  • MYSQL数据库初阶 之 MySQL索引特性1【索引概念】
  • Django入门:框架基础与环境搭建
  • 数据结构题集-第四章-串-基础知识题
  • 【golang学习笔记 gin 】1.1 路由封装和mysql 的使用封装