DevMaster.net Forums
[[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]]

Go Back   DevMaster.net Forums > Site Discussions > Articles Discussion
User Name
Password
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-15-2003, 12:05 AM   #1
DmEditor
DevMaster Editor
 
Join Date: Jan 2005
Posts: 54
Default

OpenAL Lesson 3: Multiple Sources
Author:: Jesse Maurais
Description: Create an audio scene with more than one source

Post your discussions/comments here by clicking on Add Reply.
DmEditor is offline   Reply With Quote
Old 06-16-2003, 08:31 AM   #2
Doodle
New Member
 
Join Date: Jun 2003
Posts: 1
Default

Hi, I am new here and just wanted to say that the source code link is broken!
Doodle is offline   Reply With Quote
Old 06-16-2003, 09:03 AM   #3
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

Thank you for telling us. I fixed it..and now all of them should work.
Dia Kharrat is offline   Reply With Quote
Old 07-13-2003, 03:07 PM   #4
adribin
New Member
 
Join Date: Jan 2003
Posts: 5
Default

Hi!

Thanks Jesse for those excellent tutorials.

One question:

Is there a way to find out how man y resources you actually can create
before using the function

alGenSources(sizeOfBuffer,source); ?

I get a INVALID_VALUE when I try to create more then 20 sources?

Any ideas?
adribin is offline   Reply With Quote
Old 07-13-2003, 03:13 PM   #5
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

As far as I know there isn't any 'alGetInteger(AL_SOURCES)' feature. It would be a good idea for it to be added in the future though. However your problem is strange. There _is_ a limited number of buffers/sources but I'm pretty sure that it's 32 for each. Can you post (or e-mail me) more code so I can take a look at it?
___________________________________________
FRAG THE PLANET
Ed Helms: Alcohol causes problems and guns solve problems. I don't see why you can't have guns in bars.
Other guy: That's a stupid idea.
Ed Helms: Yeah, if your a pussy.
Jesse M is offline   Reply With Quote
Old 07-13-2003, 03:17 PM   #6
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

Isn't the limit to the number of sources you can have dependent on hardware?
Dia Kharrat is offline   Reply With Quote
Old 08-02-2003, 06:01 PM   #7
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Yes, actually. I had thought that the minimum requirement was 32, but I think I may be wrong now. I've spend more time going through the Creative source code and it looks like under the DS3D implementation the number of sources is based on how many can be allocated on your card.
___________________________________________
FRAG THE PLANET
Ed Helms: Alcohol causes problems and guns solve problems. I don't see why you can't have guns in bars.
Other guy: That's a stupid idea.
Ed Helms: Yeah, if your a pussy.
Jesse M is offline   Reply With Quote
Old 09-15-2004, 10:56 AM   #8
hh10k
New Member
 
Join Date: Sep 2004
Posts: 8
Default

Shouldn't you delete the sources before trying to delete the buffers in KillALData()? Even if the sources are stopped, the buffers will still be tied to them.
hh10k is offline   Reply With Quote
Old 09-11-2006, 11:23 AM   #9
marcinekk
New Member
 
Join Date: Aug 2006
Posts: 3
Default Re: OpenAL Lesson 3: Multiple Sources

Hello, I have a strange problem.
Based on your code I created a object oriented wav player.
There seems to be a problem when using more than 1 object of that class.
When only one object appears, everything works fine. But when I try to crate and simultaneously use 2 objects or more they seem to work correctly (sources are playing, at the end everything is deleted by a destructor), however at the end, after program exits I get a segmentation fault.


Here is the code connected with class Wavplayer and small explanation:
Program reads external text file which holds number of sounds needed in the level and paths to wav files. Based on this info it loads the sound, creates buffers etc. Problem appears when i specify 2 objects (ie. soundmaps for 2 levels). Works fine but there is a seg fault at the end.
I am almost sure that the problem is connected with memory management however I wasnt able to trace a problem yet.

Sorry for a little bit messy code, below example assumes there are only 2 files specified, and it requires some upgrades.

