waveInReset/waveOutReset死锁原因与解决方案

c++实现waveinopen录音功能 需要注意的是,实际使用中可能需要更多的错误处理和资源管理。同时,这个示例是基于Windows的,使用了Windows Multimedia API来进行音频录制。函数来录制音频数据,然后通过回调函数。这是一个简单的C++示例,使用。 阅读详情

问题背景

 

录音播音实际需求

1、随时终止

2、录音并非文件,而是形成rtp发送

3、播音并非源于文件,而是源于rtp

 

因此Waveform audio使用的buffer较小,不断的装载/发送 buffer,终止的时候Reset并且close.

大致如下调用的循环

 

录音

waveInUnprepareHeader

waveInPrepareHeader

waveInAddBuffer

 

播音

waveOutUnprepareHeader

waveOutPrepareHeader

waveOutWrite

 

循环周期40ms,我采用的是回调函数。问题是有时候调用waveInReset/waveOutReset会形成死锁,调用waveInReset/waveOutReset的线程与回调函数所在的线程死锁在一块了。

 

原因分析

这方面网上有文章提到,就是调用waveInReset/waveOutReset的同时调用了录音/播音循环调用的某个函数会形成死锁。我再稍作解释下,我们知道buffer满了或是调用Reset都会触发消息(回调函数方式的话就是MM_WOM_DONE/MM_WIM_DATA),由于调用waveInReset/waveOutReset所在的线程,与回调函数所在的线程不是一个线程,因此很容易撞车,也就是说,你调用reset的时候,另一个线程正好在处理MM_WOM_DONE/MM_WIM_DATA,于是就这样死锁了。

 

解决方案

方案一

先加上标记(假设标记bReset:bool),令bReset为true;

 

标记作用如下

if(!bReset)<

WaveIn&WaveOut;的使用示例 用WaveIn开发的录制,用WaveOut开发的播放,目的是方便广大爱好者的学习。 立即下载

相关推荐

Mem0 vs LangMem vs Letta:三大AI记忆框架实战对比(附代码示例)

本文深入对比了Mem0、LangMem和Letta三大AI记忆框架的核心特性与适用场景。Mem0提供开箱即用的记忆管理服务,适合快速集成;LangMem深度融入LangGraph生态,适合复杂工作流;Letta则采用虚拟内存系统,旨在突破上下文窗口限制。文章通过实战代码示例,为开发者选择适合其业务需求的AI记忆解决方案提供了清晰指南。

g9h0i1的博客 680

图像传感器与信号处理——详解CCD与CMOS图像传感器

一文详解CCD与CMOS图像传感器一文详解CCD与CMOS图像传感器1. 图像传感器性能关键词1.1 噪声1.2 暗电流 一文详解CCD与CMOS图像传感器 本文主要总结了CCD与CMOS传感器的原理知识,参考书籍为《数码相机中图像传感器和信号处理》,英文版为《Image Sensors And Signal Processing for Digital Still Cameras》 1. 图像传...

weixin_44580210的博客 2万+

微信小程序获取用户手机号全流程实战(附完整代码)

本文详细介绍了微信小程序获取用户手机号的全流程实战,包括前端授权、后端解密及安全合规要点。通过传统授权按钮和新版手机号快速验证组件两种方案,帮助开发者高效实现功能,并附完整代码示例。重点解析了微信小程序接口的使用技巧和常见问题解决方案,确保数据安全与用户体验。

weixin_29280219的博客 568

Android Studio连接手机详细教程(包含遇到的问题集)

如果以上内容全都调试正确了,还是存在这个无法安装的问题,多半是一开始用的别的手机进行调试安装,然后抽掉线重新换上另一个手机安装调试才会报错。无法识别的 USB 设备,跟这台计算机连接的前一个 USB 设备工作不正常,Windows 无法识别它。此时,我的开发者选项已经开启,并且windows系统和android studio已经能够识别我的设备了,但还是报了这样的错误。右击你的手机——>更新驱动程序——>浏览我的计算机以查找驱动程序软件。右击此电脑——>属性——>设备管理器——>便携设备。

IT小郭的技术博客 4万+

达梦数据库(DM)的备份与恢复功能

本文系统介绍了达梦数据库(DM)的备份与恢复功能,主要包括作业系统和物理/逻辑备份还原两大模块。作业系统部分详细说明了通过代理环境创建定时备份和删除备份作业的步骤;物理备份还原部分阐述了联机和脱机备份方式,包括数据库、表空间、表和归档的备份还原操作;逻辑备份还原部分介绍了dexp/dimp工具的使用方法及四种级别的导入导出功能。文章还介绍了图形化管理工具进行备份还原的操作流程,全面覆盖了达梦数据库的数据保护方案,为数据库管理员提供了详细的技术指导。

weixin_48812832的博客 1211

YOLO26中 RepVGGBlock_OREPA 架构的设计与性能提升分析(mAP +4.89)

REPVGGOREPA模块代表了重参数化技术的最新发展,它通过巧妙的架构设计实现了训练时的丰富表达和推理时的高效计算。其核心创新包括多分支特征聚合、动态权重生成、频域先验知识融合等技术,为深度学习模型的效率优化提供了新的解决方案。这种设计理念不仅在技术上具有重要意义,在实际应用中也展现出了显著的优势,特别是在需要高精度和高效率的工业场景中表现突出。随着重参数化技术的不断发展,REPVGGOREPA为未来的网络架构设计提供了重要的参考和启发。

know_F0727的博客 66

1小时读完100篇文献的正确打开方式

各位同仁好,我是七哥。一个在高校里从事人工智能 相关领域研究,钻研用大模型AI实操的学术人。可以和七哥交流学术写作或Gemini、GPT、Claude 等大模型 学术实操相关问题,多多交流,相互成就,共同进步。文献阅读与整理一般都是最先开始、却也最容易被低估的一步。很多学术同仁一开始就陷入越读越多、越读越乱的状态:论文下载了一大堆,但真正能用来支撑自己观点的内容却始终难以提炼出来。一方面,我们需要通过文献了解该研究领域的整体发展脉络,把握当前学界已经讨论到什么程度;

智能AI让学术科研更容易 49

关于DEJA_VU3D - Cesium功能集专栏说明

专栏主要目的是对工作中基于Cesium实现过的功能进行整合,暂时打算一周2-3更的样子来更新,每一篇都会奉上完整源代码(尽可能把代码简洁一些)。功能实现大多数是自己琢磨实现的,也有参考其他大神后整理实现的,初步算了算现在有差不多实现小130个左右的功能,后续也会不断的更新。..........................................

总得学点什么的博客 2万+

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: 谈谈工作的积累
下一篇: Win32 SDK值得注意的地方
soliddream66
博客等级 码龄19年 93粉丝 65原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值