TpAudioInterface 类
V0.2.1TpExtUtils
2025-11-14
基础信息
| 头文件: | include <TpAudioInterface.h> |
|---|---|
| Cmake: | None |
| 发布版本: | V0.2.1 |
| 继承类: | |
| 派生类: |
Public 成员函数
| TpAudioInterface(const TpString &name="default") | ||
|---|---|---|
| ~TpAudioInterface() | ||
| openDevice() | 打开音频播放设备 | |
| closeDevice() | 关闭音频播放设备 | |
| isOpen() | 音频播放设备是否打开 | |
| setVolume(tpUInt8 volume) | 设置音频播放音量 | |
| getVolume() | 获取音频播放音量 | |
| setSpeed(float speed) | 设置播放速度 | |
| getSpeed() | 获取播放速度 | |
| setPosition(tpUInt32 position) | 设置当前文件的播放位置 | |
| getPosition() | 获取当前播放位置 | |
| getDuration() | 获取文件总时长 | |
| addFile(const TpString &file) | 添加要播放的文件 | |
| addFile(const char *file) | ||
| deleteFile(const TpString &file) | 删除列表中的文件 | |
| deleteFile(const char *file) | ||
| setFile(const TpString &file) | 设置播放文件 | |
| setFile(const char *file) | ||
| playStart() | 开始播放 | |
| playContinue() | 播放继续 | |
| playPause() | 播放暂停 | |
| playStop() | 播放停止 | |
| playNext() | 播放下一个 | |
| playLast() | 播放上一个 | |
| isPlayEnd() | 是否播放结束 | |
| setSampleParame(SampleRate rate, SampleChannel channel, SampleBits bits) | 根据文件的信息自动解码并设置硬件采样参数(暂时无使用需求) | |
| setNonblock(tpBool nonblock) | 设置非阻塞(用于播放实时性高的音频流数据,播放文件时候设置不会生效) | |
| playStream(tpUInt8 *data, tpUInt32 frames, tpInt64 offset, tpInt32 delay) | 播放音频流 | |
| getSampleParame(const char *file, SampleRate &rate, SampleChannel &channel, SampleBits &bits) | 从文件获取硬件采样参数 | |
| getMaxVolume() | 获取音量允许的最大值 | |
| getMinVolume() | 获取音量允许的最小值 | |
| getMaxSpeed() | 获取速度允许的最大值 | |
| getMinSpeed() | 获取速度允许的最小值 | |
| static TpList< TpString > | getDevices() | 获取本机声卡设备列表,可直接使用返回的名字创建音频类 |
成员函数说明
TpAudioInterface::TpAudioInterface(const TpString &name="default")
暂无注释...
TpAudioInterface::~TpAudioInterface()
暂无注释...
int TpAudioInterface::openDevice()
打开音频播放设备...
打开音频播放设备
返回值:
int TpAudioInterface::closeDevice()
关闭音频播放设备...
关闭音频播放设备
返回值:
tpBool TpAudioInterface::isOpen()
音频播放设备是否打开...
音频播放设备是否打开
返回值:
int TpAudioInterface::setVolume(tpUInt8 volume)
设置音频播放音量...
设置音频播放音量
参数:volume: 音量(0~100)
返回值:
int TpAudioInterface::getVolume()
获取音频播放音量...
获取音频播放音量
返回值:
int TpAudioInterface::setSpeed(float speed)
设置播放速度...
设置播放速度
参数:speed: 播放速度,0.5~8.0
返回值:
int TpAudioInterface::getSpeed()
获取播放速度...
获取播放速度
返回值:
int TpAudioInterface::setPosition(tpUInt32 position)
设置当前文件的播放位置...
设置当前文件的播放位置
参数:position: 播放位置,单位为秒
返回值:
int TpAudioInterface::getPosition()
获取当前播放位置...
获取当前播放位置
返回值:播放位置,单位为秒
tpUInt32 TpAudioInterface::getDuration()
获取文件总时长...
获取文件总时长
返回值:文件时长,单位为秒
int TpAudioInterface::addFile(const TpString &file)
添加要播放的文件...
添加要播放的文件
参数:file: 文件
返回值:
int TpAudioInterface::addFile(const char *file)
暂无注释...
int TpAudioInterface::deleteFile(const TpString &file)
删除列表中的文件...
删除列表中的文件
参数:file: 文件
返回值:
int TpAudioInterface::deleteFile(const char *file)
暂无注释...
int TpAudioInterface::setFile(const TpString &file)
设置播放文件...
设置播放文件
参数:file: 文件
返回值:
int TpAudioInterface::setFile(const char *file)
暂无注释...
int TpAudioInterface::playStart()
开始播放...
开始播放
返回值:
int TpAudioInterface::playContinue()
播放继续...
播放继续
返回值:
int TpAudioInterface::playPause()
播放暂停...
播放暂停
返回值:
int TpAudioInterface::playStop()
播放停止...
播放停止
返回值:
int TpAudioInterface::playNext()
播放下一个...
播放下一个
返回值:
int TpAudioInterface::playLast()
播放上一个...
播放上一个
返回值:
tpBool TpAudioInterface::isPlayEnd()
是否播放结束...
是否播放结束
返回值:
int TpAudioInterface::setSampleParame(SampleRate rate, SampleChannel channel, SampleBits bits)
根据文件的信息自动解码并设置硬件采样参数(暂时无使用需求)...
根据文件的信息自动解码并设置硬件采样参数(暂时无使用需求)
手动设置硬件采样参数
参数:file:
参数:rate:
参数:channel:
参数:bits:
返回值:
返回值:
int TpAudioInterface::setNonblock(tpBool nonblock)
设置非阻塞(用于播放实时性高的音频流数据,播放文件时候设置不...
设置非阻塞(用于播放实时性高的音频流数据,播放文件时候设置不会生效)
参数:nonblock: 设置为true为非阻塞模式
返回值:
int TpAudioInterface::playStream(tpUInt8 *data, tpUInt32 frames, tpInt64 offset, tpInt32 delay)
播放音频流...
播放音频流
参数:data: 音频流数据(当前只允许小端数据)
参数:frames: 帧数(一帧包含一个采样点,每个采样点需要采样的字节数=通道数*位数/8)
参数:offset: 相对于第一次播放的偏移,如果不需要设置为-1即可,但是内部无法自行记录
参数:delay: 阻塞时长,不需要阻塞直接设置为0即可
返回值:
int TpAudioInterface::getSampleParame(const char *file, SampleRate &rate, SampleChannel &channel, SampleBits &bits)
从文件获取硬件采样参数...
从文件获取硬件采样参数
参数:rate:
参数:channel:
参数:bits:
返回值:
int TpAudioInterface::getMaxVolume()
获取音量允许的最大值...
获取音量允许的最大值
返回值:
int TpAudioInterface::getMinVolume()
获取音量允许的最小值...
获取音量允许的最小值
返回值:
float TpAudioInterface::getMaxSpeed()
获取速度允许的最大值...
获取速度允许的最大值
返回值:
float TpAudioInterface::getMinSpeed()
获取速度允许的最小值...
获取速度允许的最小值
返回值:
static TpList< TpString > TpAudioInterface::getDevices()
获取本机声卡设备列表,可直接使用返回的名字创建音频类...
获取本机声卡设备列表,可直接使用返回的名字创建音频类
返回值:
