本文整理汇总了C++中SoundSource类的典型用法代码示例。如果您正苦于以下问题:C++ SoundSource类的具体用法?C++ SoundSource怎么用?C++ SoundSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SoundSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePlaySound
void SoundEffects::HandlePlaySound(StringHash eventType, VariantMap& eventData)
{
Button* button = static_cast<Button*>(GetEventSender());
const String& soundResourceName = button->GetVar(VAR_SOUNDRESOURCE).GetString();
// Get the sound resource
ResourceCache* cache = GetSubsystem<ResourceCache>();
Sound* sound = cache->GetResource<Sound>(soundResourceName);
if (sound)
{
// Create a scene node with a SoundSource component for playing the sound. The SoundSource component plays
// non-positional audio, so its 3D position in the scene does not matter. For positional sounds the
// SoundSource3D component would be used instead
Node* soundNode = scene_->CreateChild("Sound");
SoundSource* soundSource = soundNode->CreateComponent<SoundSource>();
soundSource->Play(sound);
// In case we also play music, set the sound volume below maximum so that we don't clip the output
soundSource->SetGain(0.75f);
// Subscribe to the "sound finished" event generated by the SoundSource for removing the node once the sound has played
// Note: the event is sent through the Node (similar to e.g. node physics collision and animation trigger events)
// to not require subscribing to the particular component
SubscribeToEvent(soundNode, E_SOUNDFINISHED, URHO3D_HANDLER(SoundEffects, HandleSoundFinished));
}
}
示例2: CreateSoundSource
bool SoundManager::PlayStream( const std::string& resource_path, double fadein_time, bool looped, int sound_group, U8 volume )
{
// m_pSoundManagerImpl->PlayStream( resource_path, fadein_time, looped, sound_group, volume );
if( m_mapNameToSoundSource.find( resource_path ) != m_mapNameToSoundSource.end() )
{
// A stream sound with the same name has already been loaded.
return false;
}
SoundDesc desc;
desc.Loop = looped == 1 ? true : false;
desc.Streamed = true;
desc.SourceManagement = SoundSource::Manual;
SoundSource *pSource = CreateSoundSource( resource_path, desc );
if( pSource )
{
m_mapNameToSoundSource[resource_path] = pSource;
pSource->Play();
return true;
}
else
{
LOG_PRINT_ERROR( "Cannot play streamed sound of: " + resource_path );
return false;
}
}
示例3: alcProcessContext
void
SoundManager::update()
{
if (!sound_enabled)
return;
// check for finished sound sources
for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
SoundSource* source = *i;
if(!source->playing()) {
delete source;
i = sources.erase(i);
} else {
++i;
}
}
// check streaming sounds
if(music_source) {
music_source->update();
}
if(next_music_source && (!music_source || !music_source->playing())) {
delete music_source;
music_source = next_music_source;
//music_source->setFading(StreamSoundSource::FadingOn, 1.0f);
music_source->play();
next_music_source = 0;
}
alcProcessContext(context);
check_alc_error("Error while processing audio context: ");
}
示例4: lck
void CSound::PlaySample(size_t id, const float3& p, const float3& velocity, float volume, bool relative)
{
boost::mutex::scoped_lock lck(soundMutex);
if (sources.empty() || volume == 0.0f)
return;
if (id == 0)
{
numEmptyPlayRequests++;
return;
}
if (p.distance(myPos) > sounds[id].MaxDistance())
{
if (!relative)
return;
else
LogObject(LOG_SOUND) << "CSound::PlaySample: maxdist ignored for relative payback: " << sounds[id].Name();
}
SoundSource* best = GetNextBestSource(false);
if (!best->IsPlaying() || (best->GetCurrentPriority() <= 0 && best->GetCurrentPriority() < sounds[id].GetPriority()))
best->Play(&sounds[id], p, velocity, volume, relative);
CheckError("CSound::PlaySample");
}
示例5: RELEASE
SoundSource* DeviceAudioDX11::playQuick (SoundResource *sound)
{
SoundSource* source = SoundSource::create();
ScriptingSound* sound_loader = ScriptingSound::create();
// Build the sound file loader
sound_loader->setSoundProperty(sound);
// Connect sound packet outputs
PlugBase *s1 = source->getPlugByName("Sound_Packet");
PlugBase *s2 = sound_loader->getPlugByName("Sound_Packet");
s1->setIncomingConnection(s2);
// Play the sound source
if (play(source, sound_loader)) {
if (source->countReferences() <= 1) {
RELEASE(source);
} else {
source->release(); // Playing increments ref count so this pointer is still good
}
RELEASE(sound_loader);
return source;
} else {
RELEASE(sound_loader);
RELEASE(source);
return NULL;
}
}
示例6: alcProcessContext
void
SoundManager::update()
{
static float lasttime = real_time;
if(real_time - lasttime < 0.3)
return;
lasttime = real_time;
// update and check for finished sound sources
for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
SoundSource* source = *i;
source->update();
if(!source->playing()) {
delete source;
i = sources.erase(i);
} else {
++i;
}
}
// check streaming sounds
if(music_source) {
music_source->update();
}
alcProcessContext(context);
check_alc_error("Error while processing audio context: ");
}
示例7: InputMaster
void MasterControl::Start()
{
new InputMaster(context_, this);
cache_ = GetSubsystem<ResourceCache>();
graphics_ = GetSubsystem<Graphics>();
renderer_ = GetSubsystem<Renderer>();
CreateSineLookupTable();
// Get default style
defaultStyle_ = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml");
//Create console and debug HUD.
CreateConsoleAndDebugHud();
//Create the scene content
CreateScene();
//Create the UI content
CreateUI();
//Hook up to the frame update and render post-update events
SubscribeToEvents();
Sound* music = cache_->GetResource<Sound>("Resources/Music/Alien Chaos - Disorder.ogg"); //Battle
music->SetLooped(true);
Node* musicNode = world.scene->CreateChild("Music");
SoundSource* musicSource = musicNode->CreateComponent<SoundSource>();
musicSource->SetGain(0.32f);
musicSource->SetSoundType(SOUND_MUSIC);
musicSource->Play(music);
}
示例8: Init
void Bullet::Init(bool isPlayer, Vector2 spawnPosition)
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
Graphics* graphics = GetSubsystem<Graphics>();
halfHeight_ = graphics->GetHeight() * PIXEL_SIZE * 0.5f;
isPlayer_ = isPlayer;
Sound* laserSound = cache->GetResource<Sound>(isPlayer_ ? "Sounds/laser01.wav" : "Sounds/laser02.wav");
StaticSprite2D* sprite2D = node_->CreateComponent<StaticSprite2D>();
if (isPlayer_)
sprite2D->SetSprite( cache->GetResource<Sprite2D>("Sprites/blue_beam.png"));
else
sprite2D->SetSprite(cache->GetResource<Sprite2D>("Sprites/green_beam.png"));
sprite2D->SetBlendMode(BLEND_ADDALPHA);
SoundSource* soundSource = node_->CreateComponent<SoundSource>();
soundSource->SetSoundType(SOUND_EFFECT);
soundSource->SetGain(0.75f);
soundSource->Play(laserSound);
node_->SetPosition2D(spawnPosition);
if (!isPlayer)
{
node_->Roll(180.0f);
}
}
示例9: TDtest
void TDtest(){
AudioEasyAccess* aea = AudioEasyAccess::getInstance();
aea->playMusic("a", "drumloop.wav");
aea->playSFX("b", "drumloop.wav");
SoundSource* s = aea->getSoundSource("c", "jaguar.wav", -1.0, 0.0, 0.0);
s->playSound();
}
示例10: alSourceStop
// ------------------------------------------------------------------
void Sound::loop()
{
alSourceStop(mSource);
SoundSource* source = nEngine::Resources::inst().require<SoundSource> (mSourceName);
mStarted = true;
alSourcei(mSource, AL_BUFFER, source->getBuffer());
alSourcei(mSource, AL_LOOPING, AL_TRUE);
alSourcePlay(mSource);
}
示例11: onModelChanged
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void MissileVisual::onModelChanged()
{
RigidBodyVisual::onModelChanged();
// particle trail
s_effect_manager.createEffect("missile_smoke", osg_wrapper_->getOsgNode());
// fly by sound effect
SoundSource * snd = s_soundmanager.playLoopingEffect(s_params.get<std::string>("sfx.projectile"),
getWrapperNode()->getOsgNode());
snd->setReferenceDistance(PROJECTILE_FLY_REF_DIST);
}
示例12: lck
void CSound::StartThread(int maxSounds)
{
#if BOOST_VERSION >= 103500
try
{
#endif
{
boost::mutex::scoped_lock lck(soundMutex);
// Generate sound sources
for (int i = 0; i < maxSounds; i++)
{
SoundSource* thenewone = new SoundSource();
if (thenewone->IsValid())
{
sources.push_back(thenewone);
}
else
{
maxSounds = std::max(i-1,0);
LogObject(LOG_SOUND) << "Your hardware/driver can not handle more than " << maxSounds << " soundsources";
delete thenewone;
break;
}
}
// Set distance model (sound attenuation)
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
//alDopplerFactor(1.0);
alListenerf(AL_GAIN, masterVolume);
}
configHandler->Set("MaxSounds", maxSounds);
soundThreadRunning = true;
while (soundThreadRunning) {
#if BOOST_VERSION >= 103500
boost::this_thread::sleep(boost::posix_time::millisec(50)); // sleep
#else
SDL_Delay(50);
#endif
boost::mutex::scoped_lock lck(soundMutex); // lock
Update(); // call update
}
#if BOOST_VERSION >= 103500
}
catch(boost::thread_interrupted const&)
{
// do cleanup here
}
#endif
}
示例13: Node
void SoundSynthesis::CreateSound()
{
// Sound source needs a node so that it is considered enabled
node_ = new Node(context_);
SoundSource* source = node_->CreateComponent<SoundSource>();
soundStream_ = new BufferedSoundStream();
// Set format: 44100 Hz, sixteen bit, mono
soundStream_->SetFormat(44100, true, false);
// Start playback. We don't have data in the stream yet, but the SoundSource will wait until there is data,
// as the stream is by default in the "don't stop at end" mode
source->Play(soundStream_);
}
示例14: pushConnectionChanges
void BasicTranslator::pushConnectionChanges(Connection * conn)
{
SoundSource *src = conn->getSource();
Listener *snk = conn->getSink();
sendPosition("/spatosc/core/listener/" + snk->getID(), snk);
std::string srcPath = "/spatosc/core/source/" + src->getID();
sendPosition(srcPath, src);
std::string connectionPath = "/spatosc/core/connection/" + conn->getID();
sendAED(connectionPath, conn);
sendDelay(connectionPath, conn);
sendGainDB(connectionPath, conn);
}
示例15: memset
void Audio::MixOutput(void* dest, unsigned samples)
{
if (!playing_ || !clipBuffer_)
{
memset(dest, 0, samples * sampleSize_ * SAMPLE_SIZE_MUL);
return;
}
while (samples)
{
// If sample count exceeds the fragment (clip buffer) size, split the work
unsigned workSamples = Min(samples, fragmentSize_);
unsigned clipSamples = workSamples;
if (stereo_)
clipSamples <<= 1;
// Clear clip buffer
int* clipPtr = clipBuffer_.Get();
memset(clipPtr, 0, clipSamples * sizeof(int));
// Mix samples to clip buffer
for (PODVector<SoundSource*>::Iterator i = soundSources_.Begin(); i != soundSources_.End(); ++i)
{
SoundSource* source = *i;
// Check for pause if necessary
if (!pausedSoundTypes_.Empty())
{
if (pausedSoundTypes_.Contains(source->GetSoundType()))
continue;
}
source->Mix(clipPtr, workSamples, mixRate_, stereo_, interpolation_);
}
// Copy output from clip buffer to destination
#ifdef __EMSCRIPTEN__
float* destPtr = (float*)dest;
while (clipSamples--)
*destPtr++ = (float)Clamp(*clipPtr++, -32768, 32767) / 32768.0f;
#else
short* destPtr = (short*)dest;
while (clipSamples--)
*destPtr++ = (short)Clamp(*clipPtr++, -32768, 32767);
#endif
samples -= workSamples;
((unsigned char*&)dest) += sampleSize_ * SAMPLE_SIZE_MUL * workSamples;
}
}