Code:
#ifndef __WAVPLAYER_H__ #define __WAVPLAYER_H__ #include <string> #include <windows.h> #include <fstream> //OpenAl headers #include <al/al.h> #include <al/alc.h> #include <al/alut.c> // Maximum data needed. #define NUM_BUFFERS 2 // Maximum emissions needed. #define NUM_SOURCES 2 using namespace std; class Wavplayer { public: Wavplayer(string path); ~Wavplayer(); bool ReadSoundMap(); ALboolean LoadALData(); void SetSourceValues(); void SetListenerValues(); void Play(); void Stop(); void Pause(); private: int num_sounds; // Path to the soundmap file string soundmap_path; char sound_path1[100]; char sound_path2[100]; ALuint Buffers[NUM_BUFFERS]; ALuint Sources[NUM_SOURCES]; ALfloat SourcesPos[NUM_SOURCES][3]; ALfloat SourcesVel[NUM_SOURCES][3]; ALfloat ListenerPos[]; ALfloat ListenerVel[]; ALfloat ListenerOri[]; }; Wavplayer::Wavplayer(string path) { soundmap_path = path.c_str(); } Wavplayer::~Wavplayer() { alDeleteSources(NUM_SOURCES, &Sources[0]); alDeleteBuffers(NUM_BUFFERS, &Buffers[0]); } bool Wavplayer::ReadSoundMap() { ifstream soundmap; string line; char name[10]; char path[255]; int numsounds; char strMessage[255] = {0}; // Open the soundmap file soundmap.open(soundmap_path.c_str()); // Make sure we have a valid file pointer (we found the file) if(!soundmap) { sprintf(strMessage, "Unable to find the file: %s!", strMessage); MessageBox(NULL, strMessage, "Error", MB_OK); return false; } // Read first line and search for number of sounds getline(soundmap, line); sscanf(line.c_str(), "NUM_SOUNDS %d\n", &numsounds); getline(soundmap, line); // Read all sound names and paths // for(int i=0; i<numsounds; i++) // { getline(soundmap, line); sscanf(line.c_str(), "%s %s\n", name, sound_path1); cout << name << endl; cout << path << endl; getline(soundmap, line); sscanf(line.c_str(), "%s %s\n", name, sound_path2); cout << name << endl; cout << path << endl; // } soundmap.close(); } ALboolean Wavplayer::LoadALData() { // Variables to load into. ALenum format; ALsizei size; ALvoid* data; ALsizei freq; ALboolean loop; // Load wav data into a buffer. alGenBuffers(NUM_BUFFERS, Buffers); if(alGetError() != AL_NO_ERROR) return AL_FALSE; alutLoadWAVFile(sound_path1, &format, &data, &size, &freq, &loop); alBufferData(Buffers[0], format, data, size, freq); alutUnloadWAV(format, data, size, freq); alutLoadWAVFile(sound_path2, &format, &data, &size, &freq, &loop); alBufferData(Buffers[1], format, data, size, freq); alutUnloadWAV(format, data, size, freq); // Bind the buffer with the source. alGenSources(NUM_SOURCES, Sources); if(alGetError() != AL_NO_ERROR) return AL_FALSE; } void Wavplayer::SetSourceValues() { SourcesPos[0][0] = 0.0; SourcesPos[0][1] = 0.0; SourcesPos[0][2] = 0.0; alSourcefv(Sources[0], AL_POSITION, SourcesPos[0]); alSourcefv(Sources[1], AL_POSITION, SourcesPos[1]); SourcesVel[0][0] = 0.0; SourcesVel[0][1] = 0.0; SourcesVel[0][2] = 0.0; alSourcefv(Sources[0], AL_VELOCITY, SourcesVel[0]); alSourcefv(Sources[1], AL_VELOCITY, SourcesVel[1]); alSourcei (Sources[1], AL_BUFFER, Buffers[1] ); alSourcei (Sources[1], AL_LOOPING, AL_TRUE ); alSourcef (Sources[1], AL_PITCH, 1.0 ); alSourcef (Sources[1], AL_GAIN, 1.0); alSourcei (Sources[0], AL_BUFFER, Buffers[0] ); alSourcei (Sources[0], AL_LOOPING, AL_TRUE ); alSourcef (Sources[0], AL_PITCH, 1.0 ); alSourcef (Sources[0], AL_GAIN, 1.0); if(alGetError() != AL_NO_ERROR) exit(1); } void Wavplayer::SetListenerValues() { ListenerPos[0] = 0.0; ListenerPos[1] = 0.0; ListenerPos[2] = 0.0; alListenerfv(AL_POSITION, ListenerPos); ListenerVel[0] = 0.0; ListenerVel[1] = 0.0; ListenerVel[2] = 0.0; alListenerfv(AL_VELOCITY, ListenerVel); ListenerOri[0] = 0.0f; ListenerOri[1] = 0.0f; ListenerOri[2] = -1.0f; ListenerOri[4] = 0.0f; ListenerOri[5] = 1.0f; ListenerOri[6] = 0.0f; alListenerfv(AL_ORIENTATION, ListenerOri); if(alGetError() != AL_NO_ERROR) exit(1); } void Wavplayer::Play() { alSourcePlay(Sources[0]); alSourceStop(Sources[1]); } void Wavplayer::Stop() { alSourceStop(Sources[0]); alSourcePlay(Sources[1]); } void Wavplayer::Pause() { alSourcePause(Sources[0]); } #endif

Last edited by marcinekk : 09-11-2006 at 02:15 PM.
marcinekk is offline   Reply With Quote
Old 09-19-2006, 05:14 AM   #10
marcinekk
New Member
 
Join Date: Aug 2006
Posts: 3
Default Re: OpenAL Lesson 3: Multiple Sources

ahhhh I found the mistake
I had removed aluExit from the destructor in order not to revoke it twice, and eventually i forgot to paste it in my main.cpp SO alu remained open and I got these seg faults.
marcinekk is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump


All times are GMT -7. The time now is 12:31 AM.


Powered by vBulletin
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.