主要的问题:
我在一个面向大专本科初学者的软件无线电项目taskBus中使用QMultiMedia模块录音,假设了 QIODevice::readAll() 每次必然返回整数组样点。比如立体声,16位,则返回的字节数必然是4的整数倍。这个行为从Qt4、Qt5都没有出问题。结果Qt6时,在Win10下返回了奇数个字节。如果不做缓存,后续的样点字节就被破坏,声音就很怪很怪。

我已经在Qt的社区反馈了这个问题:
A noteworthy Qt6 issue: QIODevice::readAll() create by QAudioSource returns an odd byte length for qint16 sample points.

When I migrated a Qt5 project to Qt6, I ran into this problem. Under Windows 10, My instances of MSYS2 Qt 6.2.0 x64 compilation are not working properly. I traced the debugging and found the problem.

My old code presupposes that readAll must return a complete sample.

//QAudioSource *AudioInputSound = new QAudioSource(dev, format, this);
//QIODevice InputDev = AudioInputSound->start();
//connect(InputDev, SIGNAL(readyRead()), SLOT(OnReadMore()));
void Dialog::OnReadMore()
{//...QByteArray data = InputDev->readAll();const short * spt = (const short * ) data.constData();//Audio sample point size will be 4 bytes for stereo, 2 bytes for mono.const int point_size = sizeof(short) * channels;//Problem Here it is! //This Operation suppose that (data.size() % point_size ==0).int points = data.size()/point_size;//Do signal process funtions.deal_function(spt, point_size, points);//When funtion returns, data will be recycled. The lost of odd tail disrupts subsequent samples.
}

But under the new Qt6, it returns an odd number of bytes. This is an issue that I didn’t think through. Currently, it is solved by a cache that preserves the tail data.

//...
QByteArray buffer;
void Dialog::OnReadMore()
{//We can put bytes to a buffer first.buffer.append(InputDev->readAll());const short * spt = (const short * ) buffer.constData();const int point_size = sizeof(short) * channels;     //The variable "points" now refers to the maximum number of samples that can be processed. int points = buffer.size()/point_size;deal_function(spt, point_size, points);//Remove old data and KEEP the tail. buffer.remove(0,points* point_size);
}

This introduces some performance issues. However, it is not a big problem for low-speed devices such as sound cards.

This is not a BUG, but this behavior of the QAudioInput module can be troubling. Some poorly designed programs crash, just like mine. For Qt, which may be used in medical devices, special attention needs to be paid to this feature.

I wish Qt better and better!

特性提醒-Qt6录音QIODevice::readAll()返回奇数字节。相关推荐

  1. Qt QNetworkReply 无数据 readAll返回空字符串 无错误代码 error返回0

    直通车 问题描述 原因 解决 说一句话 问题描述 Qt5.用QNetworkAccessManager 拉取某网站数据.代码基本正确:QNetworkReply.error返回0,表明无错误发生:但r ...

  2. Qt 使用C++特性“引用” - 获得槽函数的返回值

    QT信号与槽中,槽函数是可以定义有返回值的,但是我们都是在connect函数中进行调用,那么该如何获得调用后的槽函数的返回值呢? 答案是不可能获得了的! 槽函数虽然可以定义返回值类型,但其实他和信号一 ...

  3. python struct.pack()函数 (返回一个字节对象,其中包含根据格式字符串fmt打包的值v1,v2,...)

    def pack(fmt, *args): # known case of _struct.pack"""pack(fmt, v1, v2, ...) -> byt ...

  4. 【SQL开发实战技巧】系列(四十五):Oracle12C常用新特性☞VARCHAR2/NVARCHAR2类型最大长度由4000字节扩展到32767字节

    系列文章目录 文章目录 系列文章目录 前言 Oracle12C常用新特性☞VARCHAR2/NVARCHAR2类型最大长度由4000字节扩展到32767字节 案例一:CDB+PDB环境启用扩展 案例二 ...

  5. python的高级特性3:神奇的__call__与返回函数

    __call__是一个很神奇的特性,只要某个类型中有__call__方法,,我们可以把这个类型的对象当作函数来使用. 也许说的比较抽象,举个例子就会明白. In [107]: f = absIn [1 ...

  6. android 解决通话录音时无法返回挂断状态的bug

    据了解,安卓6.0开始不再支持通话录音,除非修改系统.系统放开权限.root,这也可以理解,毕竟这涉及到隐私问题,万一我一个亿的银行密码被人窃听了呢? 最近有个定制的系统有个需求--------通话录 ...

  7. 【操作消息提醒——AjaxResult】和【返回状态码——HttpStatus】

    文章目录 1.操作消息提醒--AjaxResult.java 2.返回状态码--HttpStatus 1.操作消息提醒--AjaxResult.java package com.shuang.mess ...

  8. oracle如何判断奇数偶数_返回奇数行或者偶数行数据库表记录

    --方法1用Decode函数 for even number of records select*from emp where rowid in(select decode(mod(rownum,2) ...

  9. python os write_Python 3:写入方法与os.write返回的字节数

    我想创建一个包含许多"页面"的文本文件,并将每个页面的字节偏移记录在一个单独的文件中.为此,我将字符串打印到主输出文件并使用bytes_written = file.write(s ...

最新文章

  1. 运维企业专题(10)RHCS集群工具——FENCE搭建、高可用服务配置详解
  2. 深度学习论文阅读路线图
  3. kafka java_Kafka 使用Java实现数据的生产和消费demo
  4. 码栈开发手册(四)---编码方式开发(日期相关函数)
  5. Butter Knife:一个安卓视图注入框架
  6. java线程 对文件copy 可能删除了 报异常_java线程对文件copy可能删除了报异常
  7. CentOS-Samba服务
  8. 前端学习(3205):对state的理解
  9. html文件整体结构,HTML文件基本结构
  10. 梯度下降法理论与实践
  11. 首都师范大学数学专业考研试题参考解答
  12. 如何不用密钥破解tableau
  13. 《完全写作指南》读书笔记
  14. linux opendir路径_Linux C - opendir 和 readdir 和 closedir - 目录文件打开
  15. java web简答题_javaweb简答题
  16. 百度劫持有哪些特征,百度快照劫持处理方法及流程?
  17. pack_padded_sequence;pad_packed_sequence
  18. eliteadmin网页后台管理模板简介
  19. matlab中argmax_argmin(matlab中argmin函数)
  20. IDEA 中 project窗口,不显示项目工程目录,解决方法

热门文章

  1. js数组按中文拼音排序_JavaScript数组
  2. cocos2d-xnbsp;图片纹理优…
  3. 卖给高通之后的CSR的现状和未来
  4. webpack Vue热加载配置好的确不行解决方法,限于webstorm编辑
  5. matlab初学matlab——变量类型
  6. 符号及符号表是什么?
  7. 6. unity之脚本
  8. Windows Server2012R2插网线无网络---网络受限
  9. 华为电子邮件显示未读邮件1_电子邮件简介已经过去
  10. php printer使用手册,go/printer