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 07-13-2003, 07:20 PM   #1
DmEditor
DevMaster Editor
 
Join Date: Jan 2005
Posts: 54
Default

OpenAL Lesson 8: OggVorbis Streaming Using The Source Queue
Author: Jesse Maurais
Description: This tutorial explains about OggVorbis files and how to read them. How to code a simple OggVorbis player will also be shown. Sample source code is also included.

Post your discussions/comments here by clicking on Add Reply.
DmEditor is offline   Reply With Quote
Old 07-14-2003, 03:24 AM   #2
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

Heh, GREAT! thats what i've waited for! an ogg player for openAL. now it starts to really rock!

about the quality issues. in general it is definitely bether than mp3. there is no discussion about this. the only issue is the conversion from mp3 to ogg, where there can be quite some additional loss (logically). but directly from cd to ogg results in very high quality on half the size than ogg. always..

what you could've noted is that ogg yet gets used in games! so, for example Duke Nukem - Manhattan Project has all its sound as vorbis files. i think even unreal2 does (?! anyone can confirm that?).

i'm very happy to see this tutorial, as i followed the other ones and always thought yeah, OpenAL sounds great to use.... but i want my vorbis files.....

next an implementation for ogg speex, input and output, and we can start talking together through OpenAL..


does OpenAL handle input as well? through microphone? or only output? hm..


anyways, great work! i hope to see more..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-14-2003, 01:22 PM   #3
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Glad you liked it.

I'm not going to jump the fence on the Ogg vs. mp3 issue. I don't know any of the specific arguements, all I know is that there were a couple of heavily argued threads on several boards I've visited.

Yes Unreal2 does use Ogg. I actually used their files to experiment on while I was coding the article. There was one in particular that I would really liked to have distributed with the tut, but I didn't want to get sued.

Ogg Speex? Well, I'm hoping that this article will spawn a sub-series on using Ogg with OpenAL. I will definately be writting more. I'll check that one out for sure.

No, OpenAL does not support input directly. You can, however, support it inderectly by creating the PCM data yourself and sending it through the buffer object. I will also look into that for a future article.
___________________________________________
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-14-2003, 01:55 PM   #4
Noor
Senior Member
 
Join Date: Jan 2003
Location: ON, Canada
Posts: 524
Default

WOW, very nice and powerful tutorial, thanks. I was going to ask you the same question davepermen asked, but now I got it. Thanks!
___________________________________________
"What ever happened to happily ever after?"
Noor is offline   Reply With Quote
Old 07-14-2003, 09:56 PM   #5
chenbin_osu
New Member
 
Join Date: Jan 2003
Posts: 10
Default

Excellent tutorial. I've always wanted to know about OggVorbis files. Thanks a lot. Looking forward to more OpenAL tutorials.

I have one question: Why does OpenAL support OggVorbis files and not MP3 files for example?
chenbin_osu is offline   Reply With Quote
Old 07-15-2003, 02:28 AM   #6
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

it doesnt support oggvorbis. it does support streaming sources. and here we use the oggvorbis libraries to realtime uncompress the oggvorbis formated files, and stream them into openAL. you can do the same with all other audioformat, as well with other soundlibraries.

its like opengl. opengl does not support model or texture formats. just ways to feed gl with data. so formats are independend of opengl, and opengl is independend on formats. same for openal.

you can of course use mp3. but nobody would. oggvorbis is smaller, and for free.

and its essencially great if you want to make your stuff downloadable, because qualitymode -1, the lowest, still sounds great on most systems anyways (tested it out quite hard, and again, direct audio cd conversions, NOT mp3 to ogg..), and really is very small.. 25MB a typical filled 75min cd.. about 15 to 20MB a typical cd, like dido, or elton john, or what ever..1.1 to 1.5MB a typical track..

now don't let us argue wether quality -1 is good or not. for demo downloads its GREAT.. and you can even set the khz down as well, to 24000 for example, make it mono.. it still sounds good. not great anymore, but good. and you get every track under one MB..




and for textfiles, we would use ogg speex..

and in the distribution, where quality counts, we could use ogg flac, so we would have full audio cd quality (okay.. we would use ogg vorbis, with for example quality mode 1, or 2.. thats enough..)


mp3 is dead... at least for gamedev 100%.. and for audiocd's, too.. the only thing really is old mp3 files.. converting them to ogg gives quite some quality-hurt..then again, we all don't have mp3's wich we haven't recorded from a cd or other uncompressed source, have we?
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-15-2003, 11:29 AM   #7
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Unless you coung "AL_VORBIS_EXT". I think it was supposed to be used like another format enum, and the data was to be a vorbis bitstream.

alBufferData(buffer, AL_VORBIS_EXT, size, vorbis_data, rate);

I may be wrong though. Haven't looked into it very much. Better off using your own code for it though since this is likely implemented in software anyway. At least for now; I hear that there are several boards that are being shipped with support for accelerating Ogg decoding. I'll have to buy me one of those when I can scrape up some cash.
___________________________________________
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-15-2003, 02:11 PM   #8
ameijer
New Member
 
Join Date: Jan 2003
Posts: 5
Default

What are the main advantages of using OpenAL over using SDL ?
ameijer is offline   Reply With Quote
Old 07-15-2003, 03:32 PM   #9
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

Quote:
Originally Posted by ameijer
What are the main advantages of using OpenAL over using SDL ?
same as for using opengl instead of sdl? 3d? opengl style interface? great tutorials on devmaster.net?

wich ever you want.. those 3 are great features..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-15-2003, 09:38 PM   #10
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Quote:
What are the main advantages of using OpenAL over using SDL ?

Why use SDL over DirectX? We can play that game for a while.

My reason is I don't like either api. DirectX is plain ugly (unless you *really* know what your doing), and SDL is annoying for me. I don't have anything against SDL as an api per-se, but having to prefix "SDL_" before everything gets on my nerves. I just think it looks terrible. Same reason I never used fmod. (prefix "FSOUND_"? what are they thinking?!?)

I'm also starting to have a problem with all the cross-platform api's. I'm all for portability, but it's getting silly. There are just too many, and none of them really support the kind of functionality and flexibility than you get with just using the OS's api directly. I was hoping that OpenML would solve all of this, but that seems like a lost cause these days.
___________________________________________
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-16-2003, 11:14 AM   #11
Noor
Senior Member
 
Join Date: Jan 2003
Location: ON, Canada
Posts: 524
Default

I found this about the benifits of Ogg files:

http://slashdot.org/articles/02/09/09/0045...3.shtml?tid=141

Quote:
Originally Posted by slashdot
The Ogg Vorbis format came out far ahead of MP3, MP3Pro, RealAudio Surround, and Windows Media 9 Beta in a comparison of different audio formats by Germany's respected computer magazine c't. More than 6,000 people took part in the test. Heise says Ogg's dominance was most pronounced with 64 kBit/sec samples; the full magazine article (out on Monday) mentions that in pre-tests, some people actually mistook the 128 kBit/sec Ogg samples for the uncoded version. Let's hear it for those strangely named open source file formats.
___________________________________________
"What ever happened to happily ever after?"
Noor is offline   Reply With Quote
Old 07-16-2003, 03:51 PM   #12
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

the benefits?

just browse this with a simple search on ".ogg" and you find some..

upload limit per file is 2mb... hehe.. ogg fits there in nicely! just don't tell anyone those tracks are there.. thanks
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-17-2003, 02:06 AM   #13
cdgray
New Member
 
Join Date: Jan 2003
Posts: 21
Default

Thanks for the great tutorial!

Quote:
Code:
* * * *<< "version * * * * " << vorbisInfo->version * * * * << "\n" * * * *<< "channels * * * *" << vorbisInfo->channels * * * *<< "\n" * * * *<< "rate (hz) * * * " << vorbisInfo->rate * * * * * *<< "\n"

Would you mind explaining the concept of "channels" and what they are in general. I'v heard of them in many file formats, but since I came across it with this tutorial, it made me ponder over the concept a little bit more.

Thanks.
cdgray is offline   Reply With Quote
Old 07-17-2003, 02:14 AM   #14
ameijer
New Member
 
Join Date: Jan 2003
Posts: 5
Default

Do you happen to know which games actually use Ogg Vorbis files? Is it widely used?
ameijer is offline   Reply With Quote
Old 07-17-2003, 11:21 AM   #15
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Quote:
Would you mind explaining the concept of "channels" and what they are in general. I'v heard of them in many file formats, but since I came across it with this tutorial, it made me ponder over the concept a little bit more.

Well it's really not that complicated. The number of channels defines how many output samples there are contained within the file. If a file only has 1 channel than it is called "mono", if it has 2 then it is "stereo" or "binaural" (which literally means "to hear with both ears"). Usually when you have a stereo sample each channel is meant to be played in it's own speaker (or headphone). If you have more than 2 channels then your getting into some surround sound stuff which will probably require a fancier (and expensive) setup to ge the full experience.

I don't think I've mentioned this before, but OpenAL only supports spatialized sound for mono (or 1 channel) samples. This is heavily based on research done by the IA-SIG I3DL2 papers which state that both (or all) output devices need to be available to the audio api in order to fully model the effect of 3D sound. This simply cannot be done with stereo samples.

Quote:
Do you happen to know which games actually use Ogg Vorbis files? Is it widely used?

It's getting more popular everyday with game developers. The support and documentation on the format has a lot to do with it. I know for sure that MetalGear2 and Unreal2/UT2k3 use OggVorbis. There a probably plenty of others that I don't know of too. My game will be using Ogg and Speex and maybe Mogg.
___________________________________________
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-17-2003, 05:53 PM   #16
davepermen
Senior Member
 
davepermen's Avatar
 
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
Default

jesse, just for clarification. ogg is a containerformat, vorbis is the soundformat currently so widely used and impressive. speex is another format, but gets stored in ogg files as well (well, currently spx files, but you can store them in an ogg file). same for flac, another format..


vorbis: great codec for music data, high compression ratio at still high quality
speex: great codec for speech, very high compression ratio, still understandable (and cd quality speech at very low data rates..)
flac: great codec for music data, if lossless data is needed. compresses audio data to about half the size, with no loss at all.

there are others, and not all are for audio, but the others are still in heavy development..
___________________________________________
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....
davepermen is offline   Reply With Quote
Old 07-20-2003, 03:25 PM   #17
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

Jesse, btw, TheCell has sent in a port to VC++ 6.0 for Lesson8
Dia Kharrat is offline   Reply With Quote
Old 07-29-2003, 06:33 PM   #18
chenbin_osu
New Member
 
Join Date: Jan 2003
Posts: 10
Default

I have a question regarding Lesson 8 of your valuable series.

Code:
alSourcef (source, AL_ROLLOFF_FACTOR, 0.0); alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE);

Although you briefly explained the rolloff factor, I still didn't quite understand it. Would you mind explaining further? Thank you!!!
chenbin_osu is offline   Reply With Quote
Old 07-31-2003, 03:19 AM   #19
Dia Kharrat
DevMaster Staff
 
Join Date: Jan 2003
Posts: 1,201
Default

Quote:
Originally Posted by email from newleaf
I've read your tutorial and try to re-write a ogg stream class just like yours but a little bit
different.I want to make my ogg stream loop from the beginning when they meet the end of the file.I
add some code in stream()

bool OGGStream::Stream( ALuint buffer )
{
char pcm[BUFFER_SIZE];
int size = 0;
int section;
int oggresult;
ALenum alresult ;

while(size < BUFFER_SIZE)
{
oggresult = ov_read(&oggStream, pcm + size, BUFFER_SIZE - size, 0, 2, 1, &section);

if(oggresult > 0)
size += oggresult;
else
if(oggresult < 0)
throw GetOGGErrorString(oggresult) + " while reading buffers in
KCOGGStream::Stream()" ;
else
break;
}

if(size == 0)
{
oggresult = ov_time_seek( &oggStream , 0 ) ;
if( oggresult != 0 )
throw GetOGGErrorString(oggresult) + " while looping buffers in KCOGGStream::Stream()"
;

}

alBufferData(buffer, format, pcm, size, vorbisInfo->rate);
if( ( alresult = alGetError() ) != AL_NO_ERROR )
throw GetALErrorString(alresult) + " while buffering data in OGGStream::Stream()" ;

return true;
}

What I want to to is to read buffer from the beginning when they reach the end.But when excuting,I
caught an exception "AL_INVALID_VALUE while while buffering data in OGGStream::Stream()" and it
was thrown from the bottom the this function.I have no clue why it happens

a user sent me this email, so I thought I'll post here for Jesse to reply.
Dia Kharrat is offline   Reply With Quote
Old 07-31-2003, 02:31 PM   #20
donBerto
Senior Member
 
donBerto's Avatar
 
Join Date: Jan 2003
Location: East Coast, USA
Posts: 370
Default

SWEET! thanks a lot apex!

yummy ogg player comin up!

___________________________________________
Imagine.
donBerto is offline   Reply With Quote
Old 08-01-2003, 12:29 PM   #21
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Quote:
Although you briefly explained the rolloff factor, I still didn't quite understand it. Would you mind explaining further? Thank you!!!

I planned on writting my next tutorial on attenuation so I didn't want to go off into details, but... There's an extensive attenuation calculation in OpenAL that is used to calculate volume (gain reduction) based on the listener's distance to the source. Rolloff factor is used in this calculation. In fact, rolloff judges the strength of the equation, and if this value is 0 then the equation has no effect. Essentially we turn off attenuation. The OpenAL implementation may even optimize for this, and since we usually want background music to be heard from everywhere it would be in our best interests to turn off attenuation.

Quote:
I've read your tutorial and try to re-write a ogg stream class just like yours but a little bit different.I want to make my ogg stream loop from the beginning when they meet the end of the file.I add some code in stream()

I don't see exactly what could be causing the problem, but there are some things you may want to change. I've altered the original code that I've used a bit to accomadate file seeking.

bool ogg_stream::seek(float time)
{
return (ov_time_seek(&oggStream, time) == 0);
}

Is just another function to wrap the Ogg functionality. This next part goes in the main loop.

if(!ogg.update())
{
if(ogg.seek(0))
ogg.playback();
else
throw "Cannot seek file.";
}

I've used this in my code, and it works. But I have no idea what's going on with yours (looks like it whould work to me). Was that the only modifications you've made?
___________________________________________
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 08-03-2003, 03:46 AM   #22
newleaf
New Member
 
Join Date: Jul 2003
Posts: 3
Default

Thanks for replying.I don't know what version of OpenAL you are using.I just found an OpenAL32.dll in my windows\system32\ directory, but its' size is 132 kb.Maybe some games that use OpenAL install that file for me earlier.I found that when I use this dll as the runtime library,the app just works fine.But when I use the OpenAL SDK from Creative's OpenAL SDK download page( size of the OpenAL32.dll in this package is 156 kb ),the app will raise an exception when it loops from the beginning.I've uploaded a test program and put two versions of dlls in it.Maybe you can try it with those 2 dlls.Thanks a lot.

Here is the test program:OGG test program
newleaf is offline   Reply With Quote
Old 08-03-2003, 03:49 AM   #23
newleaf
New Member
 
Join Date: Jul 2003
Posts: 3
Default

I'm sorry.The above link is wrong.Try this:OGG Test Program
newleaf is offline   Reply With Quote
Old 08-03-2003, 11:19 AM   #24
Jesse M
Member
 
Join Date: Jun 2003
Location: Airdrie, Alberta, Canada
Posts: 32
Default

Neither dll work for me, and I think I know why. In the version info part of the Creative OpenAL driver it says "For use with EMU10KX.VXD, E10KXNT.SYS OR E10KX2K.SYS", which means it's some new driver implementation I've never seen before (what kind of sound card to you have? new?)

I looked at your code and it looks like you don't check for a file error. That and the fact that the Ogg file isn't in the .rar you gave is probably why it keeps crashing. I don't happen to have any Ogg files to test with right now.

I still don't know why the DS3D wrapper version (the SDK one) won't work, because that's what I've been using for all of the tutorials so far. There must be something else that your doing differently, but I can't tell what it is from your code (other than your using GL as well, but that shouldn't affect anything).
___________________________________________
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 08-04-2003, 10:11 AM   #25
newleaf
New Member
 
Join Date: Jul 2003
Posts: 3
Unhappy

Here is the ogg file that I forget to put with the test program.

I am using Creative Sound Blaster Live Value,with DirectX9.0a,Win2000.The driver for my card is ctaud2k.sys( ver 5.12.0001.0252 ).
newleaf 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 07:36 AM.


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