本文整理汇总了C++中fmod::System::close方法的典型用法代码示例。如果您正苦于以下问题:C++ System::close方法的具体用法?C++ System::close怎么用?C++ System::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fmod::System
的用法示例。
在下文中一共展示了System::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playEnvironment
int Game::playEnvironment()
{
bool soundDone=false;
FMOD::System* system;
FMOD_RESULT result = FMOD::System_Create(&system);
system->init(32, FMOD_INIT_NORMAL, NULL);
FMOD::Sound* sound;
result = system->createSound("Ocean.WAV",FMOD_LOOP_NORMAL,NULL, &sound);
FMOD::Channel* channel = 0;
bool pauseSound = false;
channel->isPlaying(&pauseSound);
result = system->playSound(FMOD_CHANNEL_FREE, sound,false, &channel);
soundDone=true;
while (soundDone!=true)
{
channel->setPaused(false);
system->update();
result = sound->release();
result = system->close();
result = system->release();
}
return 0;
}
示例2: FMODErrorCheck
/**
* Create a map where the keys are the names of the devices
* and the values are the id (0-x where x = num of devices)
*/
map<string,int> AudioDevice::getDeviceMap()
{
FMOD_RESULT result;
FMOD::System* sys;
result = FMOD::System_Create( &sys );
FMODErrorCheck(result);
int numDrivers;
result = sys->getNumDrivers(&numDrivers);
FMODErrorCheck(result);
map<string,int> deviceMap;
//app::console() << "===========================" << endl;
//app::console() << "Listing audio devices:" << endl;
for(int i=0; i<numDrivers; i++)
{
FMOD_GUID guid;
char deviceName[256];
sys->getDriverInfo(i, deviceName, 256, &guid);
//app::console() << "(" << i << ") " << deviceName << endl;
deviceMap[string(deviceName)] = i;
}
//app::console() << "===========================" << endl;
FMODErrorCheck( sys->close() );
FMODErrorCheck( sys->release() );
return deviceMap;
}
示例3: shutdown
void StepTwoApp::shutdown()
{
// 4. Release resources!
for(auto& sound : mSounds) {
FMODErrorCheck(sound->release());
}
FMODErrorCheck( mSystem->close() );
FMODErrorCheck( mSystem->release() );
}
示例4: playSound
int Game::playSound(bool Sound)
{
bool soundDone= false;
//declare variable for FMOD system object
FMOD::System* system;
//allocate memory for the FMOD system object
FMOD_RESULT result = FMOD::System_Create(&system);
//initialize the FMOD system object
system->init(32, FMOD_INIT_NORMAL, NULL);
//declare variable for the sound object
FMOD::Sound* sound;
//created sound object and specify the sound
result = system->createSound("Cathedral_of_Light.mp3",FMOD_LOOP_NORMAL,NULL, &sound);
// play sound - 1st parameter can be combined flags (| separator)
FMOD::Channel* channel = 0;
//start sound
bool pauseSound=false;
channel->isPlaying(&pauseSound);
result = system->playSound(FMOD_CHANNEL_FREE, sound, Sound, &channel);
soundDone=true;
while (soundDone!=true)
{
channel->setPaused(false);
system->update();
//}
// release resources
result = sound->release();
result = system->close();
result = system->release();
}
return 0;
}
示例5: main
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;
memset(gCurrentTrackArtist, 0, 256);
memset(gCurrentTrackTitle, 0, 256);
strcpy(gOutputFileName, "output.mp3"); /* Start off like this then rename if a title tag comes along */
printf("======================================================================\n");
printf("RipNetStream Example. Copyright (c) Firelight Technologies 2004-2014.\n");
printf("======================================================================\n\n");
if (argc < 2)
{
printf("Usage: ripnetstream <url>\n");
return -1;
}
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(100, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->setStreamBufferSize(gFileBufferSize, FMOD_TIMEUNIT_RAWBYTES);
ERRCHECK(result);
result = system->attachFileSystem(myopen, myclose, myread, 0);
ERRCHECK(result);
printf("Buffering...\n\n");
result = system->createSound(argv[1], FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM | FMOD_NONBLOCKING, 0, &sound);
ERRCHECK(result);
/*
Main loop
*/
do
{
static bool mute = false;
if (sound && !channel)
{
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
}
if (_kbhit())
{
key = _getch();
switch (key)
{
case ' ' :
{
if (channel)
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
}
break;
}
case 'm' :
case 'M' :
{
if (channel)
{
channel->getMute(&mute);
channel->setMute(!mute);
}
break;
}
}
}
system->update();
if (channel)
{
bool playing = false;
int tagsupdated = 0;
//.........这里部分代码省略.........
示例6: FMOD_Main
//.........这里部分代码省略.........
{
float pitch;
result = channelgroup->getPitch(&pitch);
ERRCHECK(result);
pitch += 0.01f;
result = channelgroup->setPitch(pitch);
ERRCHECK(result);
result = system->update();
ERRCHECK(result);
Common_Sleep(10);
}
}
if (Common_BtnPress(BTN_ACTION3))
{
for (count = 0; count < 50; count++)
{
float pitch;
result = channelgroup->getPitch(&pitch);
ERRCHECK(result);
if (pitch > 0.1f)
{
pitch -= 0.01f;
}
result = channelgroup->setPitch(pitch);
ERRCHECK(result);
result = system->update();
ERRCHECK(result);
Common_Sleep(10);
}
}
result = system->update();
ERRCHECK(result);
/*
Print some information
*/
{
bool playing = false;
bool paused = false;
int chansplaying;
if (channelgroup)
{
result = channelgroup->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channelgroup->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
}
result = system->getChannelsPlaying(&chansplaying);
ERRCHECK(result);
Common_Draw("==================================================");
Common_Draw("Gapless Playback example.");
Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
Common_Draw("==================================================");
Common_Draw("");
Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
Common_Draw("Press %s to increase pitch", Common_BtnStr(BTN_ACTION2));
Common_Draw("Press %s to decrease pitch", Common_BtnStr(BTN_ACTION3));
Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
Common_Draw("");
Common_Draw("Channels Playing %d : %s", chansplaying, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Common_Sleep(50);
} while (!Common_BtnPress(BTN_QUIT));
/*
Shut down
*/
result = sound[NOTE_C]->release();
ERRCHECK(result);
result = sound[NOTE_D]->release();
ERRCHECK(result);
result = sound[NOTE_E]->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
Common_Close();
return 0;
}
示例7: main
//.........这里部分代码省略.........
channel2->setPaused(!paused);
}
if (key == '3')
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3);
ERRCHECK(result);
}
if (key == ' ')
{
listenerflag = !listenerflag;
}
if (!listenerflag)
{
if (key == '<')
{
listenerpos.x -= 1.0f * DISTANCEFACTOR;
if (listenerpos.x < -35 * DISTANCEFACTOR)
{
listenerpos.x = -35 * DISTANCEFACTOR;
}
}
if (key == '>')
{
listenerpos.x += 1.0f * DISTANCEFACTOR;
if (listenerpos.x > 36 * DISTANCEFACTOR)
{
listenerpos.x = 36 * DISTANCEFACTOR;
}
}
}
}
// ==========================================================================================
// UPDATE THE LISTENER
// ==========================================================================================
{
static float t = 0;
static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f };
FMOD_VECTOR vel;
if (listenerflag)
{
listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong
}
// ********* NOTE ******* READ NEXT COMMENT!!!!!
// vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);
// store pos for next time
lastpos = listenerpos;
result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up);
ERRCHECK(result);
t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example
// print out a small visual display
{
char s[80];
sprintf(s, "|.......................<1>......................<2>....................|");
s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L';
printf("%s\r", s);
}
}
system->update();
Sleep(INTERFACE_UPDATETIME - 1);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例8: main
//.........这里部分代码省略.........
}
memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); /* required. */
createsoundexinfo.decodebuffersize = 44100; /* Chunk size of stream update in samples. This will be the amount of data passed to the user callback. */
createsoundexinfo.length = 44100 * channels * sizeof(signed short) * 5; /* Length of PCM data in bytes of whole song (for Sound::getLength) */
createsoundexinfo.numchannels = channels; /* Number of channels in the sound. */
createsoundexinfo.defaultfrequency = 44100; /* Default playback rate of sound. */
createsoundexinfo.format = FMOD_SOUND_FORMAT_PCM16; /* Data format of sound. */
createsoundexinfo.pcmreadcallback = pcmreadcallback; /* User callback for reading. */
createsoundexinfo.pcmsetposcallback = pcmsetposcallback; /* User callback for seeking. */
result = system->createSound(0, mode, &createsoundexinfo, &sound);
ERRCHECK(result);
printf("Press space to pause, Esc to quit\n");
printf("\n");
/*
Play the sound.
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, 0, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
if (_kbhit())
{
key = _getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Time %02d:%02d:%02d/%02d:%02d:%02d : %s\r", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Sleep(20);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例9: main
//.........这里部分代码省略.........
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case '1' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, 0, &channel);
ERRCHECK(result);
break;
}
case '2' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound2, 0, &channel);
ERRCHECK(result);
break;
}
case '3' :
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, 0, &channel);
ERRCHECK(result);
break;
}
}
}
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;
if (channel)
{
FMOD::Sound *currentsound = 0;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
channel->getCurrentSound(¤tsound);
if (currentsound)
{
result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
}
}
system->getChannelsPlaying(&channelsplaying);
printf("\rTime %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", channelsplaying);
fflush(stdout);
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例10: main
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound;
FMOD_RESULT result;
unsigned int version;
/*
Create a System object and initialize.
*/
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
return 0;
}
result = system->init(1, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
result = system->createStream("../media/wave.mp3", FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
ERRCHECK(result);
printf("==========================================================================\n");
printf("Offline Decoding Example. Copyright (c) Firelight Technologies 2004-2011.\n");
printf("==========================================================================\n");
printf("\n");
printf("This program will open wave.mp3 and decode it into wave.raw using the\n");
printf("Sound::readData function.\n");
printf("\n");
/*
Decode the sound and write it to a .raw file.
*/
{
void *data;
unsigned int length = 0, read;
unsigned int bytesread;
FILE *outfp;
#define CHUNKSIZE 4096
result = sound->getLength(&length, FMOD_TIMEUNIT_PCMBYTES);
ERRCHECK(result);
outfp = fopen("output.raw", "wb");
if (!outfp)
{
printf("Error! Could not open output.raw output file.\n");
return 0;
}
data = malloc(CHUNKSIZE);
if (!data)
{
printf("Error! Failed to allocate %d bytes.\n", CHUNKSIZE);
return 0;
}
bytesread = 0;
do
{
result = sound->readData((char *)data, CHUNKSIZE, &read);
fwrite((char *)data, read, 1, outfp);
bytesread += read;
printf("writing %d bytes of %d to output.raw\r", bytesread, length);
}
while (result == FMOD_OK && read == CHUNKSIZE);
/*
Loop terminates when either
1. the read function returns an error. (ie FMOD_ERR_FILE_EOF etc).
2. the amount requested was different to the amount returned. (somehow got an EOF without the file error, maybe a non stream file format like mod/s3m/xm/it/midi).
If 'bytesread' is bigger than 'length' then it just means that FMOD miscalculated the size,
but this will not usually happen if FMOD_ACCURATETIME is used. (this will give the correct length for VBR formats)
*/
printf("\n");
if (outfp)
{
fclose(outfp);
}
}
printf("\n");
/*
Shut down
*/
//.........这里部分代码省略.........
示例11: main
//.........这里部分代码省略.........
result = cdsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
ERRCHECK(result);
printf("Total CD length %02d:%02d\n\n", lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100);
}
/*
Play a CD track
*/
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
/*
Main loop
*/
do
{
if (kbhit())
{
key = getch();
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
case 'n' :
{
currenttrack++;
if (currenttrack >= numtracks)
{
currenttrack = 0;
}
result = cdsound->getSubSound(currenttrack, &sound);
ERRCHECK(result);
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
ERRCHECK(result);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
ERRCHECK(result);
}
printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Sleep(10);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例12: main
//.........这里部分代码省略.........
switch (key)
{
case ' ' :
{
bool paused;
channel->getPaused(&paused);
channel->setPaused(!paused);
break;
}
case '<' :
{
unsigned int ms;
channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);
if (ms >= 10000)
{
ms -= 10000;
}
else
{
ms = 0;
}
channel->setPosition(ms, FMOD_TIMEUNIT_SENTENCE_MS);
break;
}
case '>' :
{
unsigned int ms;
channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);
ms += 10000;
channel->setPosition(ms, FMOD_TIMEUNIT_SENTENCE_MS);
break;
}
case 'n' :
{
channel->getPosition(¤ttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND);
currenttrack++;
if (currenttrack >= numtracks)
{
currenttrack = 0;
}
channel->setPosition(currenttrack, FMOD_TIMEUNIT_SENTENCE_SUBSOUND);
break;
}
}
}
system->update();
if (channel)
{
unsigned int ms;
unsigned int lenms;
bool playing;
bool paused;
int busy;
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->isPlaying(&playing);
ERRCHECK(result);
result = channel->getPosition(&ms, FMOD_TIMEUNIT_SENTENCE_MS);
ERRCHECK(result);
result = cdsound->getLength(&lenms, FMOD_TIMEUNIT_SENTENCE_MS);
ERRCHECK(result);
result = FMOD::File_GetDiskBusy(&busy);
ERRCHECK(result);
printf("Track %d/%d : %02d:%02d:%02d/%02d:%02d:%02d : %s (%s)\r", currenttrack + 1, numtracks, ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped", busy ? "*" : " ");
}
Sleep(50);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = cdsound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例13: main
//.........这里部分代码省略.........
channel2->setPaused(!paused);
}
if (key == '3')
{
result = system->playSound(FMOD_CHANNEL_FREE, sound3, false, &channel3);
ERRCHECK(result);
}
if (key == ' ')
{
listenerflag = !listenerflag;
}
if (!listenerflag)
{
if (key == '<')
{
listenerpos.x -= 1.0f * DISTANCEFACTOR;
if (listenerpos.x < -35 * DISTANCEFACTOR)
{
listenerpos.x = -35 * DISTANCEFACTOR;
}
}
if (key == '>')
{
listenerpos.x += 1.0f * DISTANCEFACTOR;
if (listenerpos.x > 36 * DISTANCEFACTOR)
{
listenerpos.x = 36 * DISTANCEFACTOR;
}
}
}
}
// ==========================================================================================
// UPDATE THE LISTENER
// ==========================================================================================
{
static float t = 0;
static FMOD_VECTOR lastpos = { 0.0f, 0.0f, 0.0f };
FMOD_VECTOR forward = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR up = { 0.0f, 1.0f, 0.0f };
FMOD_VECTOR vel;
if (listenerflag)
{
listenerpos.x = (float)sin(t * 0.05f) * 33.0f * DISTANCEFACTOR; // left right pingpong
}
// ********* NOTE ******* READ NEXT COMMENT!!!!!
// vel = how far we moved last FRAME (m/f), then time compensate it to SECONDS (m/s).
vel.x = (listenerpos.x - lastpos.x) * (1000 / INTERFACE_UPDATETIME);
vel.y = (listenerpos.y - lastpos.y) * (1000 / INTERFACE_UPDATETIME);
vel.z = (listenerpos.z - lastpos.z) * (1000 / INTERFACE_UPDATETIME);
// store pos for next time
lastpos = listenerpos;
result = system->set3DListenerAttributes(0, &listenerpos, &vel, &forward, &up);
ERRCHECK(result);
t += (30 * (1.0f / (float)INTERFACE_UPDATETIME)); // t is just a time value .. it increments in 30m/s steps in this example
// print out a small visual display
{
char s[80];
sprintf(s, "|.......................<1>......................<2>....................|");
s[(int)(listenerpos.x / DISTANCEFACTOR) + 35] = 'L';
printf("%s\r", s);
}
}
system->update();
Sleep(INTERFACE_UPDATETIME - 1);
} while (key != 27);
printf("\n");
/*
Shut down
*/
result = sound1->release();
ERRCHECK(result);
result = sound2->release();
ERRCHECK(result);
result = sound3->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
return 0;
}
示例14: FMOD_Main
//.........这里部分代码省略.........
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
Common_Fatal("FMOD lib version %08x doesn't match header version %08x", version, FMOD_VERSION);
}
result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
ERRCHECK(result);
result = system->createSound(Common_MediaPath("wave.mp3"), FMOD_HARDWARE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound);
ERRCHECK(result);
/*
Play the sound.
*/
result = system->playSound(sound, 0, false, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
Common_Update();
if (Common_BtnPress(BTN_ACTION1))
{
bool paused;
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->setPaused(!paused);
ERRCHECK(result);
}
result = system->update();
ERRCHECK(result);
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = false;
bool paused = false;
if (channel)
{
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = sound->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
}
Common_Draw("==================================================");
Common_Draw("Play Stream Example.");
Common_Draw("Copyright (c) Firelight Technologies 2004-2013.");
Common_Draw("==================================================");
Common_Draw("");
Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
Common_Draw("");
Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Common_Sleep(50);
} while (!Common_BtnPress(BTN_QUIT));
/*
Shut down
*/
result = sound->release();
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
Common_Close();
return 0;
}
示例15: FMOD_Main
//.........这里部分代码省略.........
result = sound->getNumSubSounds(&numsubsounds);
ERRCHECK(result);
if (numsubsounds)
{
sound->getSubSound(0, &sound_to_play);
ERRCHECK(result);
}
else
{
sound_to_play = sound;
}
/*
Play the sound.
*/
result = system->playSound(sound_to_play, 0, false, &channel);
ERRCHECK(result);
/*
Main loop.
*/
do
{
Common_Update();
if (Common_BtnPress(BTN_ACTION1))
{
bool paused;
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->setPaused(!paused);
ERRCHECK(result);
}
result = system->update();
ERRCHECK(result);
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = false;
bool paused = false;
if (channel)
{
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPaused(&paused);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
result = sound_to_play->getLength(&lenms, FMOD_TIMEUNIT_MS);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE))
{
ERRCHECK(result);
}
}
Common_Draw("==================================================");
Common_Draw("Play Stream Example.");
Common_Draw("Copyright (c) Firelight Technologies 2004-2014.");
Common_Draw("==================================================");
Common_Draw("");
Common_Draw("Press %s to toggle pause", Common_BtnStr(BTN_ACTION1));
Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
Common_Draw("");
Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
}
Common_Sleep(50);
} while (!Common_BtnPress(BTN_QUIT));
/*
Shut down
*/
result = sound->release(); /* Release the parent, not the sound that was retrieved with getSubSound. */
ERRCHECK(result);
result = system->close();
ERRCHECK(result);
result = system->release();
ERRCHECK(result);
Common_Close();
return 0;
}