• 大小: 2.98MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-27
  • 语言: 其他
  • 标签: pcm  aac  

资源简介

实现获取pc上接入的音频输入设备,并采集音频输入设备音频数据(pcm),然后基于libfaac进行编码,最终生成aac文件。

资源截图

代码片段和文件信息

/*
功能描述: 简单实现用DirectShow采集Windows麦克风音频PCM数据
经过FAAC编码成AAC存储文件,可根据项目修改成直播,对讲
等实时传输类应用。

From: http://blog.csdn.net/xiejiashu
Site: http://www.easydarwin.org
时间: 2014/07/28
*/
#include “../DSAudio/General.h“
#include
#include
#include
#include
#include “../DSAudio/dscapture.h“
#include “DSAudio/FAACEncoder.h“

unsigned char fBitsPerSample fNumChannels;
unsigned fSamplingFrequency;
unsigned fGranularityInMS;

DSCapture* ds_capture_;
FAACEncoder* faac_encoder_;

unsigned long max_out_bytes;
unsigned char* outbuf;

FILE* f_aac_;

int main()
{

fBitsPerSample = 16; //单个采样音频信息位数
fNumChannels = 2; //通道数
fSamplingFrequency = 44100;//采样率

faac_encoder_ = new FAACEncoder(); //新建AAC编码对象

faac_encoder_->Init(fSamplingFrequencyfNumChannelsfBitsPerSample); //初始化AAC编码器

ds_capture_ = new DSCapture();
std::map a_devices = ds_capture_->DShowGraph()->AudioCapDevices();

if(a_devices.size() == 0 ) ::exit(0);

DSAudioFormat audio_fmt;
    audio_fmt.samples_per_sec = fSamplingFrequency;
    audio_fmt.channels = fNumChannels;
    audio_fmt.bits_per_sample = fBitsPerSample;

// 枚举音频采样设备,选择最后一个
CString audio_device_id;
for (std::map::iterator it = a_devices.begin(); it != a_devices.end(); ++it)
    {
audio_device_id = it->first;
    }

    ds_capture_->Create(audio_device_id audio_fmt NULL);
   
// 开始采集音频数据
    ds_capture_->StartAudio();

::Sleep(10);

max_out_bytes = faac_encoder_->MaxOutBytes();
    outbuf = (unsigned char*)malloc(max_out_bytes);

// 编码后存文件
f_aac_ = fopen(“./audio.aac““wb“);
printf(“Recording...“);
while(1)
{
int pcmLen = 0;
// 采集音频pcm数据
char* pcmBuf = ds_capture_->GetBuffer(pcmLen);
if(pcmLen > 0)
{
unsigned int sample_count = (pcmLen << 3)/fBitsPerSample;
unsigned int buf_size = 0;
// 编码AAC
faac_encoder_->Encode((unsigned char*)pcmBuf sample_count (unsigned char*)outbuf buf_size);
if(buf_size > 0)
{
printf(“.“);
// 存文件或者自定义
fwrite(outbuf1buf_sizef_aac_);
}
}
// 释放采集的pcm数据
ds_capture_->ReleaseBuffer(pcmBuf);
::Sleep(1);
}

free(outbuf);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        887  2013-09-22 17:35  WinAudioRecord\AudioRecord.sln

     文件       5769  2013-09-23 15:10  WinAudioRecord\AudioRecord.vcproj

     文件     131072  2013-07-21 22:50  WinAudioRecord\Debug\libfaacd.dll

     文件        631  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\activecf.h

     文件       1826  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\amaudio.h

     文件       1065  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\amparse.h

     文件      73261  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\amstream.h

     文件       3974  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\amva.h

     文件      19851  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\Amvideo.h

     文件       1097  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\atsmedia.h

     文件       1532  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\audevcod.h

     文件      20543  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\austream.h

     文件      13805  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\aviriff.h

     文件       6861  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\basetsd.h

     文件     125594  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\bdaiface.h

     文件      54539  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\bdamedia.h

     文件      53527  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\Bdatif.h

     文件      15486  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\bdatypes.h

     文件        944  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\comlite.h

     文件     178266  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\control.h

     文件      88071  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d.h

     文件      72232  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d8.h

     文件      16088  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d8caps.h

     文件      63735  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d8types.h

     文件      96132  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d9.h

     文件      22164  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d9caps.h

     文件      69800  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3d9types.h

     文件      26113  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3dcaps.h

     文件      14874  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3drm.h

     文件      24261  2013-07-21 22:54  WinAudioRecord\DirectShow\Include\d3drmdef.h

............此处省略202个文件信息

评论

共有 条评论