当前位置: 首页>>代码示例>>C++>>正文


C++ SoundPlayer类代码示例

本文整理汇总了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);
}
开发者ID:valereA,项目名称:murmur,代码行数:61,代码来源:soundManager.cpp

示例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);
    }    
}
开发者ID:jerlich,项目名称:rt-fsm,代码行数:25,代码来源:EmulApp.cpp

示例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);
}
开发者ID:gclue,项目名称:GCube2,代码行数:34,代码来源:FirstSceneController.cpp

示例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;
}
开发者ID:Gooeybots,项目名称:Hackman,代码行数:33,代码来源:playgame.cpp

示例5: SoundPlayer

Status SoundManager::createMeidaPlayer( SoundClip* clip )
{
    SoundPlayer* newPlayer = new SoundPlayer();
    newPlayer->init( clip );

    connect( newPlayer, &SoundPlayer::durationChanged, this, &SoundManager::onDurationChanged );

    return Status::OK;
}
开发者ID:biosdaddy,项目名称:pencil,代码行数:9,代码来源:soundmanager.cpp

示例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();
}
开发者ID:opieproject,项目名称:qte-opie,代码行数:9,代码来源:sound.cpp

示例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;
	}
}
开发者ID:gclue,项目名称:GCube2,代码行数:14,代码来源:FirstSceneController.cpp

示例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);
    }
}
开发者ID:v3ga,项目名称:murmur,代码行数:15,代码来源:soundManager.cpp

示例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});

}
开发者ID:CarlPoirier,项目名称:Example_of_Signal_Processing_on_Linux,代码行数:49,代码来源:main.cpp

示例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;
}
开发者ID:charlesa101,项目名称:cocos2d-x,代码行数:46,代码来源:SoundDataManager.cpp

示例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;
}
开发者ID:DerSaidin,项目名称:DarkRadiant,代码行数:22,代码来源:SoundPlayer.cpp

示例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();
  }
}
开发者ID:ruthmagnus,项目名称:audacity,代码行数:22,代码来源:AudioView.cpp

示例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 );
	}
}
开发者ID:AndrewFM,项目名称:Effekseer,代码行数:27,代码来源:Effekseer.EffectNode.cpp

示例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();
}
开发者ID:v3ga,项目名称:murmur,代码行数:69,代码来源:soundManager.cpp

示例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_);
  }
开发者ID:kazukin134,项目名称:BrickAndTrip,代码行数:14,代码来源:RootController.hpp


注:本文中的SoundPlayer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。