JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. A/V
  3. Main content

PortAudio枚举音频设备

2015年6月23日 2236hotness 1likes 0comments

前面我们说到了如何用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编码,我没做转换,转化后即可正常显示。

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: 音视频
Last updated:2018年12月23日

Jeff

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

Tip the author Like
Next article >

Comments

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
  • 告别CapCut收费!开源视频剪辑工具OpenCut 来了
  • 音视频开发入门:视频基础
  • 大话WebRTC
  • WebRTC音视频传输基础:NAT穿透
  • Intel平台硬件加速视频编解码开发
Categories

COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang