• 大小: 265KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-30
  • 语言: 其他
  • 标签: Qt  SDL  

资源简介

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个文件信息

评论

共有 条评论