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


C++ Sound::getLength方法代码示例

本文整理汇总了C++中fmod::Sound::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Sound::getLength方法的具体用法?C++ Sound::getLength怎么用?C++ Sound::getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fmod::Sound的用法示例。


在下文中一共展示了Sound::getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnUpdateGame

int SinglePlayChapter::OnUpdateGame()
{
	m_pkSystem->update();
	m_pkUIManager->Update();

	bool start = !m_pkThirdCube->IsStart();
	m_pkUIManager->GetUIEngine().GetDialog(IDD_MULTI)->GetButton(IDC_RESETBTN)->SetEnabled(start);
	m_pkUIManager->GetUIEngine().GetDialog(IDD_MULTI)->GetButton(IDC_SHUFFLEBTN)->SetEnabled(start);


	if( m_pkChannel )
	{
		unsigned int lenms = 0;
		FMOD::Sound *currentsound = 0;
		m_pkChannel->getCurrentSound( &currentsound );
		m_pkChannel->setVolume(1.0f);
		if( currentsound )
		{
			currentsound->getLength(& lenms, FMOD_TIMEUNIT_MS );
		}
	}
	if( m_AnimationList.size() > 30 )
	{
		delete m_AnimationList.front();
		m_AnimationList.pop_front();
	}
	return 0;
}
开发者ID:oksangman,项目名称:Ant,代码行数:28,代码来源:SinglePlayChapter.cpp

示例2: _ObtenerTiempoCancion

UINT64 InformacionArchivoEx::_ObtenerTiempoCancion(const TCHAR *Path, FMOD::System *InstanciaFMOD) {
	UINT Milisegundos = 0;
	FMOD::Sound	 *Stream;
	InstanciaFMOD->createStream(reinterpret_cast<const char *>(Path), FMOD_OPENONLY | FMOD_UNICODE, 0, &Stream);
	Stream->getLength(&Milisegundos, FMOD_TIMEUNIT_MS);
	FMOD_RESULT R = Stream->release();
	return Milisegundos;
}
开发者ID:devildrey33,项目名称:BubaTronik,代码行数:8,代码来源:InformacionArchivoEx.cpp

示例3: getDuration

float AudioEngineImpl::getDuration(int audioID){
  try{
    FMOD::Sound * sound = mapChannelInfo[audioID].sound; 
    unsigned int length; 
    FMOD_RESULT result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
    ERRCHECK(result);
    float duration = (float)length / 1000.0f; 
    return duration;
    }catch(const std::out_of_range& oor){
      printf("AudioEngineImpl::getDuration: invalid audioID: %d\n", audioID);
    return AudioEngine::TIME_UNKNOWN;
  }
};
开发者ID:1414648814,项目名称:AStar-Cocos2dx,代码行数:13,代码来源:AudioEngine-linux.cpp

示例4: OnUpdateGame

int MultiPlayChapter::OnUpdateGame()
{
	m_pkSystem->update();
	m_pkUIManager->Update();

	bool start = !m_pkThirdCube->IsStart();
	CUI::Dialog *pkDialog = m_pkUIManager->GetUIEngine().GetDialog(IDD_MULTI);
	pkDialog->GetButton(IDC_RESETBTN)->SetEnabled(start);
	pkDialog->GetButton(IDC_SHUFFLEBTN)->SetEnabled(start);


	if( m_pkThirdCube->SendInfoSize() )
	{
		const SendRotateInfo &t = m_pkThirdCube->GetSendRotateInfo();

		//	sizeof(info) = 52

		memset(m_szData, 0, BUFSIZE);

		m_szData[0] = m_pkThirdCube->GetID();
		memcpy(&m_szData[1], &t, sizeof(t));
		m_pkNetWork->SendPacket( CS_ROTATEINFO, m_szData, sizeof(t)+1 );

		//	로테이트 정보보내기
		m_pkThirdCube->SendRotateInfoPop();
	}
	if( m_pkChannel )
	{
		unsigned int lenms = 0;
		FMOD::Sound *currentsound = 0;
		m_pkChannel->getCurrentSound( &currentsound );
		m_pkChannel->setVolume(1.0f);
		if( currentsound )
		{
			currentsound->getLength(& lenms, FMOD_TIMEUNIT_MS );
		}
	}
	if( m_AnimationList.size() > 30 )
	{
		delete m_AnimationList.front();
		m_AnimationList.pop_front();
	}

	if( m_pkThirdCube->IsSendPacketWait() && m_pkThirdCube->IsWait() )
	{
		m_pkNetWork->SendPacket( CS_WAIT, 0, 0 );
	}

	return 0;
}
开发者ID:oksangman,项目名称:Ant,代码行数:50,代码来源:MultiPlayChapter.cpp

示例5: getSoundTimeRemaining

float KSoundManager::getSoundTimeRemaining(SkySound* channel)
{
	if(mSilent) return 0;
	if(!channel) return 0;
	if(mInitFailed) return 0;
	FMOD::Sound* sound;
	channel->getCurrentSound(&sound);
	if(!sound) return 0;
	unsigned int pos = 0;
	unsigned int length;
	result = channel->getPosition(&pos, FMOD_TIMEUNIT_MS);
	result = sound->getLength(&length, FMOD_TIMEUNIT_MS);
	return 0.001 * (length - pos);
}
开发者ID:allegrocm,项目名称:Falcon,代码行数:14,代码来源:KSoundManager.cpp

示例6: _ObtenerTiempoCancionCDAudio

UINT64 InformacionArchivoEx::_ObtenerTiempoCancionCDAudio(const TCHAR *Path, FMOD::System *InstanciaFMOD) {
	char Letra[3]; 
	Letra[0] = static_cast<char>(Path[0]);
	Letra[1] = ':';
	Letra[2] = '\0';
	UINT Milisegundos = 0;
	FMOD::Sound	 *Stream = NULL;
	FMOD::Sound	 *PistaCD = NULL;
	FMOD_RESULT Error = InstanciaFMOD->createStream(Letra, FMOD_OPENONLY, 0, &Stream);
	if (Stream != NULL) {
		Stream->getSubSound(InfoPath.Pista - 1, &PistaCD); // no s'identifica la pista en els cds d'audio posible error en funcio Info
		if (PistaCD != NULL) {
			PistaCD->getLength(&Milisegundos, FMOD_TIMEUNIT_MS);
			PistaCD->release();
			Stream->release();
		}
	}
	return Milisegundos;
}
开发者ID:devildrey33,项目名称:BubaTronik,代码行数:19,代码来源:InformacionArchivoEx.cpp

示例7: Update

void SoundManager::Update(float DeltaTime)
{
    gTimeToUpdate	+=	DeltaTime;


    if(gTimeToUpdate > 0.1f)
    {
        gSystem->update();
        unsigned int ms = 0;
        unsigned int lenms = 0;
        bool         playing = false;
        bool         paused = false;
        int          channelsplaying = 0;

        if (gChannel)
        {
            FMOD::Sound *currentsound = 0;

            ErrorCheck(gChannel->isPlaying(&playing));
            ErrorCheck(gChannel->getPaused(&paused));
            ErrorCheck(gChannel->getPosition(&ms, FMOD_TIMEUNIT_MS));

            gChannel->getCurrentSound(&currentsound);

            if (currentsound)
            {
                ErrorCheck(currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS));
            }
        }

        for(int i = gPlayingSounds->size() - 1; i >= 0; --i)
        {
            PlayingSound*	tSound	=	gPlayingSounds->at(i);
            ErrorCheck( tSound->second.second->isPlaying( &playing ) );

            if(!playing)
                gPlayingSounds->erase(gPlayingSounds->begin() + i);
        }

        gTimeToUpdate	=	0;
    }
}
开发者ID:CarlRapp,项目名称:CodenameGamma,代码行数:42,代码来源:SoundManager.cpp

示例8: loadPlaylist

