FMOD_Sound_GetDefaults、
时间: 2024-01-12 22:02:38 浏览: 27
对不起,我之前的回答有误。在 FMOD 中,获取音频采样率的正确方法是使用 `FMOD_Sound_GetFormat` 函数。以下是使用 FMOD C API 获取当前音频采样率的示例代码:
```cpp
#include <QCoreApplication>
#include <fmod.h>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
FMOD_SYSTEM* system;
FMOD_RESULT result = FMOD_System_Create(&system);
if (result != FMOD_OK) {
qDebug() << "Failed to create FMOD system:" << FMOD_ErrorString(result);
return -1;
}
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, nullptr);
if (result != FMOD_OK) {
qDebug() << "Failed to initialize FMOD system:" << FMOD_ErrorString(result);
FMOD_System_Release(system);
return -1;
}
FMOD_SOUND* sound;
result = FMOD_System_CreateSound(system, "path/to/audio/file.wav", FMOD_DEFAULT, nullptr, &sound);
if (result != FMOD_OK) {
qDebug() << "Failed to create FMOD sound:" << FMOD_ErrorString(result);
FMOD_System_Release(system);
return -1;
}
FMOD_SOUND_FORMAT format;
result = FMOD_Sound_GetFormat(sound, nullptr, nullptr, nullptr, &format, nullptr);
if (result != FMOD_OK) {
qDebug() << "Failed to get sound format:" << FMOD_ErrorString(result);
FMOD_Sound_Release(sound);
FMOD_System_Release(system);
return -1;
}
int sampleRate;
result = FMOD_Sound_GetDefaults(sound, &sampleRate, nullptr, nullptr, nullptr);
if (result != FMOD_OK) {
qDebug() << "Failed to get sound defaults:" << FMOD_ErrorString(result);
FMOD_Sound_Release(sound);
FMOD_System_Release(system);
return -1;
}
qDebug() << "Sample rate:" << sampleRate;
FMOD_Sound_Release(sound);
FMOD_System_Close(system);
FMOD_System_Release(system);
return a.exec();
}
```
请确保已经将正确的 FMOD 库链接到项目中,并将音频文件的路径替换为实际的文件路径。这段代码会创建 FMOD 系统对象、加载音频文件,并通过 `FMOD_Sound_GetFormat` 函数获取音频文件的格式,然后使用 `FMOD_Sound_GetDefaults` 函数获取音频文件的采样率。最后,将采样率打印到调试输出中。
希望这次回答能对你有帮助。如果还有其他问题,请随时提问。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)