Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411579 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 05, 2024, 02:14:31 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)OpenAL- Underwater
Pages: [1] 2
Print
Author Topic: OpenAL- Underwater  (Read 11643 times)
Glaiel-Gamer
Guest
« on: September 27, 2009, 11:10:51 AM »

Anyone know how to do a good underwater effect?


This is what I have so far and well... it's less than favorable and quite hilarious when you jump in the water and hear the music go BEOOOOOO000000000WWWWWWWWWWWwwwwwwwwwww..........

(this piece of code will be called at ~120Hz when there is distortion)
Code:
void syncMusic::setDistortion(float amount){
  distortion = amount;
  float val = 1.0;
  if(distortion > .1){
    val = 1.0 - random(0.8, 1.0)*distortion * .4;
  }
  for(int i = 0; i<tracks.size(); i++){
    alSourcef (tracks[i]->Source, AL_PITCH, val);
  }
}
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #1 on: September 27, 2009, 11:29:54 AM »

I'm guessing you'd want reverb... I think OpenAL has an EAX extension for reverb, but since it's EAX, it only works on windows.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #2 on: September 27, 2009, 11:42:01 AM »

Don't distort the pitch. Run it through a lowpass filter instead. And yeah, reverb might help too.
Logged
raigan
Level 5
*****


View Profile
« Reply #3 on: September 27, 2009, 01:34:20 PM »

Yeah, I think just a low-pass filter should do it.
Logged
Glaiel-Gamer
Guest
« Reply #4 on: September 27, 2009, 01:43:14 PM »

Yeah, I think just a low-pass filter should do it.

any links for how to do this in openAL?

I prefer to keep dependencies to a minimum
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #5 on: September 27, 2009, 01:58:43 PM »

you could just have two sets of sound effects: above and below water. run all your sounds through a low pass filter in audacity, and create separate sound files for each sound. then just switch to those when the player goes underwater.
Logged

Glaiel-Gamer
Guest
« Reply #6 on: September 27, 2009, 01:59:33 PM »

you could just have two sets of sound effects: above and below water. run all your sounds through a low pass filter in audacity, and create separate sounds for each sound. then just switch to those when the player goes underwater.

I'm talking about background music and considering I have 5 tracks of music per "song" (~20-30 MB per song) I don't want to end up doubling that
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #7 on: September 27, 2009, 02:04:17 PM »

ah, understandable.

another option is just to quiet it. simply reducing the volume suddenly can given an interesting effect.
Logged

Glaiel-Gamer
Guest
« Reply #8 on: September 27, 2009, 02:11:24 PM »

ah, understandable.

another option is just to quiet it. simply reducing the volume suddenly can given an interesting effect.
I kinda want some funky effect

I had this right now
http://www.youtube.com/watch?v=0ELUuncInPQ#t=8m41s

That was using one of the 5 tracks as a "water" track and he put some funky staticy chords in it to layer on top of the other 5.

I'm changing that since water isn't really common enough to warrant wasting a whole audio track for, and I decided to add another one in somewhere else and free up the space used by the water track by using a filter instead. I don't want to use 6 tracks either, I'm already pushing it trying to stream 5 oggs at a time and the filesize can't really afford it especially when i add more songs in
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #9 on: September 27, 2009, 02:26:47 PM »

i can't really tell the difference between underwater and not there, although that could be because of youtube's poor sound quality
Logged

Impossible
Level 3
***



View Profile
« Reply #10 on: September 27, 2009, 03:11:43 PM »

Yeah, I think just a low-pass filter should do it.

any links for how to do this in openAL?

I prefer to keep dependencies to a minimum

I don't think its possible in a cross platform way in OpenAL. OpenAL is a really shitty audio API...
Logged
Zaphos
Guest
« Reply #11 on: September 27, 2009, 03:52:01 PM »

EFX is supposed to be the portable equivalent to EAX for OpenAL and should let you do low pass filters and reverb -- there are samples in the OpenAL SDK for this, and a doc called "Effects Extension Guide.pdf" that might help.