void SoundManager::loadPlaylist(std::string filename)
{
	FMOD::Sound* playlist;
	mSystem->createSound(filename.c_str(), FMOD_DEFAULT, 0, &playlist);
	FMOD_SOUND_TYPE type;
	playlist->getFormat(&type, 0, 0, 0);
	if(type != FMOD_SOUND_TYPE_PLAYLIST)
	{
		printf("%s, wasn't a playlist!  Make sure it exists and it's in .m3u format.\n", filename.c_str());
		return;
	}
	printf("loading playlist %s\n", filename.c_str());
	int count = 0;
	FMOD_TAG tag;
	result = FMOD_OK;
	//go through the m3u file and extract the playlist info
	result = playlist->getTag("FILE", count, &tag);
	while(result == FMOD_OK)
	{

		unsigned int trackTime = 0;
		FMOD::Sound* music;		//attempt to load the song
		result = mSystem->createSound((char*)tag.data, FMOD_CREATESTREAM | FMOD_SOFTWARE | FMOD_2D, 0, &music); 
		//if we successfully found the file, get its length and close it
		if(result == FMOD_OK)
		{
			music->getLength(&trackTime, FMOD_TIMEUNIT_MS);
			music->release();
			PlayListEntry p(std::string((char*)tag.data), 0.001 * trackTime + 2.f);
			mPlayList.push_back(p);
//			printf("our file is...%s at %f seconds\n", p.filename.c_str(), p.trackTime);
		}
		else printf("%s not found, but is listed in the playlist\n", (char*)tag.data);
		
				count++;
		//check to see if we have another file in the playlist
		result = playlist->getTag("FILE", count, &tag);
	}
	mUsePlayList = true;
}
开发者ID:thoney,项目名称:MIRAGEvisApp,代码行数:40,代码来源:SoundManager.cpp

示例9: main

