![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
New Member
Join Date: Oct 2009
Location: Malaysia
Posts: 21
|
hmm..i still new to this openAL. I write my own code to run the wav file. BUt i dunno how to play the wav for only once? which function should i use? if i put the alsourcestop after the alsourceplay, it produces no sound..which function should i use ?
|
|
|
|
|
|
#2 |
|
New Member
Join Date: Oct 2009
Location: Malaysia
Posts: 21
|
i have question. In my code, when i using the alSourceplay function without looping, it comes out no sound. But, if i put this function inside a loop such as do and while loop or for loop, it produces the sound? OMG, why?
|
|
|
|
|
|
#3 |
|
DevMaster Staff
Join Date: Oct 2004
Location: Seattle, WA
Posts: 3,707
|
Post your code, please. Also be sure you've read the docs.
___________________________________________
Currently working at Sucker Punch reedbeta.com - OpenGL demos and other projects Luabridge - a lightweight, dependency-free C++/Lua binding library. CD Lite - an unobtrusive, minimal CD player application for Windows. |
|
|
|
|
|
#4 |
|
New Member
Join Date: Oct 2009
Location: Malaysia
Posts: 21
|
if using this code, it works fine. But if i take off the do while loop, it can't produce the sound.
Code:
Last edited by Reedbeta : 11-07-2009 at 01:06 PM. |
|
|
|
|
|
#5 |
|
New Member
Join Date: Oct 2009
Location: Malaysia
Posts: 21
|
if i put like this, it has no sound!..why=.=?
alSourcePlay(source); alDeleteBuffers(1, &buffer); alDeleteSources(1, &source); alutExit(); |
|
|
|
|
|
#6 |
|
DevMaster Staff
Join Date: Oct 2004
Location: Seattle, WA
Posts: 3,707
|
First of all, please use the [code]...[/code] tags in the forum to post code.
Second, it looks like your problem is you don't realize alSourcePlay() is asynchronous. alSourcePlay() just *starts* playing a sound - then returns control to you immediately. It does not wait for the sound to be finished. If you think about it this is exactly what you want for making a game or other interactive application. You don't want the game to pause just because a sound played. So, in your second code sample, you are telling the sound to start playing and then immediately deleting it and exiting. So you do not hear anything because you stopped the sound before it had a chance to play at all. In the first code sample, it works because your program waits for you to press a key in getch(), and while it's waiting the sound has time to play. If you want to play the sound once and then exit, you have to wait for the sound to finish yourself. I'm sure there are AL functions to let you do this, although I don't know which ones since I'm not very familiar with AL myself. If you look around in the API I'm sure you can find it.
___________________________________________
Currently working at Sucker Punch reedbeta.com - OpenGL demos and other projects Luabridge - a lightweight, dependency-free C++/Lua binding library. CD Lite - an unobtrusive, minimal CD player application for Windows. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|