void AudiereMusicInterface::PlayMusic(int theSongId, int theOffset, bool noLoop) { AudiereMusicMap::iterator anItr = mMusicMap.find(theSongId); if (anItr != mMusicMap.end()) { AudiereMusicInfo* aMusicInfo = &anItr->second; aMusicInfo->mVolume = aMusicInfo->mVolumeCap; aMusicInfo->mVolumeAdd = 0.0f; if (aMusicInfo->mStream) { OutputStreamPtr aStream = aMusicInfo->mStream; aStream->setVolume(float(mMasterVolume * aMusicInfo->mVolume)); aStream->setRepeat(!noLoop); if (theOffset != 0) aStream->setPosition(theOffset); aStream->play(); } else if (aMusicInfo->mMIDIStream) { MIDIStreamPtr aStream = aMusicInfo->mMIDIStream; aStream->setRepeat(!noLoop); if (theOffset != 0) aStream->setPosition(theOffset); aStream->play(); } } }
int main(int argc, const char** argv) { const char* device_name = ""; if (argc >= 2) { device_name = argv[1]; } AudioDevicePtr device(OpenDevice(device_name)); if (!device) { cerr << "OpenDevice() failed" << endl; return EXIT_FAILURE; } OutputStreamPtr tone = device->openStream(CreateTone(440)); if (!tone) { cerr << "openStream() failed" << endl; return EXIT_FAILURE; } tone->play(); clock_t start = clock(); for (int i = 0; i < 100000; ++i) { assert(tone->isPlaying()); } clock_t end = clock(); double duration = double(end - start) / CLOCKS_PER_SEC; cout << "Total time for 100,000 isPlaying() calls = " << duration << " seconds" << endl; cout << "That is " << duration / 100000 << " seconds per call." << endl; return EXIT_SUCCESS; }
void PlaySong(const std::string& filename) { // Since this file is background music, we don't need to load the // whole thing into memory. std::string soundpath = FilePathMgr::Instance().GetSoundPath() + filename; g_currSong = OpenSound(g_device, soundpath.c_str(), true); if (!g_currSong) { assert(false); } // Great, we have some opened streams! What do we do with them? // let's start the background music first g_currSong->setRepeat(true); g_currSong->setVolume(g_volume); g_currSong->play(); }
int main(int argc, const char** argv) { if (argc != 2 && argc != 3) { cerr << "usage: simple <filename> [<device>]" << endl; return EXIT_FAILURE; } cerr << "initializing..." << endl; const char* device_name = ""; if (argc == 3) { device_name = argv[2]; } AudioDevicePtr device = OpenDevice(device_name); if (!device) { cerr << "OpenDevice() failed" << endl; return EXIT_FAILURE; } cerr << "opened device" << endl; OutputStreamPtr sound = OpenSound(device, argv[1]); if (!sound) { cerr << "OpenSound() failed" << endl; return EXIT_FAILURE; } cerr << "opened sound" << endl; sound->play(); cerr << "started playback" << endl; while (sound->isPlaying()) { sleepSecond(); if (sound->isSeekable()) { cerr << "position: " << sound->getPosition() << endl; } } return EXIT_SUCCESS; }