int main(int argc, char *argv[])
{
    FMOD::System           *system;
    FMOD::Sound            *sound;
    FMOD::Channel          *channel = 0;
    FMOD_RESULT             result;
    FMOD_MODE               mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE;
    int                     key;
    int                     channels = 2;
    FMOD_CREATESOUNDEXINFO  createsoundexinfo;
    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(32, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
        
    printf("============================================================================\n");
    printf("User Created Sound Example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("============================================================================\n");
    printf("Sound played here is generated in realtime.  It will either play as a stream\n");
    printf("which means it is continually filled as it is playing, or it will play as a \n");
    printf("static sample, which means it is filled once as the sound is created, then  \n");
    printf("when played it will just play that short loop of data.                      \n");
    printf("============================================================================\n");
    printf("\n");

    do
    {
        printf("Press 1 to play as a runtime decoded stream. (will carry on infinitely)\n");
        printf("Press 2 to play as a static in memory sample. (loops a short block of data)\n");
        printf("Press Esc to quit.\n\n");
        key = _getch();

    } while (key != 27 && key != '1' && key != '2');

    if (key == 27)
    {
        return 0;
    }
    else if (key == '1')
    {
        mode |= FMOD_CREATESTREAM;
    }

    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;
                }
            }
//.........这里部分代码省略.........
开发者ID:chandonnet,项目名称:FTB2015,代码行数:101,代码来源:main.cpp

示例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
    */
//.........这里部分代码省略.........
开发者ID:YanisBreton,项目名称:wolf3d,代码行数:101,代码来源:main.cpp

示例11: playMusic

bool Music::playMusic(TCHAR* fileName,bool loop,bool single,float volume)
{
	try{



	FMOD::Sound* soundTemp	=	NULL;
	
	std::map<SoundStruct*,FMOD::Sound*>::iterator ite;

		for(ite=_recycle.begin();ite!=_recycle.end();ite++)
		{
			if((strcmp(((*ite).first)->soundName,fileName))==0)
			{

				soundTemp	=	(*ite).second;
				if(single==true)
				{
					unsigned int curTime	=	static_cast<unsigned int>(timeGetTime());
					if(curTime-((*ite).first)->_lastTime<((*ite).first)->_len+200)
						return true;
					else
					{
											
						((*ite).first)->_lastTime		=	curTime;
					}


				}

				//soundTemp->
			}


		}


	if(soundTemp==NULL)
	{
	
		
		if(	FMOD_OK!=_system->createStream(fileName, FMOD_HARDWARE, 0, &soundTemp))  //´´½¨ÉùÒô
		{

			return false;
		}

		soundTemp->setMode(FMOD_LOOP_OFF);  //¹Ø±ÕÑ­»·  


		if(loop)
			soundTemp->setMode(FMOD_LOOP_NORMAL);
		else
			soundTemp->setMode(FMOD_LOOP_OFF);

		_system->playSound(FMOD_CHANNEL_FREE, soundTemp, false, &_channel);		 
		_channel->setVolume(volume);    //²¥·ÅÉùÒô

		SoundStruct* temp	=	new SoundStruct;
		temp->_lastTime	=	static_cast<unsigned int>(timeGetTime());
		temp->soundName	=	new TCHAR[MAX_PATH];
		strcpy(temp->soundName,fileName);
		temp->channel	=	_channel;
		
		unsigned int llen=0;
		soundTemp->getLength(&llen,FMOD_TIMEUNIT_MS);
		temp->_len	=	llen;

		_recycle.insert(std::make_pair(temp,soundTemp));
		
		return true;

	}

	if(loop)
		soundTemp->setMode(FMOD_LOOP_NORMAL);
	else
		soundTemp->setMode(FMOD_LOOP_OFF);



	_system->playSound(FMOD_CHANNEL_FREE, soundTemp, false, &_channel);		 
	_channel->setVolume(volume);    //²¥·ÅÉùÒô
	
	}
	catch(...)
	{

	}
	
	return true;
}
开发者ID:zhvirus,项目名称:zhangtina,代码行数:92,代码来源:ZHMusic.cpp

示例12: main

int main(int ac, const char **av)
{
	// Create application window
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, _T("Douceur"), NULL };
	RegisterClassEx(&wc);
	HWND hwnd = CreateWindow(_T("Douceur"), _T("Douceur"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);

	// Initialize Direct3D
	if (CreateDeviceD3D(hwnd) < 0)
	{
		CleanupDeviceD3D();
		UnregisterClass(_T("Douceur"), wc.hInstance);
		return 1;
	}

	// Show the window
	ShowWindow(hwnd, SW_SHOWDEFAULT);
	UpdateWindow(hwnd);

	// Setup ImGui binding
	ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);

	// Load Fonts
	// (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
	//ImGuiIO& io = ImGui::GetIO();
	//io.Fonts->AddFontDefault();
	//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
	//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 16.0f);
	//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyClean.ttf", 13.0f);
	//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
	//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());

	bool show_test_window = true;
	ImVec4 clear_col = ImColor(114, 144, 154);
	// Main loop
	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	std::string arduinoMsg;
	std::string arduinoDisplayMsg;
	bool messageEnded = true;

	FMOD::System *fmodSystem;
	FMOD::System_Create(&fmodSystem);

	FMOD::Sound        *sound = 0;
	FMOD::Channel      *channel = 0;
	FMOD::ChannelGroup *mastergroup = 0;

	fmodSystem->init(128, FMOD_INIT_NORMAL, 0);

	fmodSystem->getMasterChannelGroup(&mastergroup);

	fmodSystem->createSound("../DouceurExternal/audio-samples/Yamaha-1.wav", FMOD_LOOP_NORMAL, 0, &sound);

	unsigned int soundLength = 0;
	sound->getLength(&soundLength, FMOD_TIMEUNIT_MS);

	Serial arduino("COM6");
	Board  board(fmodSystem);

	while (msg.message != WM_QUIT)
	{
		fmodSystem->update();

		if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			continue;
		}
		ImGui_ImplDX11_NewFrame();

		static bool first = true;
		static int from = 0;
		static int to = 400;
		static float freq = 1.f;
		static float pan = 0.f;
		static float pitch = 0.f;
		if (!first)
		{
			fmodSystem->playSound(sound, mastergroup, false, &channel);
			first = true;
			to = soundLength;
			channel->getFrequency(&freq);
			channel->getPitch(&pitch);
		}

		{
			ImGui::SetNextWindowPos(ImVec2(10, 10));
			ImGui::Begin("FPS", nullptr, ImVec2(0, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
			ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
			ImGui::End();
		}

		if (false)
		{
			ImGui::Begin("SoloudTest");

			bool changed = ImGui::SliderInt("from", (int*)&from, 0, soundLength - 1);
//.........这里部分代码省略.........
开发者ID:cesarl,项目名称:Douceur,代码行数:101,代码来源:main.cpp

示例13: main


//.........这里部分代码省略.........
        exinfo.length = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 2;
    }
 
    result = system->createSound(0, FMOD_2D | FMOD_SOFTWARE | FMOD_OPENUSER, &exinfo, &sound);
    ERRCHECK(result);

    printf("========================================================================\n");
    printf("Record to disk example.  Copyright (c) Firelight Technologies 2004-2014.\n");
    printf("========================================================================\n");
    printf("\n");
    printf("Press a key to start recording to record.wav\n");
    printf("\n");

    getch();

    result = system->recordStart(recorddriver, sound, true);
    ERRCHECK(result);

    printf("Press 'Esc' to quit\n");
    printf("\n");

    fp = fopen("record.wav", "wb");
    if (!fp)
    {
        printf("ERROR : could not open record.wav for writing.\n");
        return 1;
    }

    /*
        Write out the wav header.  As we don't know the length yet it will be 0.
    */
    WriteWavHeader(fp, sound, datalength);

    result = sound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);

    /*
        Main loop.
    */
    do
    {
        static unsigned int lastrecordpos = 0;
        unsigned int recordpos = 0;

        if (kbhit())
        {
            key = getch();
        }

        system->getRecordPosition(recorddriver, &recordpos);
        ERRCHECK(result);

        if (recordpos != lastrecordpos)        
        {
            void *ptr1, *ptr2;
            int blocklength;
            unsigned int len1, len2;
            
            blocklength = (int)recordpos - (int)lastrecordpos;
            if (blocklength < 0)
            {
                blocklength += soundlength;
            }

            /*
                Lock the sound to get access to the raw data.
开发者ID:kengonakajima,项目名称:moyai,代码行数:67,代码来源:main.cpp

示例14: RegisterSound

void USwFMOD::RegisterSound( USound* Sound )
{
	guard(USwFMOD::RegisterSound);
	//SWF_LOG( NAME_DevSound, TEXT("%s -- %s :: [%s]"), SWF_LOGP, *ToStr(Sound) );
	FMOD_RESULT result;

	checkSlow(Sound);
	if( !Sound->Handle )
	{
		FMOD::Sound* sound;

		// Load the data.
		Sound->Data.LoadSpecial();
		SWF_LOG( NAME_DevSound, TEXT("Register sound: %s (%i)"), Sound->GetPathName(), Sound->Data.Num() );
		check(Sound->Data.Num()>0);

		// Sound extended data
#pragma pack(push)
#pragma pack(8)
		FMOD_CREATESOUNDEXINFO exinfo;
		appMemset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
		exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
		exinfo.length = Sound->Data.Num();
#pragma pack(pop)

		// Sound flags
		FMOD_MODE fmode = 0
			| FMOD_SOFTWARE
			| FMOD_IGNORETAGS
		//	| FMOD_LOOP_OFF
		//	| FMOD_2D
			| FMOD_OPENMEMORY
			| FMOD_CREATESAMPLE
			| FMOD_3D 
			| FMOD_3D_LINEARROLLOFF
			;
	

		// Format-specific flags
		if( Sound->FileType == SoundType_WAV )
		{
			// WAV
			exinfo.suggestedsoundtype = FMOD_SOUND_TYPE_WAV;
		}
		else if( Sound->FileType == SoundType_MP2 || Sound->FileType == SoundType_MP3 )
		{
			// MP3 
			fmode |= FMOD_ACCURATETIME;
			exinfo.suggestedsoundtype = FMOD_SOUND_TYPE_MPEG;
		}
		else
		{
			// Unknown, try anyway
			fmode |= FMOD_ACCURATETIME;
		}

		// Create sound
		SWF_FMOD_CALL( System->createSound( static_cast<const char*>(Sound->Data.GetData()), fmode, &exinfo, &sound ));
		if( result == FMOD_OK )
		{
			// Register the sound.
			Sound->Handle = sound;
			SWF_FMOD_CALL( sound->setUserData(Sound) );

			unsigned int length;
			SWF_FMOD_CALL( sound->getLength(&length,FMOD_TIMEUNIT_MS) );
			Sound->Duration = length*0.001f;
		}
		else
		{
			SWF_LOG_WARN( FString::Printf(TEXT("Couldn't register sound [%s][%i][%s]"), Sound->GetPathName(), Sound->Data.Num(), *ToStr(result)) );
		}
		
		// Unload the data.
		Sound->Data.Unload();
	}

	unguard;
}
开发者ID:roman-dzieciol,项目名称:SwFMOD,代码行数:79,代码来源:SwFMODRegister.cpp

示例15: sizeof

FMOD::Channel *queue_next_sound(int outputrate, FMOD::Channel *playingchannel, int newindex, int slot)
{
    FMOD_RESULT result;
    FMOD::Channel *newchannel;
    FMOD::Sound *newsound;
    
#ifdef USE_STREAMS  /* Create a new stream */
    FMOD_CREATESOUNDEXINFO info;
    Common_Memset(&info, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    info.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    info.suggestedsoundtype = FMOD_SOUND_TYPE_OGGVORBIS;
    result = gSystem->createStream(soundname[newindex], FMOD_IGNORETAGS | FMOD_LOWMEM, &info, &sound[slot]);
    ERRCHECK(result);
    newsound = sound[slot];
#else   /* Use an existing sound that was passed into us */
    (void)slot;
    newsound = sound[newindex];
#endif
    
    result = gSystem->playSound(newsound, 0, true, &newchannel);
    ERRCHECK(result);
      
    if (playingchannel)
    {    
        unsigned long long startdelay = 0;
        unsigned int soundlength = 0;
        float soundfrequency;
        FMOD::Sound *playingsound;
        
        /*
            Get the start time of the playing channel.
        */
        result = playingchannel->getDelay(&startdelay, 0);
        ERRCHECK(result);
        
        /*
            Grab the length of the playing sound, and its frequency, so we can caluate where to place the new sound on the time line.
        */
        result = playingchannel->getCurrentSound(&playingsound);
        ERRCHECK(result);
        result = playingsound->getLength(&soundlength, FMOD_TIMEUNIT_PCM);
        ERRCHECK(result);
        result = playingchannel->getFrequency(&soundfrequency);
        ERRCHECK(result);
        
        /* 
            Now calculate the length of the sound in 'output samples'.  
            Ie if a 44khz sound is 22050 samples long, and the output rate is 48khz, then we want to delay by 24000 output samples.
        */
        soundlength *= outputrate;   
        soundlength /= (int)soundfrequency;
        
        startdelay += soundlength; /* Add output rate adjusted sound length, to the clock value of the sound that is currently playing */

        result = newchannel->setDelay(startdelay, 0); /* Set the delay of the new sound to the end of the old sound */
        ERRCHECK(result);
    }
    else
    {
        unsigned int bufferlength;
        unsigned long long startdelay;

        result = gSystem->getDSPBufferSize(&bufferlength, 0);
        ERRCHECK(result);

        result = newchannel->getDSPClock(0, &startdelay);
        ERRCHECK(result);

        startdelay += (2 * bufferlength);
        result = newchannel->setDelay(startdelay, 0);
        ERRCHECK(result);
    }
    
    {
        float val, variation;
        
        /*
            Randomize pitch/volume to make it sound more realistic / random.
        */
        result = newchannel->getFrequency(&val);
        ERRCHECK(result);
        variation = (((float)(rand()%10000) / 5000.0f) - 1.0f); /* -1.0 to +1.0 */
        val *= (1.0f + (variation * 0.02f));                    /* @22khz, range fluctuates from 21509 to 22491 */
        result = newchannel->setFrequency(val);
        ERRCHECK(result);

        result = newchannel->getVolume(&val);
        ERRCHECK(result);
        variation = ((float)(rand()%10000) / 10000.0f);         /*  0.0 to 1.0 */
        val *= (1.0f - (variation * 0.2f));                     /*  0.8 to 1.0 */
        result = newchannel->setVolume(val);
        ERRCHECK(result);
    }   
        
    result = newchannel->setPaused(false);
    ERRCHECK(result);
       
    return newchannel;
}
开发者ID:joyfish,项目名称:GameThirdPartyLibs,代码行数:99,代码来源:granular_synth.cpp


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