资源简介
实时录音与播放的内存实现 Qt代码。下载前请先阅读http://blog.csdn.net/kakadiablo/article/details/7561509#comments
代码片段和文件信息
#include “bufferInheritedfromQIODevice.h“
const qint64 BufferDurationUs = 10 * 1000000; // 10second
Generator::Generator(QByteArray buffer)
{
m_GeneratorBuffer = buffer;
m_pos=0;
}
Generator::~Generator()
{
}
void Generator::start()
{
open(QIODevice::ReadOnly);
}
void Generator::stop()
{
m_pos = 0;
close();
}
qint64 Generator::readData(char *data qint64 len)
{
qDebug() << “len is “ << len;
qint64 total = 0;
while (len - total > 0) {
const qint64 chunk = qMin((m_GeneratorBuffer.size() - m_pos) len - total);
memcpy(data + total m_GeneratorBuffer.constData() + m_pos chunk);
m_pos = (m_pos + chunk) % m_GeneratorBuffer.size();
total += chunk;
qDebug() << “total is “< }
return total;
}
qint64 Generator::writeData(const char *data qint64 len)
{
Q_UNUSED(data);
Q_UNUSED(len);
return 0;
}
qint64 Generator::bytesAvailable() const
{
return m_GeneratorBuffer.size() + QIODevice::bytesAvailable();
}
void bufferPlayback::startPlayback()
{
if (m_audioOutput) {
m_mode = QAudio::AudioOutput;
m_dataLengthPlay = 0;
m_generator->start();
m_audioOutput->start(m_generator);
}
}
bufferPlayback::bufferPlayback()
: m_mode(QAudio::AudioInput)
m_audioInput(0)
m_audioInputDevice(QAudioDeviceInfo::defaultInputDevice())
m_audioInputIODevice(0)
m_audioOutputDevice(QAudioDeviceInfo::defaultOutputDevice())
m_audioOutput(0)
m_bufferLength(0)
m_dataLengthPlay(0)
m_dataLengthRecord(0)
{
selectFormat();
initialize();
QList inputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
m_audioInputDevice = inputDevices.at(0);
QList outputDevices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
m_audioOutputDevice = outputDevices.at(0);
QTimer::singleShot(3000 reinterpret_castject*>(this) SLOT(startPlayback()));
startRecording();
qDebug() << “Device name: “ << m_audioInputDevice.deviceName();
qDebug() << “Device name: “ << m_audioOutputDevice.deviceName();
}
bufferPlayback::~bufferPlayback()
{
delete m_audioInput;
delete m_audioOutput;
delete m_generator;
}
qint64 bufferPlayback::audioLength(const QAudioFormat &format qint64 microSeconds)
{
qint64 result = (format.frequency() * format.channels() * (format.sampleSize() / 8))
* microSeconds / 1000000;
result -= result % (format.channelCount() * format.sampleSize());
return result;
}
qint64 bufferPlayback::bufferLength() const
{
return m_bufferLength;
}
void bufferPlayback::initialize()
{
m_bufferLength = audioLength(format BufferDurationUs);
m_buffer.resize(m_bufferLength);
m_buffer.fill(0);
m_audioInput = new QAudioInput(m_audioInputD
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 417 2012-05-08 15:44 3 methods\bufferCircularPlaybackInheritedFromQIODevice\bufferCircularPlaybackInheritedFromQIODevice.pro
文件 46208 2012-07-02 23:33 3 methods\bufferCircularPlaybackInheritedFromQIODevice\bufferCircularPlaybackInheritedFromQIODevice.pro.user
文件 5738 2012-05-13 01:40 3 methods\bufferCircularPlaybackInheritedFromQIODevice\bufferInheritedfromQIODevice.cpp
文件 2043 2012-07-02 23:30 3 methods\bufferCircularPlaybackInheritedFromQIODevice\bufferInheritedfromQIODevice.h
文件 196 2012-05-08 15:32 3 methods\bufferCircularPlaybackInheritedFromQIODevice\main.cpp
文件 654 2012-05-08 15:27 3 methods\bufferCircularPlaybackInheritedFromQIODevice\mainwindow.ui
文件 7331 2012-05-12 01:29 3 methods\inheritedVersion3\inheritedVersion3.cpp
文件 2521 2012-05-12 01:29 3 methods\inheritedVersion3\inheritedVersion3.h
文件 368 2012-07-02 23:33 3 methods\inheritedVersion3\inheritedVersion3.pro
文件 45938 2012-07-02 23:33 3 methods\inheritedVersion3\inheritedVersion3.pro.user
文件 201 2012-07-02 23:32 3 methods\inheritedVersion3\main.cpp
文件 654 2012-05-12 01:19 3 methods\inheritedVersion3\mainwindow.ui
文件 4958 2012-05-21 23:20 3 methods\mybuffer\deployment.pri
文件 182 2012-05-21 23:29 3 methods\mybuffer\main.cpp
文件 5591 2012-05-21 23:29 3 methods\mybuffer\mainwindow.cpp
文件 1455 2012-05-21 23:29 3 methods\mybuffer\mainwindow.h
文件 554 2012-05-21 23:20 3 methods\mybuffer\mainwindow.ui
文件 232 2012-05-21 23:20 3 methods\mybuffer\mybuffer.desktop
文件 1758 2012-05-21 23:33 3 methods\mybuffer\mybuffer.pro
文件 121628 2012-06-02 21:35 3 methods\mybuffer\mybuffer.pro.user
文件 6596 2012-05-21 23:20 3 methods\mybuffer\mybuffer.svg
文件 3400 2012-05-21 23:20 3 methods\mybuffer\mybuffer64.png
文件 4945 2012-05-21 23:20 3 methods\mybuffer\mybuffer80.png
文件 297 2012-05-21 23:20 3 methods\mybuffer\mybuffer_harmattan.desktop
文件 110 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\changelog
文件 2 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\compat
文件 4908 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\control
文件 1371 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\copyright
文件 138 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\README
文件 1933 2012-05-21 23:20 3 methods\mybuffer\qtc_packaging\debian_fremantle\rules
............此处省略18个文件信息
- 上一篇:512乘512的BMP格式的Lena图
- 下一篇:宿舍管理系统论文 宿舍管理系统论文
相关资源
- Qt实现的转灰度图源代码
- QT网络调试助手
- qt各种页面切换动画实现
- QVTKWidgetPlugin.dll
- Qt中QLabel单击事件响应
- qt贪吃蛇游戏源码
- Qt写的天气预报
- qt TCP网络编程与聊天室的实现
- 关于qtabWidget tab竖写方式
-
mpla
yer QT源码 - Qt 4.70 多功能科学计算器
- QTabWidget标签拖拽出窗口,又可还原
- MQTT MT2503上的移植文件
- 使用Qt实现的阴影映射源代码
- vst混响SonitusFXReverbVST.
- QT 4.5.0 with vs2003 vs2005 vs2008
- 钢琴的声音do re mi fa so la si do的音频素
- Qt小实练--实现圆角、阴影、无边框窗
- Qt截图小
- PyQt4入门指南 PDF中文版
- Qt常用图标资源png
- 基于labview的双声道音频信号录制系统
- qt下图片循环显示的几个很好的,包括
- QT将应用程序缩小到右下角任务栏的系
- Qt creator 做的计算器工程文件
- 北邮嵌入式实验_MQTT协议实验过程及代
- Qt类继承关系图
- Qt4迁移至Qt5完全指南
- 基于QT局域网聊天系统毕业论文
- qtcreator + Keil MDK armcc +openocd 编译 调试
评论
共有 条评论