剑痴乎

  • 首页
  • 文章分类
    • 音视频
    • WebRTC
    • 编程之美
    • Linux
    • Windows
    • 生活点滴
    • 校园生活
  • 参考
    • API参考
    • 实用工具
    • 测试音视频
    • 文档
  • 留言板
  • 关于
剑痴乎
代码为剑,如痴如醉
  1. 首页
  2. 音视频
  3. 正文

PortAudio枚举音频设备

2015年6月23日 2014点热度 1人点赞 0条评论

前面我们说到了如何用Visual Studio编译portAudio,下面我们开始讲下如何使用PortAudio,先从最简单的开始,这篇文章我们主要讲如何枚举音频相关设备。代码如下:

PortAudio 枚举音频设备
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
#include "portaudio.h"
#pragma  comment(lib,"portaudio_x86.lib")
 
 
int main()
{
int     i, iNumDevices, defaultDisplayed;
const   PaDeviceInfo *deviceInfo;
//PaStreamParameters inputParameters, outputParameters;
PaError err;
 
//初始化
err = Pa_Initialize();
if( err != paNoError )
{
cout<<"Pa_Initialize error\r\n";
    }
 
//获得设备数量
iNumDevices = Pa_GetDeviceCount();
if (iNumDevices < 0)
{
cout<<"Get device count error\r\n";
}
 
for (i = 0;i<iNumDevices;i++)
{
deviceInfo = Pa_GetDeviceInfo(i);
cout<<deviceInfo->name<<endl; //打印设备名
}
 
getchar();
return 0;
}

如下是deviceinfo对应结构体声明:

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** A structure providing information and capabilities of PortAudio devices.
Devices may support input, output or both input and output.
*/
typedef struct PaDeviceInfo
{
    int structVersion;  /* this is struct version 2 */
    const char *name;
    PaHostApiIndex hostApi; /**< note this is a host API index, not a type id*/
    
    int maxInputChannels;
    int maxOutputChannels;
 
    /** Default latency values for interactive performance. */
    PaTime defaultLowInputLatency;
    PaTime defaultLowOutputLatency;
    /** Default latency values for robust non-interactive applications (eg. playing sound files). */
    PaTime defaultHighInputLatency;
    PaTime defaultHighOutputLatency;
 
    double defaultSampleRate;
} PaDeviceInfo;

编译运行得到如下结果:

portaudio枚举音频设备

portaudio枚举音频设备

在最后几行打印的结果中出现的一些设备名汉字乱码是因为有些设备名以UTF-8编码,我没做转换,转化后即可正常显示。

本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
标签: 音视频
最后更新:2018年12月23日

Jeff

管理员——代码为剑,如痴如醉

打赏 点赞
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

版权声明

为支持原创,创作更好的文章,未经许可,禁止任何形式的转载与抄袭,如需转载请邮件私信!本人保留所有法定权利。违者必究!

最近评论
ztt 发布于 3 周前(04月05日) 你好,想看里面的视频和图片为什么没有显示呢?需要下flash吗还是什么。
huowa222 发布于 1 个月前(03月26日) 同问
邱国禄 发布于 2 个月前(02月17日) Receive Delta以0.25ms为单位,reference time以64ms为单位,kDe...
啊非 发布于 4 个月前(12月30日) 大神,请教一个问题: constexpr int kBaseScaleFactor = Tran...
啊非 发布于 4 个月前(12月30日) reference time:3字节,表示参考时间,以64ms为单位,但是 代码里面是 Trans...
相关文章
  • 音视频开发入门:视频基础
  • 大话WebRTC
  • WebRTC音视频传输基础:NAT穿透
  • Intel平台硬件加速视频编解码开发
  • 音视频开发入门:音频基础

COPYRIGHT © 2024 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang