Author Topic: OGG Support damnit!  (Read 4510 times)

0 Members and 1 Guest are viewing this topic.

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
anyone know about Open AL?
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 
OpenAL is a cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications.


www.openal.org

 

Offline Inquisitor

We used OpenAL and Ogg decoders in Lore. It's not a trivial implementation, but, it wasn't impossible either.

If anyone wants to take a crack at it, I think the audio system could use the love...

Isn't the linux port using openAL?
No signature.

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
We would probably do better to just use OGG to play music and voices (streaming both of them) which would give better quality and shouldn't use too much memory or CPU time.  The CPU usage is a lot lower on the newer decoders now than it used to be.  The game needs fast computers anyway and we'll have the benefit of the various SSE extensions to assist.  I can't really see the benefit of having regular effects be OGG but I'm not against the idea.

Yes, the Linux and OSX ports use OpenAL.  The OpenAL code is not yet complete and is missing streaming (I'm working on it, sort of) and 3D sound.  The 3D code is there but is b0rked and I don't know enough of the sound physics to figure out exactly what I did wrong.  Both Mac and Linux versions of OpenAL have extensions to decode/play OGG files but I'm not sure about the Windows version.

Oh and Inquisitor, I don't suppose there is a Linux version of Lore around somewhere is there?  All I've seen is Mac and Windows versions and it looks like a cool game but my money only gets spent on Linux stuff these days.

 

Offline Flipside

  • əp!sd!l£
  • 212
Is there a limit to the resolution of the WAV files in-game, I've always kept them at the quality used by :v: but if you can use higher res sounds then I'm inclined to agree with Taylor.

 

Offline Inquisitor

taylor: email me, I'll hook you up with a copy of the Linux build.
No signature.

 
You are making it to hard on yourselves.  Look up something called FMOD, it reduces playing a ogg file down to a couple of lines of code.  It handles all of the decoding and playback of audio files.  It can stream them from disk so there is should be very little overhead to it.  I've implemented a mp3 jukebox in Imperial Alliance using FMOD and I haven't noticed any kind of slowdown.  The only thing that you need to distrubute is like a 150k dll.  And since this project is freeware then there is no charge for usage.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
To implement support for a sound format, functions are needed to:
  • Get info about the file AND load the file into memory. This should only require opening the file once to reduce load times
  • Convert part or all of the file into PCM format.


I'd prefer not to use something that requires a DLL, and is portable.

If I have those three functions for a given filetype it *should* be possible to add support for it.


A couple examples from the FS2 code's ACM converter code...note that all are run after the file to convert has been loaded into memory.

Music

These three functions are used to convert ADPCM music files. stream_open opens a stream, getting everything ready to convert the file.

convert converts part of the data into PCM format.

stream_close closes the stream, cleaning everything up.

Code: [Select]

//Get ready to convert
int ACM_stream_open(WAVEFORMATEX *pwfxSrc, WAVEFORMATEX *pwfxDest, void **stream, int dest_bps)

//While we have music playing, convert part of it...boy, if only this did OGG too.
int ACM_convert(void *stream, ubyte *src, int src_len, ubyte *dest, int max_dest_bytes, unsigned int *dest_len, unsigned int *src_bytes_used)

//We're done!
int ACM_stream_close(void *stream)


Sound FX and maybe voice

This function converts an entire ADPCM file into PCM format, which is later loaded into a DirectSound buffer.

Code: [Select]
// =============================================================================
// ACM_convert_ADPCM_to_PCM()
//
// Convert an ADPCM wave file to a PCM wave file using the Audio Compression Manager
//
// parameters:    *pwfxSrc   => address of WAVEFORMATEX structure describing the source wave
//                *src       => pointer to raw source wave data
//                src_len    => num bytes of source wave data
//                **dest     => pointer to pointer to dest buffer for wave data
//                              (mem is allocated in this function if *dest is NULL)
// max_dest_bytes => Maximum memory allocated to dest
//                *dest_len => returns num bytes of wave data in converted form (OUTPUT PARAMETER)
// *src_bytes_used => returns num bytes of src actually used in the conversion
// dest_bps => bits per sample that data should be uncompressed to
//
// returns:       0 => success
//               -1 => could not convert wav file
//
//
// NOTES:
// 1. Storage for the decompressed audio will be allocated in this function if *dest in NULL.
//    The caller is responsible for freeing this memory later.
//
int ACM_convert_ADPCM_to_PCM(WAVEFORMATEX *pwfxSrc, ubyte *src, int src_len, ubyte **dest, int max_dest_bytes, int *dest_len, unsigned int *src_bytes_used, unsigned short dest_bps)
-C

 

Offline Flipside

  • əp!sd!l£
  • 212
http://www.vorbis.com/download_win_1.0.1.psp

I'm not sure if it's any help, but thats the main SDK download from the Ogg Vorbis site, I've no idea whether that is what you're looking for as I have a suspicion is uses dlls :(

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
FMOD would work but it's not open source.  It's available on most platforms but it's up to the developers to add new support or fix problems.  In my case, for instance, they don't have a 64-bit Linux version available so I can't use it.  FMOD is just like DevIL but for audio and it was pretty easy to add DevIL support.  It does support WAV (PCM & ADPCM) as well as OGG but other formats can be platform specific.

We can just integrate the Vorbis code in to do the decoding.  It's free and under a BSD-like license so all we have to add is a copyright notice in the docs, no external DLLs.  If it's done correctly then it will end up looking like the ADPCM stuff (function wise) and will be cross platform and can be tuned to suit our needs.  Icculus already donated his ADPCM decoder which is cross platform, but currently only used with Linux, so FMOD would only give us OGG.  Reworking everything to support FMOD looks like a lot of work simply from a code cleanup point of view and it's not even something I can think about working on until it's 64-bit ready for Linux.

From an implementation standpoint I think that FMOD would work out pretty well but with the drawbacks (not OSS, platform support possibly sketchy, formats not truely compatible cross-platform) it could end up being a dead end at some point down the road.  I'm not against it at this point in time but I'm certainly not for it either.  Adding a few new files for OGG decoding with 3 or so external functions to convert with sounds like a better bet to me.

 
I have an advantage as I'm not/don't care about porting Imperial Alliance to other platforms.  And I'm trying to get it done in the least amount of time.  I.E. its pretty senseless for me to take the time to code in a decoder when I can just use FMOD.  Also I'm not reworking everything to use FMOD.  FMOD is only for the background music all the other sound effects are still done with the original FS2 code.  The user has the option to use the original event driven audio with sound effects or disable the event audio and use mp3(ogg) with sound effects.

 

Offline Kosh

  • A year behind what's funny
  • 210
Not to burst anyone's bubble, but shouldn't we figure out what is causing that memory usage issue and fix it before adding more features?



But, it's not really any of my business anyway.
« Last Edit: June 21, 2004, 11:09:17 pm by 1313 »
"The reason for this is that the original Fortran got so convoluted and extensive (10's of millions of lines of code) that no-one can actually figure out how it works, there's a massive project going on to decode the original Fortran and write a more modern system, but until then, the UK communication network is actually relying heavily on 35 year old Fortran that nobody understands." - Flipside

Brain I/O error
Replace and press any key

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Oops.

Incidentally, does anyone see anything wrong with these calculations?

      si->n_channels = si->ogg_info.vi->channels;
      si->sample_rate = si->ogg_info.vi->rate;
      si->bits = 16;                        //OGGs always decoded at 16 bits here
      si->n_block_align = si->n_channels * 2;
      si->avg_bytes_per_sec = si->sample_rate * si->n_block_align;
      si->size = ov_pcm_total(&si->ogg_info, -1) * si->n_block_align;
      snd->duration = fl2i(1000.0f * (si->size / (si->bits/8.0f)) / si->sample_rate);
-C

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Kosh: Assuming that you are using D3D, can you try running in OpenGL mode and see if you still have the same memory problems.  I don't see this issue but since I don't really use D3D I'm not sure if that's the reason or not.  And this happens with official 3.6 right?  Let me know what build (if not 3.6) and VPs (if other than MediaVP stuff) you have and I'll run through this tomorrow.

Quote
Originally posted by WMCoolmon
Incidentally, does anyone see anything wrong with these calculations?
ov_pcm_total() returns a 64-bit value so it's not going to fit in si->size without truncating.  You can cast it (hope not though) or have it calculated already and ensure it's less than UINT_MAX before doing math on it and assigning it to si->size.  Other than that I don't see anything obvious.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Okay, I commited my work on this to the CVS repository. Could someone see what I did wrong?

There's also a big section of code in the load_buffer() function that I was trying to use for debugging, didn't work, but I left it in in case someone else had use for it and could get it to work. You'll probably wanna delete it when OGG is all fixed.
-C

 

Offline Kosh

  • A year behind what's funny
  • 210
Taylor, I PM'd you the answer. Enough off topic for me.
"The reason for this is that the original Fortran got so convoluted and extensive (10's of millions of lines of code) that no-one can actually figure out how it works, there's a massive project going on to decode the original Fortran and write a more modern system, but until then, the UK communication network is actually relying heavily on 35 year old Fortran that nobody understands." - Flipside

Brain I/O error
Replace and press any key

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by Kosh
Taylor, I PM'd you the answer. Enough off topic for me.

Yeah, I haven't answered yet but you probably know that already.  I'm working on something and will get you a new build to test if you want.  I haven't had as much time to work on this today as I had thought but I'll PM you when I've got something. Building as I write this and if it works4me I'll let you know.