Loading wavs with FSound.FSOUND_Sample_Load

I can’t seem to get fmod to take whatever ByteBuffer I send it when I call FSound.FSOUND_Sample_Load(int, ByteBuffer, int, int, int). The result is always a null pointer exception which I’m assuming means the buffer wasn’t correct and therefore means the Sample’s memory location is invalid.

Anyone have a tried and true method to break down a wav into a ByteBuffer? I’ve seen various examples on how to create an acceptable wav ByteBuffer for OpenAL, however, none of those work (I’m assuming that this is beacuse OpenAL and FMOD require the buffer to be created differently)

Also, is there any reason why FMUSIC_MODULE and FSOUND_STREAM types can be loaded by file whereas an FSOUND_SAMPLE needs a buffer? Perhaps FSOUND_SAMPLE isn’t supported yet?

Thanks in advance!

Edit: I found a way around the problem by loading the wav first as a FSOUND_STREAM. I then use FSound.FSOUND_Stream_GetSample(stream) to convert the stream into a sample. It’s a hack, however, it works until a true solution is found.

Edit2: Ok, well, Fsound.FSOUND_STream_GetSample(stream) doesn’t work like I thought. Apparantly it only gets the header of the stream, which works fine if the sound I want to play is very short. If the sample is long, i’m back to the drawing board.

Edit3: OK! It’s another hack but it sorta works. I’m a musician by trade so I went oldschool and used a tracker to hold a few samples. Using FMusic.FMUSIC_GetSample(module, sample#) I was able to rip the samples from my own modules. Again, this works but it’s very much a hack. However, there is some novelty to having all sounds loaded and stored in one file.

The FMOD port is still … preview ::slight_smile: There are known bugs and there are unimplemented methods. I would love to get a copy of your FMOD stuff, since most of what I have is really basic.

[quote]Also, is there any reason why FMUSIC_MODULE and FSOUND_STREAM types can be loaded by file whereas an FSOUND_SAMPLE needs a buffer? Perhaps FSOUND_SAMPLE isn’t supported yet?
[/quote]
There should be a ‘FSOUND_Sample_Load(int index, String name, int inputmode, int offset, int length)’ in there…
However - you are approaching the field of unimplemented methods :slight_smile: - I started on FMUSIC which is 100% complete - then I ventured on to FSOUND which has 80% implemented - I take a stab at the remaining every once in a while - Callback for instance is incomplete in FSOUND.
If possible, you might want to look at the java/native code to check against expected result - and if possible implement/fix stuff and send it to me, I’ll commit it in CVS then :wink:

So the great Matzon wants to see my FMOD stuff huh? I’m honored. I really love LWJGL, I just wish I had more knowledge about things to help out with it’s creation.

I apologize, I didn’t even think to poke aroud into the native code. I knew from the FMOD api that there was a ‘FSOUND_Sample_Load(int index, String name, int inputmode, int offset, int length)’ but I figured that you intentionally only implemented the ByteBuffer variety to maintain consistency with how GL11 loads textures with buffers.

Anyway, in the native I found that ‘FSOUND_Sample_Load(int, ByteBuffer, int, int, int)’ wasn’t implemented- it’s supposed to throw a new FMODException saying so, however, my implementation in Java wasn’t setup to catch errors.

I edited the String version of Sample_Load. I’m going out on a limb here, hopefully it is what’s needed.


JNIEXPORT jlong JNICALL Java_org_lwjgl_fmod_FSound_nFSOUND_1Sample_1Load__ILjava_lang_String_2III(JNIEnv * env, jclass clazz, jint index, jstring name, jint inputmode, jint offset, jint length) {
      const char* filename = (const char*) (env->GetStringUTFChars(name, 0));

      return (jlong) fmod->FSOUND_Sample_Load(index, filename, inputmode, offset, length);
}

As far as my FMod stuff goes, I don’t really think there’s anything special. My stuff is ‘really basic’ too. The only things that are high end are the actual sound files- since I composed them myself ;D ;D ;D

Here’s what I use to get a sample out of a module:


Vector musicModules;      //  Active modules.
Vector sampleRef;      //  Filenames of all valid samples- needed because modules mess with filenames.

...

if(ref.endsWith(".wav")){
      for(int i = 0; i < musicModules.size(); i++){
            FMusicModule module = (FMusicModule)musicModules.get(i);
                        
            for(int s = 0; s < FMusic.FMUSIC_GetNumSamples(module); s++){
                  FSoundSample sample = FMusic.FMUSIC_GetSample(module, s);
                  String sampleName = FSound.FSOUND_Sample_GetName(sample) + ".wav";
                              
                  if(ref.compareTo(sampleName) == 0){
                        soundSamples.add(sample);
                        sampleRef.add(ref);
                  }                                          
            }
      }                  
}

It’s extremely specific to my scenario. Depending on what type of module is used (s3m, it, mod) and the program used to save it, the sample’s filename can become corrupt, mangled, or the extention can be dropped. Additionally, .it allows other modules to be used as samples, so there can be huge problems if FMOD is expecting a ‘FSOUND_SAMPLE’ when instead it gets a ‘FMUSIC_MODULE’. I wouldn’t expect it to be such a big deal since the problem is VERY specific. Once 'FSOUND_SAMPLE’s can be loaded without the need to rip them from modules, this problem would probably dissapear- unless you’re making some sort of a winamp clone.

well i still cant seem to load the lwjgl fmod dll. just get
a linking error even if i use the:


System.loadLibrary("lwjgl-fmod");

and yep i have the lastest fmod installed. if i can get it
going i can port over my fmod stuff- may help some :slight_smile:

heres a snip of the error:


An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x7BC2E8B
Function=Java_org_lwjgl_fmod_FSound_FSOUND_1SetOutput+0xB
Library=C:\Documents and Settings\Administrator\jbproject\Xith3DPart4\lwjgl-fmod.dll

Current Java thread:
      at org.lwjgl.fmod.FSound.FSOUND_SetOutput(Native Method)

and heres my call where it goes pop


FSound.FSOUND_SetOutput(FSound.FSOUND_OUTPUT_DSOUND);

ok after some messing around- and me being a muppet.
i spoted the problem and all is working. i needed to
include the lwjgl.jar also.

anyways that aside any news on implementing:


FSound.FSOUND_3D_Listener_SetAttributes():

i just get an error saying:
org.lwjgl.fmod.FMODException: missing implementation.
sort of an importent one for the 3D jazz dudes. if u like i
can write a little ‘how to do 3d in lwjgl java fmod?’. will
need that call to start all the fun that can be had there.

the call in java is used like this:


  FloatBuffer cloc = FloatBuffer.wrap(new float[] {0f, 0f, 0f});
  FloatBuffer cval = FloatBuffer.wrap(new float[] {0f, 0f, 0f});

  public void setListenerLocation(float x, float y, float z, Vector3f[] rightupout) {
    cloc.put(0, x); cloc.put(1, y); cloc.put(2, z);
    FSound.FSOUND_3D_Listener_SetAttributes(cloc, cval,
                                                rightupout[2].x, rightupout[2].y, rightupout[2].z,
                                                rightupout[1].x, rightupout[1].y, rightupout[1].z);
    FSound.FSOUND_Update();
  }

all the playing of audio files seem to work fine, along
with streams. just missing afew gems. i would like
to play with DSP next. but lets get the 3d rocking.