Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Can't create sound second time?  (Read 26137 times)
0 Members and 1 Guest are viewing this topic.
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Posted 2014-12-18 02:41:25 »

Here is a bit of the source:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public class Sound extends Point {
    ...
   public Sound(String name) {
        ...
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffers.get(name));
      alDeleteSources(source);
      source = alGenSources();
      alSourcei(source, AL_BUFFER, buffers.get(name));
     
      setDistanceModel(INVERSE);
      setDirection(0);
     
      int error = alGetError();
      if (error != AL_NO_ERROR) {
         throw new RGException(RGException.SOUND, alGetString(error));
      }
   }
    ...
   public void destroy() {
      alDeleteSources(source);
   }


But when I create a sound with the file "laser.wav", then let it play (let it go, let it go), then destroy it, then create another sound with "laser.wav"... It throws this error:

1  
Exception in thread "main" com.redmintie.redgame.core.RGException: [SOUND] Invalid Name


I had a look into it and this error is caused by:
1  
alSourcei(source, AL_BUFFER, buffers.get(name));


Is OpenAL deleting the buffer? Does anybody know what is happening? Sry for so much code... I tried recreating it in a simpler version but I wasn't able to... also, this is my first time trying OpenAL (it is amazing btw)

Thx in advance...

EDIT: just found out that you don't actually have to let the sound play out... even if you don't let it play out or dont event start it playing at all... It will still create the same error

Is it sad that I still get a fright when the computer beeps at me...
Offline philfrei
« Reply #1 - Posted 2014-12-18 23:02:35 »

I haven't worked with OpenAL, but I am curious about one aspect of your question, and it might lead to a solution.

With Clip (in javax.sound.sampled), a common newbie practice is to reload the sound anew from the source file with each playback. They don't realize that the Clip was designed to only be loaded once, and that there are methods to reposition the "playback head" of the sound back to the start, and replay it.

Is this possible with the sounds you are trying to play? It seems really inefficient to me to have to destroy and reload a sound for the simple task of playing it more than once. Chances are, once it is in memory, there is a way to reset it to the beginning and restart.

music and music apps: http://adonax.com
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #2 - Posted 2014-12-18 23:54:47 »

Interesting... But the source doesn't contain all the data... The data is cached (as an openAL buffer) and put into each source made...

but maybe after playing, I might have to rewind the buffer?

If that doesn't work I can just have it cached as a format, ByteBuffer data, and frequency... Then load it into a new buffer and add that buffer to the source...

Is it sad that I still get a fright when the computer beeps at me...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #3 - Posted 2014-12-19 00:22:14 »

Nope... not working... Just found out that "Invalid Name" is coming from:
1  
source = alGenSources()


What would be the "Invalid Name"? It can't be the limit... I only create 2 sources... What is happening here?

Is it sad that I still get a fright when the computer beeps at me...
Offline matanui159

JGO Coder


Medals: 11
Projects: 1
Exp: 10-12 months


Aww... So cute...


« Reply #4 - Posted 2014-12-19 04:11:53 »

FINALLY FIGURED IT OUT!!!

It had nothing to do with OpenAL... for some reason my entities where still updating for one last frame after they got removed...
So an error was created but because I only check for errors when creating the sound, the error popped up there...

Now I have to figure out why my entities are updating...

Is it sad that I still get a fright when the computer beeps at me...
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (150 views)
2017-09-30 02:57:34

theagentd (225 views)
2017-09-26 18:23:31

cybrmynd (306 views)
2017-08-02 12:28:51

cybrmynd (291 views)
2017-08-02 12:19:43

cybrmynd (302 views)
2017-08-02 12:18:09

Sralse (293 views)
2017-07-25 17:13:48

Archive (980 views)
2017-04-27 17:45:51

buddyBro (1108 views)
2017-04-05 03:38:00

CopyableCougar4 (1685 views)
2017-03-24 15:39:42

theagentd (1434 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!