【问题标题】:How to play sound with 7.1 audio system sfml?如何使用 7.1 音频系统 sfml 播放声音?
【发布时间】:2019-05-30 11:24:35
【问题描述】:

我正在尝试使用 sfml 录制一些声音,然后播放。我以前用我相信有 5.1 音响系统的旧耳机成功地做到了这一点。但是现在当我尝试用我的新耳机(7.1 声音)做同样的事情时。代码抛出此错误。

AL 库:(EE) SetChannelMap:无法匹配前端中心通道 (2) 在频道地图中。

我已尝试重新启动 Visual Studio。重新启动我的电脑。在 Visual Studio 中重置缓存。

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
    sf::ContextSettings settings;
    settings.antialiasingLevel = 8;
    sf::RenderWindow window;
    window.create(sf::VideoMode(800, 500), "Audio check", sf::Style::Close | sf::Style::Resize);
    if (!sf::SoundBufferRecorder::isAvailable())
    {
        // error: audio capture is not available on this system
        std::cout << "Something went wrong" << std::endl;
    }

    // create the recorder
    sf::SoundBufferRecorder recorder;

    recorder.start(44100);
    //record the audio for 5 sec
    std::this_thread::sleep_for(std::chrono::milliseconds(5000));

    recorder.stop();

    //get the buffer from the recorder and play it back
    const sf::SoundBuffer& buffer = recorder.getBuffer();
    sf::Sound sound(buffer);
    sound.play();

    sf::Event event;
    while (window.isOpen()) {

        while (window.pollEvent(event)) {
            switch (event.type) {
            case sf::Event::Closed:
                window.close();
                break;
            }
        }
        window.clear(sf::Color::Blue);
        window.display();
    }

    return EXIT_SUCCESS;
}

【问题讨论】:

    标签: c++ audio sfml


    【解决方案1】:

    实际上 SFML 不支持超过 2 个通道的录制。如果我们查看 SoundRecorder 类的方法 setChannelCount() 的文档,它最多只支持 2 个(通道)。


    编辑

    来自openAL 库, 所基于的库(重点是我的):

    六边形.ambdec

    指定 7.1 的平前六角扬声器设置 环绕输出。前置左右扬声器置于+30 和 -30 度,侧扬声器放置在 +90 和 -90 度, 和后置扬声器放置在 +150 和 -150 度。虽然这是针对 7.1 输出,但没有为解码器定义前置中置扬声器,这意味着扬声器 对于 3D 声音将静音(但仍可与 AL_SOFT_direct_channels 或 ALC_EXT_DEDICATED 输出)。 一个“适当”的 7.1 将来可能会提供解码器,但由于 扬声器配置会有所取舍。

    似乎该库不包含实际的 7.1 解码器。

    【讨论】:

    • 好的,谢谢。你知道我该如何解决这个问题吗?因为我实际上根本无法播放任何声音,因为它给了我上述错误。
    • @pabolo12 深入了解openAL 库的代码,似乎 7.1 声音可能存在一些问题。我会用我发现的内容编辑我的答案,也许在这个领域有更多经验的人可以提供帮助。
    猜你喜欢
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 2023-02-25
    • 1970-01-01
    • 2014-12-22
    • 1970-01-01
    相关资源
    最近更新 更多