本文整理汇总了C++中BackgroundMusicsMap类的典型用法代码示例。如果您正苦于以下问题:C++ BackgroundMusicsMap类的具体用法?C++ BackgroundMusicsMap怎么用?C++ BackgroundMusicsMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BackgroundMusicsMap类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stopBackgroundMusic
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
// If there is already a background music source we stop it first
if (s_backgroundSource != AL_NONE)
stopBackgroundMusic(false);
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
preloadBackgroundMusic(fullPath.c_str());
it = s_backgroundMusics.find(fullPath);
}
if (it != s_backgroundMusics.end())
{
s_backgroundSource = it->second->source;
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
setBackgroundVolume(s_volume);
alSourcePlay(s_backgroundSource);
checkALError("playBackgroundMusic:alSourcePlay");
}
}
示例2: checkALError
void SimpleAudioEngine::end()
{
checkALError("end");
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
alSourceStop(it->second->source);
checkALError("end");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end");
alDeleteSources(1, &it->second->source);
checkALError("end");
delete it->second;
}
s_effects.clear();
// and the background too
stopBackground(true);
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
alSourceStop(it->second->source);
checkALError("end");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end");
alDeleteSources(1, &it->second->source);
checkALError("end");
delete it->second;
}
s_backgroundMusics.clear();
}
示例3: Mix_FreeChunk
void SimpleAudioEngine::end()
{
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
Mix_FreeChunk(it->second->chunk);
delete it->second;
}
s_effects.clear();
// and the background too
stopBackground(true);
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
Mix_FreeMusic(it->second->music);
delete it->second;
}
s_backgroundMusics.clear();
}
示例4: createBufferFromOGG
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
ALuint buffer = AL_NONE;
if (isOGGFile(fullPath.data()))
{
buffer = createBufferFromOGG(fullPath.data());
}
else
{
buffer = alutCreateBufferFromFile(fullPath.data());
}
checkALError("preloadBackgroundMusic");
if (buffer == AL_NONE)
{
fprintf(stderr, "Error loading file: '%s'\n", fullPath.data());
alDeleteBuffers(1, &buffer);
return;
}
ALuint source = AL_NONE;
alGenSources(1, &source);
checkALError("preloadBackgroundMusic");
alSourcei(source, AL_BUFFER, buffer);
checkALError("preloadBackgroundMusic");
backgroundMusicData* data = new backgroundMusicData();
data->buffer = buffer;
data->source = source;
s_backgroundMusics.insert(BackgroundMusicsMap::value_type(fullPath, data));
}
}
示例5: stopBackgroundMusic
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
if (s_backgroundSource != AL_NONE)
stopBackgroundMusic(false);
// Changing file path to full path
std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
preloadBackgroundMusic(fullPath.c_str());
it = s_backgroundMusics.find(fullPath);
}
if (it != s_backgroundMusics.end())
{
s_backgroundSource = it->second->source;
alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
alSourcePlay(s_backgroundSource);
checkALError("playBackgroundMusic");
}
}
示例6: stopBackground
static void stopBackground(bool bReleaseData)
{
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground");
alDeleteSources(1, &it->second->source);
checkALError("stopBackground");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
示例7: fopen
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
// Changing file path to full path
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);
BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
if (it == s_backgroundMusics.end())
{
ALuint buffer = AL_NONE;
bool success = false;
OpenALFile file;
file.debugName = pszFilePath;
file.file = fopen(fullPath.c_str(), "rb");
if (!file.file) {
fprintf(stderr, "Cannot read file: '%s'\n", fullPath.data());
return;
}
const std::vector<OpenALDecoder *> &decoders = OpenALDecoder::getDecoders();
for (size_t i = 0, n = decoders.size(); !success && i < n; ++i)
success = decoders[i]->decode(file, buffer);
file.clear();
ALuint source = AL_NONE;
alGenSources(1, &source);
checkALError("preloadBackgroundMusic:alGenSources");
alSourcei(source, AL_BUFFER, buffer);
checkALError("preloadBackgroundMusic:alSourcei");
backgroundMusicData* data = new backgroundMusicData();
data->buffer = buffer;
data->source = source;
s_backgroundMusics.insert(BackgroundMusicsMap::value_type(fullPath, data));
}
}
示例8: checkALError
namespace CocosDenshion {
struct soundData {
ALuint buffer;
ALuint source;
bool isLooped;
float pitch;
float pan;
float gain;
};
typedef map<string, soundData *> EffectsMap;
EffectsMap s_effects;
typedef enum {
PLAYING,
STOPPED,
PAUSED,
} playStatus;
static float s_volume = 1.0f;
static float s_effectVolume = 1.0f;
struct backgroundMusicData {
ALuint buffer;
ALuint source;
};
typedef map<string, backgroundMusicData *> BackgroundMusicsMap;
BackgroundMusicsMap s_backgroundMusics;
static ALuint s_backgroundSource = AL_NONE;
static SimpleAudioEngine *s_engine = nullptr;
static int checkALError(const char *funcName)
{
int err = alGetError();
if (err != AL_NO_ERROR)
{
switch (err)
{
case AL_INVALID_NAME:
fprintf(stderr, "AL_INVALID_NAME in %s\n", funcName);
break;
case AL_INVALID_ENUM:
fprintf(stderr, "AL_INVALID_ENUM in %s\n", funcName);
break;
case AL_INVALID_VALUE:
fprintf(stderr, "AL_INVALID_VALUE in %s\n", funcName);
break;
case AL_INVALID_OPERATION:
fprintf(stderr, "AL_INVALID_OPERATION in %s\n", funcName);
break;
case AL_OUT_OF_MEMORY:
fprintf(stderr, "AL_OUT_OF_MEMORY in %s\n", funcName);
break;
}
}
return err;
}
static void stopBackground(bool bReleaseData)
{
// The background music might have been already stopped
// Stop request can come from
// - stopBackgroundMusic(..)
// - end(..)
if (s_backgroundSource != AL_NONE)
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteSources(1, &it->second->source);
checkALError("stopBackground:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground:alDeleteBuffers");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
static void setBackgroundVolume(float volume)
{
alSourcef(s_backgroundSource, AL_GAIN, volume);
//.........这里部分代码省略.........
示例9: stopBackground
namespace CocosDenshion
{
struct soundData {
Mix_Chunk *chunk;
bool isLooped;
};
typedef map<string, soundData *> EffectsMap;
EffectsMap s_effects;
float s_effectsVolume = 1.0;
typedef enum {
PLAYING,
STOPPED,
PAUSED,
} playStatus;
struct backgroundMusicData {
Mix_Music *music;
};
typedef map<string, backgroundMusicData *> BackgroundMusicsMap;
BackgroundMusicsMap s_backgroundMusics;
float s_backgroundVolume = 1.0;
static SimpleAudioEngine *s_engine = 0;
// Unfortunately this is just hard-coded in Emscripten's SDL
// implementation.
static const int NR_CHANNELS = 32;
static void stopBackground(bool bReleaseData)
{
SimpleAudioEngine *engine = SimpleAudioEngine::getInstance();
engine->stopBackgroundMusic();
}
SimpleAudioEngine::SimpleAudioEngine()
{
}
SimpleAudioEngine::~SimpleAudioEngine()
{
}
SimpleAudioEngine* SimpleAudioEngine::getInstance()
{
if (!s_engine)
s_engine = new SimpleAudioEngine();
return s_engine;
}
void SimpleAudioEngine::end()
{
// clear all the sounds
EffectsMap::const_iterator end = s_effects.end();
for (EffectsMap::iterator it = s_effects.begin(); it != end; it++)
{
Mix_FreeChunk(it->second->chunk);
delete it->second;
}
s_effects.clear();
// and the background too
stopBackground(true);
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
Mix_FreeMusic(it->second->music);
delete it->second;
}
s_backgroundMusics.clear();
}
//
// background audio
//
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
{
}
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
std::string key = std::string(pszFilePath);
struct backgroundMusicData *musicData;
if(!s_backgroundMusics.count(key))
{
musicData = new struct backgroundMusicData();
musicData->music = Mix_LoadMUS(pszFilePath);
s_backgroundMusics[key] = musicData;
}
else
{
musicData = s_backgroundMusics[key];
}
Mix_PlayMusic(musicData->music, bLoop ? -1 : 0);
}
void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData)
{
//.........这里部分代码省略.........
示例10: checkALError
namespace CocosDenshion
{
struct soundData {
ALuint buffer;
ALuint source;
bool isLooped;
};
typedef map<string, soundData *> EffectsMap;
EffectsMap s_effects;
typedef enum {
PLAYING,
STOPPED,
PAUSED,
} playStatus;
static float s_volume = 1.0f;
static float s_effectVolume = 1.0f;
struct backgroundMusicData {
ALuint buffer;
ALuint source;
};
typedef map<string, backgroundMusicData *> BackgroundMusicsMap;
BackgroundMusicsMap s_backgroundMusics;
static ALuint s_backgroundSource = AL_NONE;
static SimpleAudioEngine *s_engine = 0;
static int checkALError(const char *funcName)
{
int err = alGetError();
if (err != AL_NO_ERROR)
{
switch (err)
{
case AL_INVALID_NAME:
fprintf(stderr, "AL_INVALID_NAME in %s\n", funcName);
break;
case AL_INVALID_ENUM:
fprintf(stderr, "AL_INVALID_ENUM in %s\n", funcName);
break;
case AL_INVALID_VALUE:
fprintf(stderr, "AL_INVALID_VALUE in %s\n", funcName);
break;
case AL_INVALID_OPERATION:
fprintf(stderr, "AL_INVALID_OPERATION in %s\n", funcName);
break;
case AL_OUT_OF_MEMORY:
fprintf(stderr, "AL_OUT_OF_MEMORY in %s\n", funcName);
break;
}
}
return err;
}
static void stopBackground(bool bReleaseData)
{
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (BackgroundMusicsMap::iterator it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground");
alDeleteSources(1, &it->second->source);
checkALError("stopBackground");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
static void setBackgroundVolume(float volume)
{
alSourcef(s_backgroundSource, AL_GAIN, volume);
}
SimpleAudioEngine::SimpleAudioEngine()
{
alutInit(0, 0);
}
SimpleAudioEngine::~SimpleAudioEngine()
{
//.........这里部分代码省略.........
示例11: stopBackground
static void stopBackground(bool bReleaseData)
{
// The background music might have been already stopped
// Stop request can come from
// - stopBackgroundMusic(..)
// - end(..)
if (s_backgroundSource != AL_NONE)
alSourceStop(s_backgroundSource);
if (bReleaseData)
{
for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
if (it->second->source == s_backgroundSource)
{
alDeleteSources(1, &it->second->source);
checkALError("stopBackground:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("stopBackground:alDeleteBuffers");
delete it->second;
s_backgroundMusics.erase(it);
break;
}
}
}
s_backgroundSource = AL_NONE;
}
示例12: end
void SimpleAudioEngine::end()
{
checkALError("end:init");
// clear all the sound effects
EffectsMap::const_iterator end = s_effects.end();
for (auto it = s_effects.begin(); it != end; ++it)
{
alSourceStop(it->second->source);
checkALError("end:alSourceStop");
alDeleteSources(1, &it->second->source);
checkALError("end:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end:alDeleteBuffers");
delete it->second;
}
s_effects.clear();
// and the background music too
stopBackground(true);
for (auto it = s_backgroundMusics.begin(); it != s_backgroundMusics.end(); ++it)
{
alSourceStop(it->second->source);
checkALError("end:alSourceStop");
alDeleteSources(1, &it->second->source);
checkALError("end:alDeleteSources");
alDeleteBuffers(1, &it->second->buffer);
checkALError("end:alDeleteBuffers");
delete it->second;
}
s_backgroundMusics.clear();
CC_SAFE_DELETE(s_engine);
}
示例13: playBackgroundMusic
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
std::string key = std::string(pszFilePath);
struct backgroundMusicData *musicData;
if(!s_backgroundMusics.count(key))
{
musicData = new struct backgroundMusicData();
musicData->music = Mix_LoadMUS(pszFilePath);
s_backgroundMusics[key] = musicData;
}
else
{
musicData = s_backgroundMusics[key];
}
Mix_PlayMusic(musicData->music, bLoop ? -1 : 0);
}