快板 5 一次播放多个样本
Allegro 5 Play Multiple Samples at Once
我在播放样本 Allegro 5 时遇到了一个问题。当我播放样本时,在播放完之前,我无法再次播放该样本。有时,如果正在播放另一个不同的样本,它也不会播放样本。
无论如何要解决这个问题?
我使用"声音"类播放音频,该类只有一个播放功能。其余的是构造器和成员变量,所有这些都用于播放函数。
void Sound::play()
{
al_play_sample(
pSample, // ALLEGRO_SAMPLE
mGain, // float
mPan, // float
mSpeed, // float
getPlaymode(mPlaymode), // I use my own non-AL playmode enums. This is a private function that returns the AL version.
NULL); // ALLEGRO_SAMPLE_ID
}
全班:
声音.h
class ContentManager;
enum Playmode
{
BiDir,
Loop,
Once,
StreamOnce,
StreamOneDir
};
class Sound : public Trackable
{
private:
/* Variables
* * * * * * * * * * * * */
ALLEGRO_SAMPLE* pSample;
float
mGain,
mPan,
mSpeed;
Playmode mPlaymode;
std::string
mAssetPath,
mAssetName;
/* Private Functions
* * * * * * * * * * * * */
ALLEGRO_PLAYMODE getPlaymode(Playmode playmode)
{
switch (playmode)
{
case BiDir:
return ALLEGRO_PLAYMODE::ALLEGRO_PLAYMODE_BIDIR;
case Loop:
return ALLEGRO_PLAYMODE::ALLEGRO_PLAYMODE_LOOP;
case Once:
return ALLEGRO_PLAYMODE::ALLEGRO_PLAYMODE_ONCE;
case StreamOnce:
return ALLEGRO_PLAYMODE::_ALLEGRO_PLAYMODE_STREAM_ONCE;
case StreamOneDir:
return ALLEGRO_PLAYMODE::_ALLEGRO_PLAYMODE_STREAM_ONEDIR;
// Default to once
default:
return ALLEGRO_PLAYMODE::ALLEGRO_PLAYMODE_ONCE;
}
}
public:
/* Constructors/Destructor
* * * * * * * * * * * * */
Sound();
Sound(
// assetPath, assetName, gain, pan, speed, playmode
std::string assetPath,
std::string assetName,
float gain = 1.0f,
float pan = 0.0f,
float speed = 1.0f,
Playmode playmode = Once);
Sound(const Sound& other);
~Sound();
friend class ContentManager; // My content system.
void play();
};
声音.cpp
#include "Sound.h"
/* Constructors/Destructor
* * * * * * * * * * * * */
Sound::Sound()
{
this->mAssetPath = "";
this->mAssetName = "";
this->mGain = 1.0f;
this->mPan = 0.0f;
this->mSpeed = 1.0f;
this->mPlaymode = Once;
this->pSample = NULL;
}
Sound::Sound(std::string assetPath, std::string assetName, float gain, float pan, float speed, Playmode playmode)
{
this->mAssetPath = assetPath;
this->mAssetName = assetName;
this->mGain = gain;
this->mPan = pan;
this->mSpeed = speed;
this->mPlaymode = playmode;
this->pSample = al_load_sample((assetPath + assetName).c_str());
}
Sound::Sound(const Sound& other)
{
this->mAssetPath = other.mAssetPath;
this->mAssetName = other.mAssetName;
this->mGain = other.mGain;
this->mPan = other.mPan;
this->mSpeed = other.mSpeed;
this->mPlaymode = other.mPlaymode;
this->pSample = al_load_sample((mAssetPath + mAssetName).c_str());
}
Sound::~Sound()
{
al_destroy_sample(pSample);
}
void Sound::play()
{
al_play_sample(
pSample,
mGain,
mPan,
mSpeed,
getPlaymode(mPlaymode),
NULL);
}
我通过系统的其余部分调用 play 函数,它看起来像这样:
// Game->ContentManager->Sound->play()
Game::instance()->content()->getSound("somesound.wav")->play();
内容管理器包含我的资产的映射。
这是我正在为一个班级做的一个更大项目的一部分,但不,这部分不是家庭作业。我的教授不允许我们拥有任何公共/顶级 AL 代码(例如,没有公共 AL 返回等)。
如果我需要澄清任何事情,请告诉我。任何帮助总是不胜感激的。
我可能是错的,但听起来你必须使用al_reserve_samples(number_of_samples);
保留更多样本
根据ppsz的回答,我做了一些挖掘,并根据我的发现做了以下工作。
int numSamples = /*Some int*/
int reservedSamples = 0;
int i = (numSamples >= 1 ? numSamples : 1);
bool success = false;
do
{
success = al_reserve_samples(i);
i -= 1;
}
while (success == false || i > 0);
源
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- SFML纹理像播放器
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 如何收听Windows当前正在播放的声音?
- GStreamer在开始任何播放之前进行搜索
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 如何使用libav编写.mov文件,如果文件未正确完成,则可以播放
- C++新手,想知道如何使用VS code 2019播放音频文件
- 在C++不适用于猜数字游戏的情况下再次播放选项
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 按列随机播放 2D 矢量
- 如何以编程方式将音频从任何录制设备路由到任何播放设备
- 使用源读取器从网络摄像头源获取 H264 样本
- 使用 IMFSinkWriter 编码的视频的播放速度会根据宽度而变化
- 测试驱动开发 c++:如何将对象添加到向量中,将歌曲添加到播放列表并对其进行测试
- 如何在C++中播放声音?
- 旋转播放器模型以指向一个点
- MF SinkWriter mp4文件的播放持续时间是添加音频样本时的一半,图像的播放速度也是添加音频样本的两倍
- 快板 5 一次播放多个样本
- 用C/ c++在单个5.1声道上播放样本的便携式库