Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java Sound & OpenAL / Re: issue with multiple sound sources on: 2007-11-28 06:52:26
i would, if i knew how.  I've only been working with openAL/JOAL for two weeks.  I get the concept though, although i'm hoping theres a simpler solution, as i have to get this done within a week or two...
2  Java Game APIs & Engines / Java Sound & OpenAL / issue with multiple sound sources on: 2007-11-28 01:35:44
I've been trying to work on a project, and was recently given the task of getting the sound up and running.  I can get a single file to load properly, but have been unable to get multiple files to load right:

package ceruleanHero;

import java.nio.ByteBuffer;
import net.java.games.joal.AL;
import net.java.games.joal.ALFactory;
import net.java.games.joal.util.ALut;


public class Sound
{

    static AL al;
    static final int NUM_BUFFERS = 2;
    static final int NUM_SOURCES = 2;

    static final int MUSIC1 = 0;
    static final int MUSIC2 = 1;
   
    static int[] buffers = new int[NUM_BUFFERS];
    static int[] sources = new int[NUM_SOURCES];

    static float[][] sourcePos = new float[NUM_SOURCES][2];
    static float[][] sourceVel = new float[NUM_SOURCES][2];
    static float[] listenerPos = { 0.0f, 0.0f, 0.0f };
    static float[] listenerVel = { 0.0f, 0.0f, 0.0f };
    static float[] listenerOri = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };

    static int loadALData()
    {
        //variables to load into
        int[] format = new int[1];
        int[] size = new int[1];
        ByteBuffer[] data = new ByteBuffer[1];
        int[] freq = new int[1];
        int[] loop = new int[1];
       
        // load wav data into buffers
        al.alGenBuffers(NUM_BUFFERS, buffers, 0);
        if (al.alGetError() != AL.AL_NO_ERROR)
        {
            return AL.AL_FALSE;
        }

       
        //music file 1
        ALut.alutLoadWAVFile(
            "C:/Documents and Settings/Dan/Desktop/EVERYWHERE_YOU_GO.wav",
            format,
            data,
            size,
            freq,
            loop);
        al.alBufferData(
            buffers[MUSIC1],
            format[0],
            data[0],
            size[0],
            freq[0]);
        //ALut.alutUnloadWAV(format[0], data[0], size[0], freq[0]);  Line doesn't work...
        //ERROR OCCURS NEXT LINE BELOW! 

        //music file 2
        ALut.alutLoadWAVFile(
            "C:/Documents and Settings/Dan/Desktop/ICE_MAN.wav",
            format,
            data,
            size,
            freq,
            loop);
        al.alBufferData(
            buffers[MUSIC2],
            format[0],
            data[0],
            size[0],
            freq[0]);       
           //ALut.alutUnloadWAV(format[0], data[0], size[0], freq[0]);  Again, line doesn't work...

        // bind buffers into audio sources
        al.alGenSources(NUM_SOURCES, sources, 0);

        al.alSourcei(sources[MUSIC1], AL.AL_BUFFER, buffers[MUSIC1]);
        al.alSourcef(sources[MUSIC1], AL.AL_PITCH, 1.0f);
        al.alSourcef(sources[MUSIC1], AL.AL_GAIN, 1.0f);
        al.alSourcefv(sources[MUSIC1], AL.AL_POSITION, sourcePos[MUSIC1], 0);
        al.alSourcefv(sources[MUSIC1], AL.AL_POSITION, sourceVel[MUSIC1], 0);
        al.alSourcei(sources[MUSIC1], AL.AL_LOOPING, AL.AL_TRUE);

        al.alSourcei(sources[MUSIC2], AL.AL_BUFFER, buffers[MUSIC2]);
        al.alSourcef(sources[MUSIC2], AL.AL_PITCH, 1.0f);
        al.alSourcef(sources[MUSIC2], AL.AL_GAIN, 1.0f);
        al.alSourcefv(sources[MUSIC2], AL.AL_POSITION, sourcePos[MUSIC2], 0);
        al.alSourcefv(sources[MUSIC2], AL.AL_POSITION, sourceVel[MUSIC2], 0);
        al.alSourcei(sources[MUSIC2], AL.AL_LOOPING, AL.AL_FALSE);

        // do another error check and return
        if (al.alGetError() != AL.AL_NO_ERROR)
        {
            return AL.AL_FALSE;
        }

        return AL.AL_TRUE;
    }

    static void setListenerValues()
    {
        al.alListenerfv(AL.AL_POSITION, listenerPos, 0);
        al.alListenerfv(AL.AL_VELOCITY, listenerVel, 0);
        al.alListenerfv(AL.AL_ORIENTATION, listenerOri, 0);
    }

    static void killAllData()
    {
        al.alDeleteBuffers(NUM_BUFFERS, buffers, 0);
        al.alDeleteSources(NUM_SOURCES, sources, 0);
        ALut.alutExit();
    }
   
    static void playMusic1()
    {
       al.alSourcePlay(sources[MUSIC1]);
       
       System.out.println("Sound File 1 Playing");
    }
   
    static void playMusic2()
    {
       al.alSourcePlay(sources[MUSIC2]);
       
       System.out.println("Sound File 2 Playing");
    }
   
    static void stopAllMusic()
    {
       killAllData();
       
       System.out.println("All Sounds OFF");
    }

    public static void main(String[] args)
    {
        ALut.alutInit();
        al = ALFactory.getAL();
        al.alGetError();
       
        if(loadALData() == AL.AL_FALSE)
        {
            System.exit(1);   
        }
        setListenerValues();
       
        playMusic1();
        playMusic2();
        stopAllMusic();
       
    }
}

Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
   at java.nio.Bits.reserveMemory(Bits.java:633)
   at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
   at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
   at net.java.games.joal.util.WAVLoader.readFromStream(WAVLoader.java:112)
   at net.java.games.joal.util.WAVLoader.loadFromFile(WAVLoader.java:69)
   at net.java.games.joal.util.ALut.alutLoadWAVFile(ALut.java:115)
   at ceruleanHero.Sound.loadALData(Sound.java:63)
   at ceruleanHero.Sound.main(Sound.java:144)

This error occurs when i try to define the second sound file.  I know in older versions of JOAL, the function ALut.alutUnloadWAV(format[0], data[0], size[0], freq[0]); would unload the sound data, but no longer works as is.  I'm stumped on this one, any help would be appriciated.

EDIT

Showed where error occurs and the code which doesn't work.  (Note the tutorials on the JOAL site are out of date; it took me some time getting what I have working)
Also, the error occurs at compile time (should have mentoned this before).  I'm guessing the non-working ALut.alutUnloadWAV(format[0], data[0], size[0], freq[0]);  function is the cause of this, but I have been unable to get that function working right...
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!