资源简介
Qt+SDL录音并实时放音,类似KTV歌唱的
代码片段和文件信息
#include “audioengine.h“
#include
#include
extern “C“{
#include
#include
#include
#include
#include
#include
#include
#include
}
int volume = 128;
struct Node
{
char * data;
Node * next;
};
QList dataList;
SDL_mutex *mutex;
void packet_queue_init()
{
mutex = SDL_CreateMutex();
}
int packet_queue_put(QByteArray array)
{
SDL_LockMutex(mutex);
dataList.append(array);
SDL_UnlockMutex(mutex);
}
static QByteArray packet_queue_get()
{
SDL_LockMutex(mutex);
QByteArray array;
if (!dataList.isEmpty())
{
array = dataList.at(0);
dataList.removeAt(0);
}
SDL_UnlockMutex(mutex);
return array;
}
void audio_callback(void *userdata Uint8 *stream int len)
{
QByteArray array = packet_queue_get();
if (!array.isEmpty())
{
SDL_MixAudio(stream(uint8_t * )array.data()array.size()volume);
}
}
const qint64 BufferDurationUs = 10 * 1000000;
const int NotifyIntervalMs = 100;
AudioEngine::AudioEngine(Qobject *parent) :
Qobject(parent)
m_audioInputDevice(QAudioDeviceInfo::defaultInputDevice())
{
initial();
packet_queue_init();
openSDL();
startRrcording();
}
void AudioEngine:: initial()
{
m_format.setFrequency(8000);
m_format.setChannels(1);
m_format.setSampleSize(16);
m_format.setSampleType(QAudioFormat::SignedInt);
m_format.setByteOrder(QAudioFormat::LittleEndian);
m_format.setCodec(“AUDIO_S16“);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(m_format))
{
m_format = info.nearestFormat(m_format);
}
m_audioInput = new QAudioInput(m_audioInputDevice m_format this);
m_audioInput->setNotifyInterval(512);
}
void AudioEngine::startRrcording()
{
if (m_audioInput)
{
connect(m_audioInput SIGNAL(notify())this SLOT(audioNotify()));
m_audioInputIODevice = m_audioInput->start();
connect(m_audioInputIODevice SIGNAL(readyRead())this SLOT(audioDataReady()));
}
}
void AudioEngine::audioDataReady()
{
QByteArray array = m_audioInputIODevice->readAll();
packet_queue_put(array);
}
void AudioEngine::stopRecording()
{
if (m_audioInput) {
m_audioInput->stop();
QCoreApplication::instance()->processEvents();
m_audioInput->disconnect();
}
m_audioInputIODevice = 0;
}
bool AudioEngine::openSDL()
{
SDL_LockAudio();
SDL_AudioSpec spec;
SDL_AudioSpec wanted_spec;
wanted_spec.freq = 8000;
wanted_spec.format = AUDIO_S16;
wanted_spec.channels = 1;
wanted_spec.silence = 0;
wanted_spec.samples = 256;//SDL_AUDIO_BUFFER_SIZE;
wanted_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3286 2013-02-17 22:23 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\audioengine.cpp
文件 619 2013-02-17 22:22 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\audioengine.h
文件 486 2013-02-16 18:59 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\audiorecord.pro
文件 189 2011-11-03 16:04 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\main.cpp
文件 443 2013-02-17 22:09 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\mainwindow.cpp
文件 423 2011-11-03 17:33 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\mainwindow.h
文件 580 2013-02-16 18:59 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\mainwindow.ui
文件 5230 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\begin_code.h
文件 1482 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\close_code.h
文件 37206 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\doxyfile
文件 3233 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL.h
文件 1933 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_active.h
文件 11215 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_audio.h
文件 986 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_byteorder.h
文件 6048 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_cdrom.h
文件 1474 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config.h
文件 1474 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config.h.default
文件 7864 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config.h.in
文件 2803 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_dreamcast.h
文件 2801 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_macos.h
文件 4193 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_macosx.h
文件 1982 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_minimal.h
文件 2979 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_nds.h
文件 3635 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_os2.h
文件 3107 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_symbian.h
文件 4574 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_config_win32.h
文件 869 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_copying.h
文件 2221 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_cpuinfo.h
文件 6055 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_endian.h
文件 1874 2012-01-19 14:30 Qt+SDL录音并实时放音(有杂音待解决)\源代码\audiorecord\SDL\include\SDL_error.h
............此处省略36个文件信息
- 上一篇:带电容滤波的三相不控整流桥仿真
- 下一篇:发现网络中的活动主机报告及源代码
相关资源
- Windows版Qt串口终端显示通信
- 媒体播放器qt实现
- PCL1.8.1+Qt5.9.4测试程序
- Linux下使用Qt+V4L2测试UVC相机
- QT读取数据并绘制曲线
- QShareMemory.zip
- esp32 qt 源码
- Qt之QWizard向导界面
- QT实现UDP通信
- Qt 之实现 QQ系统表情窗口
- 简易五子棋qt实现
- QT实现抗锯齿圆形头像
- 基于Smart4418开发板+Qt 开发的离子色谱
- Qt.rar
- 基于QT的仿QQ登录界面
- qt编程_在子线程中更新UI界面
- 用qt4编写的聊天室
- Qt从零开始制作串口调试助手源代码(
- Qt自定义带游标的slider,在滑块正上方
- Qt播放PCM音频裸流文件
- 基于QT的音乐播放器
- QT+OpenCV+USB摄像头
- Qt实现的gbk/utf8无bom文本转码小工具
- Qt+Tcp+udp调试工具
- QT5 实现TCP通信 客户端与服务端,互相
- mingw-win32-gcc(4.8.2)-release
- QtImage读取图片,格式包括现在主要的
- Qt实现邮箱客户端
- Qt QSerialPort 通信 源码
- 重写QLabel实现图片显示框选截取保存
评论
共有 条评论