本文整理汇总了C++中SoundPlayer类的典型用法代码示例。如果您正苦于以下问题:C++ SoundPlayer类的具体用法?C++ SoundPlayer怎么用?C++ SoundPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SoundPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
//--------------------------------------------------------------
void SoundManager::setup(ofxXmlSettings& settings)
{
m_driver = settings.getValue("murmur:soundOutput:driver", 0);
printf("- setting sound output driver [%d]\n", m_driver);
ofFmodSelectDriver(m_driver);
m_driver = ofFmodGetDriverSelected();
printf("- selected driver is [%d]\n", m_driver);
int nbOutputs = settings.getValue("murmur:soundOutput:nbSpeakers", 2);
printf("- setting sound output for %d speakers\n", nbOutputs);
ofFmodSetNumOutputs( nbOutputs );
settings.pushTag("murmur");
settings.pushTag("soundOutput");
settings.pushTag("soundMain");
int nbSpeakers = settings.getNumTags("speaker");
mp_soundMainSpeakers = new int[nbSpeakers];
for (int i=0;i<nbSpeakers;i++)
{
mp_soundMainSpeakers[i] = settings.getValue("speaker",0,i);
printf("- adding for sound main speaker [%d]\n", i);
}
m_nbSoundMainSpeakers = nbSpeakers;
settings.popTag();
settings.popTag();
string soundMainFile = settings.getAttribute("murmur:soundOutput:soundMain","file", "main.wav");
printf("- sound main is [%s]\n", soundMainFile.c_str());
ofDirectory dirSounds("Sounds");
if (dirSounds.exists())
{
dirSounds.listDir();
printf("DIR %s [%d file(s)]\n", dirSounds.path().c_str(),dirSounds.size());
vector<ofFile> files = dirSounds.getFiles();
vector<ofFile>::iterator it;
for (it = files.begin(); it != files.end(); ++it)
{
if ((*it).getExtension() == "mp3" || (*it).getExtension() == "wav")
{
string filename = (*it).getFileName();
printf("- [%s]\n", filename.c_str());
SoundPlayer* pSoundPlayer = new SoundPlayer(filename);
pSoundPlayer->loadSound( "Sounds/"+filename );
pSoundPlayer->setLoop(false);
pSoundPlayer->setMultiPlay(true);
m_listSoundPlayer.push_back( pSoundPlayer );
}
}
}
mp_soundMain = getSoundPlayer(soundMainFile);
}
示例2: trigSound
void EmulApp::trigSound(int sndtrig)
{
const bool dostop = sndtrig < 0;
const unsigned snd = dostop ? -sndtrig : sndtrig;
lastSndEvt = sndtrig;
SoundPlayerMap::iterator it = soundPlayerMap.find(snd);
SoundPlayer *sp = 0;
if (it == soundPlayerMap.end()) {
Error() << "Triggered unknown sound " << snd;
return;
}
else sp = it->second;
Debug() << "Got sound trig " << sndtrig << " for filename `" << sp->fileName() << "'";
if (dostop) {
//Debug() << "sound " << snd << " stop";
sp->stop();
controlwin->untriggeredSound(snd);
} else {
//Debug() << "sound " << snd << " play";
sp->stop();
sp->play();
controlwin->triggeredSound(snd);
}
}
示例3: LOGD
// 初期化
void FirstSceneController::onInit() {
LOGD("FirstSceneController::onInit()");
ApplicationController *ctr = ApplicationController::SharedInstance();
// 音読み込み
int bgmid = SoundPlayer::loadBGM("sound/bgm_house.ogg");
SoundPlayer *player = SoundPlayer::SharedInstance();
player->play(bgmid);
sid = SoundPlayer::loadSE("sound/se_yay.ogg");
// シーン作成
Scene_ptr sceneMain(new Scene("SceneFirst"));
// プレート追加
Figure_ptr fig;
fig = Figure_ptr(new Figure("Fig"));
fig->mesh = PrimitiveObject::createPlate(Sizef(5, 5));
// マテリアルとシェーダー設定
fig->material = Material_ptr(new Material());
fig->material->texture0 = Texture_ptr(new Texture("model/gclue_logo.png"));
fig->material->ambientColor = Colorf(0, 0, 0.5);
// fig->shader = ShaderManager::GetShader(ShaderTypeColor);
// fig->shader = ShaderManager::GetShader(ShaderTypeFlat);
fig->shader = ShaderManager::GetShader(ShaderTypeTex);
fig->transform.translate(0, 3, 0);
fig->touchEventListener = this;
fig->isTouchable = true;
// シーン変更
sceneMain->addChildNode(fig);
ctr->sceneMap[1] = sceneMain;
ctr->changeScene(1);
}
示例4: UpdateMap
bool UpdateMap(std::shared_ptr<VisibleObject> &player,
std::vector<std::shared_ptr<VisibleObject> > &objectVec, Map &map,
unsigned int &score, SoundPlayer &soundPlayer,
ResourceManager &resMan)
{
bool powerPill(false);
glm::ivec2 where((int)(player->GetX()),
(int)(player->GetY()));
Object obj(map.GetWhichObject(where));
if(obj == Object::tree || obj == Object::powerPill || obj == Object::specialObject)
{
UpdateObject(where, map, player->GetPlayer(), objectVec);
switch(obj)
{
case Object::tree:
score += 10;
soundPlayer.AddToPlay(*(resMan.GetSound("chop.ogg")));
break;
case Object::powerPill:
score += 10;
soundPlayer.AddToPlay(*(resMan.GetSound("chainsaw.ogg")));
powerPill = true;
break;
case Object::specialObject:
soundPlayer.AddToPlay(*(resMan.GetSound("woodpile.ogg")));
score += 100;
break;
default:
break;
}
}
return powerPill;
}
示例5: SoundPlayer
Status SoundManager::createMeidaPlayer( SoundClip* clip )
{
SoundPlayer* newPlayer = new SoundPlayer();
newPlayer->init( clip );
connect( newPlayer, &SoundPlayer::durationChanged, this, &SoundManager::onDurationChanged );
return Status::OK;
}
示例6: main
int main(int argc, char** argv)
{
QApplication app(argc,argv);
SoundPlayer sp;
app.setMainWidget(&sp);
sp.setCaption("Qt Example - Sounds");
sp.show();
return app.exec();
}
示例7: onTouchNode
// ノードタッチイベント
void FirstSceneController::onTouchNode(TouchableNode& node, const TouchEvent &event) {
if (event.action == TouchActionDown) {
// 音再生
SoundPlayer *player = SoundPlayer::SharedInstance();
player->play(sid);
// シーン遷移
ApplicationController *ctr = ApplicationController::SharedInstance();
ctr->changeScene(2);
// サブウィンドウ表示
Window_ptr mainWindow = ctr->windowArray[1];
mainWindow->isVisible = true;
}
}
示例8: getSoundPlayer
//--------------------------------------------------------------
void SoundManager::playSound(string name, bool isLoop, float volume, int* speakers,int nbSpeakers)
{
SoundPlayer* pSoundPlayer = getSoundPlayer(name);
if (pSoundPlayer)
{
if (speakers == 0)
pSoundPlayer->play();
else
pSoundPlayer->playTo(speakers,nbSpeakers);
pSoundPlayer->setLoop(isLoop);
pSoundPlayer->setVolume(volume);
}
}
示例9: main
int main() {
SoundPlayer soundPlayer = SoundPlayer();
Mp3Decoder mp3Decoder = Mp3Decoder();
MicRecorder micRecorder = MicRecorder();
unsigned char buffer[BUFSIZE*50] = {};
unsigned char recBuffer[BUFSIZE*50] = {};
// Put path to file here
std::string path = "smw_coin.mp3";
// TODO: Manage more than int16_t encoding format, mono and 44.1kHz
Mp3Format mp3Format = mp3Decoder.Open(path);
//std::cout << "encoding: " << mp3Format.encoding << std::endl;
//std::cout << "channels: " << mp3Format.channels << std::endl;
//std::cout << "rate: " << mp3Format.rate << std::endl;
int decodeNumber = 0;
int decodedQty = 0;
while ((decodedQty = mp3Decoder.Decode(buffer+decodeNumber*BUFSIZE, BUFSIZE)) > 0) {
soundPlayer.Play(buffer+decodeNumber*BUFSIZE, decodedQty);
// Record some data in the buffer
micRecorder.Record(recBuffer+decodeNumber*BUFSIZE, decodedQty);
decodeNumber++;
}
unsigned int samplesQty = (decodeNumber-1)*BUFSIZE/sizeof(int16_t)+decodedQty;
mp3Decoder.Close();
// Process the signals as wanted here
int delay = SignalProcessor::GetDelay((int16_t*)buffer, (int16_t*)recBuffer, samplesQty);
SignalProcessor::Delay((int16_t*)buffer, samplesQty, delay);
SignalProcessor::Scale((int16_t*)buffer, samplesQty, 1, 2);
SignalProcessor::Subtract((int16_t*)recBuffer, (int16_t*)buffer, samplesQty);
// Play back for more fun
for (unsigned int i = 0; i < decodeNumber; i++) {
soundPlayer.Play(recBuffer+i*BUFSIZE, BUFSIZE);
}
printToFile(samplesQty, {(int16_t*)buffer, (int16_t*)recBuffer});
}
示例10: BREAK_IF
int SoundDataManager::loadFromFile(const char* pFilePath)
{
int nSoundID = 0;
do
{
BREAK_IF(! FileUtils::isFileExisted(pFilePath));
int nID = BKDRHash(pFilePath);
// if we have loaded the file before,break
tEffectElement *pElement = NULL;
HASH_FIND_INT(m_pEffects, &nID, pElement);
if (pElement)
{
nSoundID = nID;
break;
}
// calculate the buffer size we needed
SoundPlayer TempPlayer;
int nBufferSize = TempPlayer.GetFileBufferSize(pFilePath);
// can not calculate the size,load failed
BREAK_IF(nBufferSize < 0);
// load the file data
unsigned char* buffer = NULL;
buffer = new unsigned char[nBufferSize];
BREAK_IF(!buffer);
int nSize = TempPlayer.DecodeFile(buffer, nBufferSize, pFilePath);
BREAK_IF(nSize < 0);
// record the id
nSoundID = nID;
// add the data to hash map
pElement = (tEffectElement*)calloc(sizeof(*pElement), 1);
pElement->nSoundID = nSoundID;
pElement->pDataBuffer = buffer;
pElement->nDataSize = nBufferSize;
pElement->FileName = "";
pElement->nPlayerSoundID = -1;
HASH_ADD_INT(m_pEffects, nSoundID, pElement);
} while (0);
return nSoundID;
}
示例11: checkBuffer
gboolean SoundPlayer::checkBuffer(gpointer data) {
// Cast the passed pointer onto self
SoundPlayer* self = reinterpret_cast<SoundPlayer*>(data);
// Check for active source and buffer
if (self->_source != 0 && self->_buffer != 0) {
ALint state;
// Query the state of the source
alGetSourcei(self->_source, AL_SOURCE_STATE, &state);
if (state == AL_STOPPED) {
// Erase the buffer
self->clearBuffer();
// Disable the timer to stop calling this function
self->_timer.disable();
return false;
}
}
// Return true, so that the timer gets called again
return true;
}
示例12: OnPlayButton
void AudioView::OnPlayButton()
{
SoundPlayer player;
double plays0 = sel0;
double plays1 = sel1;
if (sel0 == sel1) {
plays0 = 0.0;
plays1 = 10000000000.0;
}
TrackList *tracks = GetTracks();
VTrack *t = tracks->First();
while(t) {
if (t->selected && t->GetKind() == (VTrack::Wave)) {
player.Begin((WaveTrack *)t, plays0, plays1);
return;
}
t = tracks->Next();
}
}
示例13: PlaySound_
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void EffectNodeImplemented::PlaySound_(Instance& instance, SoundTag tag, Manager* manager)
{
SoundPlayer* player = manager->GetSoundPlayer();
if( player == NULL )
{
return;
}
if( Sound.WaveId >= 0 )
{
SoundPlayer::InstanceParameter parameter;
parameter.Data = m_effect->GetWave( Sound.WaveId );
parameter.Volume = Sound.Volume.getValue( *manager );
parameter.Pitch = Sound.Pitch.getValue( *manager );
parameter.Pan = Sound.Pan.getValue( *manager );
parameter.Mode3D = (Sound.PanType == ParameterSoundPanType_3D);
Vector3D::Transform( parameter.Position,
Vector3D(0.0f, 0.0f, 0.0f), instance.GetGlobalMatrix43() );
parameter.Distance = Sound.Distance;
player->Play( tag, parameter );
}
}
示例14: ofFmodSelectDriver
//--------------------------------------------------------------
void SoundManager::setup(ofxXmlSettings& settings)
{
OFAPPLOG->begin("SoundManager::setup()");
m_driver = settings.getValue("murmur:soundOutput:driver", 0);
OFAPPLOG->println(" - setting sound output driver ["+ofToString(m_driver)+"]");
ofFmodSelectDriver(m_driver);
m_driver = ofFmodGetDriverSelected();
OFAPPLOG->println(" - selected driver is "+ofToString(m_driver));
int nbOutputs = settings.getValue("murmur:soundOutput:nbSpeakers", 2);
OFAPPLOG->println(" - setting sound output for "+ofToString(nbOutputs)+" speaker(s)");
ofFmodSetNumOutputs( nbOutputs );
settings.pushTag("murmur");
settings.pushTag("soundOutput");
settings.pushTag("soundMain");
int nbSpeakers = settings.getNumTags("speaker");
mp_soundMainSpeakers = new int[nbSpeakers];
for (int i=0;i<nbSpeakers;i++)
{
mp_soundMainSpeakers[i] = settings.getValue("speaker",0,i);
OFAPPLOG->println(" - adding for sound main speaker ["+ofToString(i)+"]");
}
m_nbSoundMainSpeakers = nbSpeakers;
settings.popTag();
settings.popTag();
string soundMainFile = settings.getAttribute("murmur:soundOutput:soundMain","file", "main.wav");
OFAPPLOG->println(" - sound main is '"+soundMainFile+"'");
ofDirectory dirSounds("Sounds");
if (dirSounds.exists())
{
dirSounds.listDir();
OFAPPLOG->println(" - DIR is '"+dirSounds.path()+"' ["+ofToString(dirSounds.size())+" file(s)]");
vector<ofFile> files = dirSounds.getFiles();
vector<ofFile>::iterator it;
string strFileNames = "";
string strFileNamesSep = "";
for (it = files.begin(); it != files.end(); ++it)
{
if ((*it).getExtension() == "mp3" || (*it).getExtension() == "wav")
{
string filename = (*it).getFileName();
strFileNames += strFileNamesSep + filename;
SoundPlayer* pSoundPlayer = new SoundPlayer(filename);
pSoundPlayer->loadSound( "Sounds/"+filename );
pSoundPlayer->setLoop(false);
pSoundPlayer->setMultiPlay(true);
m_listSoundPlayer.push_back( pSoundPlayer );
strFileNamesSep = ", ";
}
}
OFAPPLOG->println(" - FILES are '"+strFileNames+"'");
}
mp_soundMain = getSoundPlayer(soundMainFile);
OFAPPLOG->end();
}
示例15: update
void update(const double progressing_seconds) noexcept override {
for (auto& controller : children_) {
controller->update(progressing_seconds);
}
// 無効なControllerを削除
boost::remove_erase_if(children_,
[](ControllerPtr& child) {
return !child->isActive();
});
// 予約されたサウンドを再生
player_.update(sound_);
}