edit: EFXFilter.cpp in the sdk specifically seems like what you might be looking for.
« Last Edit: September 27, 2009, 03:57:52 PM by Zaphos » Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #12 on: September 27, 2009, 05:33:39 PM »

Yeah, I think just a low-pass filter should do it.

any links for how to do this in openAL?

I prefer to keep dependencies to a minimum

I don't think its possible in a cross platform way in OpenAL. OpenAL is a really shitty audio API...

What would you recommend instead of OpenAL? All I know of myself is FMOD, but that comes with a pretty nasty license if you want to make any profit from your product.
Logged

Glaiel-Gamer
Guest
« Reply #13 on: September 27, 2009, 05:48:56 PM »

Yeah, I think just a low-pass filter should do it.

any links for how to do this in openAL?

I prefer to keep dependencies to a minimum

I don't think its possible in a cross platform way in OpenAL. OpenAL is a really shitty audio API...

What would you recommend instead of OpenAL? All I know of myself is FMOD, but that comes with a pretty nasty license if you want to make any profit from your product.

I'm personally still using openAL since i really like it and I get myself some nice low level access to the sound and it's free.

I was not asking for alternatives to it anyway, or for opinions on the library, but looking for specific help within the library
Logged
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #14 on: September 27, 2009, 06:42:34 PM »

If you're going to be working with raw sound values, as in OpenAL, it might be worth it to learn how to do low pass/high pass/LTI filters for real.

As I remember though you can actually do a cheapo low pass filter by doing a "weighted moving average". All you really have to do, each time you write a sample, is average it with previous samples. So do something like this:

#define WEIGHT 0.1
inline float ugly_lowpass(float in) {
static float last = 0;
last = in*WEIGHT + last*(1-WEIGHT);
return last;
}

Then run ugly_lowpass(x) sequentially on every sample you send to the sound card.

As I understand if you sit down and do the math this turns out to be equivalent to a low pass filter done "correctly".

http://lorien.ncl.ac.uk/ming/filter/fillpass.htm

EDIT: Some random thoughts on this code snippet: The closer to 0 the WEIGHT number is the heavier the low pass will be. Also the heavier the low pass is the progressively quieter the output will be. If this isn't what you want may want to compensate by turning up the volume, or adding echo. I think low pass + echo will give you something very much like the cliche "video game underwater effect".
« Last Edit: September 27, 2009, 07:20:17 PM by mcc » Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #15 on: September 27, 2009, 07:55:18 PM »

MCC is on the money here, you can roll your own low pass. More example code over at the wikipedia article:
http://en.wikipedia.org/wiki/Low-pass_filter#Algorithmic_implementation
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #16 on: September 27, 2009, 08:42:28 PM »

Yeah, I think just a low-pass filter should do it.

any links for how to do this in openAL?

I prefer to keep dependencies to a minimum

I don't think its possible in a cross platform way in OpenAL. OpenAL is a really shitty audio API...

What would you recommend instead of OpenAL? All I know of myself is FMOD, but that comes with a pretty nasty license if you want to make any profit from your product.

Really? I find FMOD's license to be quite reasonable.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Zaphos
Guest
« Reply #17 on: September 27, 2009, 10:47:50 PM »

MCC is on the money here, you can roll your own low pass. More example code over at the wikipedia article:
http://en.wikipedia.org/wiki/Low-pass_filter#Algorithmic_implementation
Would you recommend this over just using the built in filter functions?
Logged
John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #18 on: September 27, 2009, 11:39:52 PM »

I have never used OpenAL, so I can't comment on its built-in filter functions. A lowpass filter is super easy to implement, though, as long as you have convenient access to your audio sample data.
Logged
bateleur
Level 10
*****



View Profile
« Reply #19 on: September 28, 2009, 05:51:18 AM »

Really? I find FMOD's license to be quite reasonable.

The licence info appears to suggest a four digit cost even for an indie game. Whether it's "reasonable" or not, it does seem high for an audio library and I can understand any developer who felt they'd rather avoid that expense.
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic