之前一直在windows下作多媒体,谁知道跑到linux下不灵了,在网上查了些资料,总算是有点思路了,主要是两大家族oss和alsa,选择了alsa来进行开发,编译alsa-lib和alsa-utils
编译alsa-lib 是这样的,../configure --host= aarch64-linux-gnu --prefix=/usr/local/ --enable-shared --disable-python
接下来就是make make install
完成就是写了音频采集的线程,如下:
class AudioCapture : public QObject
{
Q_OBJECT
public:
explicit AudioCapture(QObject *parent = nullptr);
void init(int buffer_frames,int sample_rate,
QString dev_name);
void device_list();
void pcm_list();
void setRunFlag(bool flag){_bRunFlag = flag;}
signals:
void sig_capture_data(QByteArray data);
public slots:
void doCapture();
private:
int _buffer_frames;
int _sample_rate;
QString _dev_name;
bool _bRunFlag;
};
#include "audiocapture.h"
#include <alsa/asoundlib.h>
#include <stdio.h>
#include <QDebug>
AudioCapture::AudioCapture(QObject *parent) : QObject(parent)
{
}
void AudioCapture::init(int buffer_frames, int sample_rate, QString dev_name)
{
_sample_rate = sample_rate;
_buffer_frames = buffer_frames;
_dev_name = dev_name;
_bRunFlag = false;
}
void AudioCapture::doCapture()
{
snd_pcm_t *capture_handle;
snd_pcm_hw_params_t *hw_params;
snd_pcm_format_t format = SND_PCM_FORMAT_S16;
int err;
char *buffer = nullptr;
if((err = snd_pcm_open(&capture_handle,_dev_name.toStdString().c_str(),
SND_PCM_STREAM_CAPTURE,0))<0)
{
return;
}
if(err =