Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - CreativeMD

Pages: [1] 2
1
Other Support / Re: SoundEngine loop stream sound
« on: October 28, 2017, 04:00:26 PM »
Hey there,

it's been a while. In the meantime i have decided to try to solve this issue on my own. Forge (the tool to mod in minecraft) allows a mod to change class files while the game is loading. So i implemented the changes i showed you above myself.

If you want to you can take a look at the actual transforming code here:
https://github.com/CreativeMD/AmbientSounds/blob/1.11/src/main/java/com/creativemd/ambientsounds/soundfix/SoundFixTransformer.java
https://github.com/CreativeMD/AmbientSounds/blob/1.11/src/main/java/com/creativemd/ambientsounds/soundfix/SoundFixMethods.java

So yes, basically this solves the issue. It never occurred again (at least no so far). Again thanks for all your help and support. I hope you will eventually find some time to update the engine and to fix this issue properly.

2
Other Support / Re: SoundEngine loop stream sound
« on: July 23, 2017, 11:48:22 AM »
Ok, i have taken a look at it myself and as far as i can tell there is no synchronization for that. So here is my suggestion for implementing it:

In Source.java
Code: [Select]
public boolean removed = false;

In Library.java
Code: [Select]
    public void removeSource( String sourcename )
    {
        Source mySource = sourceMap.get( sourcename );
        if( mySource != null )
        {
            if(mySource.toStream )
                mySource.removed = true;
            else
                mySource.cleanup(); // end the source, free memory
        }
        sourceMap.remove( sourcename );
    }

In StreamThread.java - run() :
Code: [Select]
                        [...]
                        if( src == null )
                        {
                            iter.remove();
                        }
                        else if( src.removed )
                        {
                            src.cleanup();
                            iter.remove();
                        }
                        else if( src.stopped() )
                        {
                            if( !src.rawDataStream )
                                iter.remove();
                        }
                        [...]

3
Other Support / Re: SoundEngine loop stream sound
« on: July 17, 2017, 12:28:30 PM »
Any news so far?

4
Other Support / Re: SoundEngine loop stream sound
« on: June 29, 2017, 10:48:26 AM »
Finally someone could send me the complete log. Catching the exception is not enough unfortunately, since the sound engine seems to crash nonetheless:
Code: [Select]
[12:35:48] [Thread-23/INFO] [STDERR/]: [com.creativemd.ambientsounds.CodecJOrbisFixed:readBytes:626]: java.lang.NullPointerException
[12:35:48] [Thread-23/INFO] [STDERR/]: [com.creativemd.ambientsounds.CodecJOrbisFixed:readBytes:626]: at com.creativemd.ambientsounds.CodecJOrbisFixed.readBytes(CodecJOrbisFixed.java:587)
[12:35:48] [Thread-23/INFO] [STDERR/]: [com.creativemd.ambientsounds.CodecJOrbisFixed:readBytes:626]: at com.creativemd.ambientsounds.CodecJOrbisFixed.read(CodecJOrbisFixed.java:356)
[12:35:48] [Thread-23/INFO] [STDERR/]: [com.creativemd.ambientsounds.CodecJOrbisFixed:readBytes:626]: at paulscode.sound.Source.stream(Source.java:953)
[12:35:48] [Thread-23/INFO] [STDERR/]: [com.creativemd.ambientsounds.CodecJOrbisFixed:readBytes:626]: at paulscode.sound.StreamThread.run(StreamThread.java:129)
[12:35:48] [Thread-23/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.NullPointerException
[12:35:48] [Thread-23/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at paulscode.sound.Source.stream(Source.java:962)
[12:35:48] [Thread-23/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at paulscode.sound.StreamThread.run(StreamThread.java:129)

This is the code causing the second exception:
Code: [Select]
buffer = codec.read();
if( buffer != null )
{
   if( buffer.audioData != null )
       channel.queueBuffer( buffer.audioData );
   buffer.cleanup();
    buffer = null;
   return true;
}
else if( codec.endOfStream() ) //<-- codec seems to be null

It looks like the method cleanup() is called while the sound is still streaming. It is the only method which sets the "codec" to null.

With that knowledge in mind i found some fishy looking code in my mod:
Code: [Select]
        if(!system.playing(sound.systemName))
        {
        if(sound.hasBeenAdded)
        {
            if(sound.repeat && AmbientSounds.debugging)
            {
            System.out.println("Unexpected ending sound " + sound.getSoundLocation() + " " + sound.systemName);
            }
            sound.playing = false;
            if(library != null)
            library.removeSource(sound.systemName); //<-- not synchronized
            else
            System.out.println("No library found. Something went wrong!");
                iterator.remove();
        }
            }else{
            sound.hasBeenAdded = true;
            }

I thought it would be necessary to remove the source after is has been played. This call is not synchronized so potentially it could be the cause of the issue, but i doubt it since it only remove a source which is not playing anymore and the issue is also there if my mod is not installed. I will do some testing nonetheless ...

Maybe you have another idea? It looks like something is cleaning up the source from another thread.

5
Other Support / Re: SoundEngine loop stream sound
« on: June 21, 2017, 02:53:48 AM »
The newest version of JOrbis is 0.0.17 and from 2008, i'm pretty sure you are already using the newest version.

The crash itself takes place here:
Code: [Select]
public int packetout(Packet op){

    /* The last part of decode. We have the stream broken into packet
       segments.  Now we need to group them into packets (or return the
       out of sync markers) */

    int ptr=lacing_returned;

    if(lacing_packet<=ptr){
      return (0);
    }

    if((lacing_vals[ptr]&0x400)!=0){ //<- this line is causing the exception
      /* We lost sync here; let the app know */
      lacing_returned++;

      /* we need to tell the codec there's a gap; it might need to
         handle previous packet dependencies. */
      packetno++;
      return (-1);
    }

    /* Gather the whole packet. We'll have no holes or a partial packet */
    {
      int size=lacing_vals[ptr]&0xff;
      int bytes=0;

      op.packet_base=body_data;
      op.packet=body_returned;
      op.e_o_s=lacing_vals[ptr]&0x200; /* last packet of the stream? */
      op.b_o_s=lacing_vals[ptr]&0x100; /* first packet of the stream? */
      bytes+=size;

      while(size==255){
        int val=lacing_vals[++ptr];
        size=val&0xff;
        if((val&0x200)!=0)
          op.e_o_s=0x200;
        bytes+=size;
      }

      op.packetno=packetno;
      op.granulepos=granule_vals[ptr];
      op.bytes=bytes;

      body_returned+=bytes;

      lacing_returned=ptr+1;
    }
    packetno++;
    return (1);
  }

I think catching the exception is the best way to do it right know. Future tests will tell if that fixes the crash of the sound engine or not.

As i said earlier, my guess it's a threading issue. The codec will cleanup everything, but still tries to continue to stream. (maybe once he runs out of streaming channels).

Thanks again for your help, if you ever run across a solution for this problem just let me know :D . I really appreciate your work and your spent time. Have a good day.

EDIT
Am I allowed to upload a modified version of your CodecJOrbis on github (open source)? I would also mark all changes i made.

6
Other Support / Re: SoundEngine loop stream sound
« on: June 19, 2017, 10:07:28 AM »
Hey there, I'm sorry to bother you again, but unfortunately this random crash (which i mentioned earlier) has become quiet annoying.

Just as a reminder I'm talking about this one:
Code: [Select]
[17:36:04] [Thread-11/INFO]: [STDERR]: java.lang.NullPointerException
[17:36:04] [Thread-11/INFO]: [STDERR]: at com.jcraft.jogg.StreamState.packetout(StreamState.java:186)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.codecs.CodecJOrbis.readBytes(CodecJOrbis.java:575)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.codecs.CodecJOrbis.read(CodecJOrbis.java:354)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.Source.stream(Source.java:953)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.StreamThread.run(StreamThread.java:129)

It causes the sound engine to crash from time to time, so all sounds will be stopped. The sound engine has to be restarted in order to make it working again.

Other mod authors are aware of this issue too, but none of us knows how to fix it. My guess is, that this is a weird thread issue, which is rather unlikely to occur, but will eventually happen if you play the game long enough. Of course the more streaming sounds will be played the more likely it is to happen.

Maybe you can help us out here? Do you have an idea what could cause this crash and how to fix it?

If not, I'm searching for a proper way to catch the exception and try to end the stream properly without causing the engine to crash as well, but unfortunately it does not work out, at least as far as i can tell, since it's rather difficult to reproduce this crash:
Code: [Select]
private byte[] readBytes()
    {
        if( !initialized( GET, XXX ) )
            return null;

        if( endOfStream( GET, XXX ) )
            return null;

        if( convertedBuffer == null )
            convertedBuffer = new byte[ convertedBufferSize ];
        byte[] returnBuffer = null;

        float[][] pcmf;
        int samples, bout, ptr, mono, val, i, j;

        switch( joggSyncState.pageout( joggPage ) )
        {
            case( 0 ):
            case( -1 ):
                break;
            default:
            {
                joggStreamState.pagein( joggPage );
                if( joggPage.granulepos() == 0 )
                {
                    endOfStream( SET, true );
                    return null;
                }
               
                try{
                processPackets: while( true )
                {
                    switch( joggStreamState.packetout( joggPacket ) )
                    {
                        case( 0 ):
                            break processPackets;
                        case( -1 ):
                            break;
                        default:
                        {
                            if( jorbisBlock.synthesis( joggPacket ) == 0 )
                                jorbisDspState.synthesis_blockin( jorbisBlock );

                            while( ( samples=jorbisDspState.synthesis_pcmout(
                                                     pcmInfo, pcmIndex ) ) > 0 )
                            {
                                pcmf = pcmInfo[0];
                                bout = ( samples < convertedBufferSize ?
                                                samples : convertedBufferSize );
                                for( i = 0; i < jorbisInfo.channels; i++ )
                                {
                                    ptr = i * 2;
                                    mono = pcmIndex[i];
                                    for( j = 0; j < bout; j++ )
                                    {
                                        val = (int) ( pcmf[i][mono + j] *
                                                                       32767. );
                                        if( val > 32767 )
                                            val = 32767;
                                        if( val < -32768 )
                                            val = -32768;
                                        if( val < 0 )
                                            val = val | 0x8000;
                                        convertedBuffer[ptr] = (byte) (val);
                                        convertedBuffer[ptr+1] =
                                                               (byte) (val>>>8);
                                        ptr += 2 * (jorbisInfo.channels);
                                    }
                                }
                                jorbisDspState.synthesis_read( bout );

                                returnBuffer = appendByteArrays( returnBuffer,
                                               convertedBuffer,
                                               2 * jorbisInfo.channels * bout );
                            }
                        }
                    }
                }
               
                }catch(Exception e){
                e.printStackTrace();
                endOfStream( SET, true );
                return null;
                }

                if( joggPage.eos() != 0 )
                    endOfStream( SET, true );
            }
        }

Is "endOfStream( SET, true );" a proper way of stopping the sound or will it cause future issues?

7
Other Support / Re: SoundEngine loop stream sound
« on: May 24, 2017, 05:32:43 AM »
Yes!!! Thank you sooo much. It seems to be fixed, everything works just fine: https://youtu.be/Z7GmncqhGpI

Now there is only this random crash, but i don't know if there is a way to fix it.

Again thank you so much for all your spent time and effort! :D You really helped me, i have been trying to solve this issue for weeks. Now i can finally release! I wish you all the best for your future projects. Thank you.

8
Other Support / Re: SoundEngine loop stream sound
« on: May 23, 2017, 11:11:41 AM »
Ok ... it looks like things get a little bit more complicated. It might be a good idea if i tell you exactly what is happening and show you my code.

So AmbientSounds (the mod i'm working on) should play sounds which should fit to the current area the player is. An area has about 3 sounds which play contentiously and a few others which play from time to time.

I recorded two videos, which should show you what is going. I'm trying to bring the system to it's limits by switching the areas rather quickly, through that way more sounds will be played simultaneously. The console (in eclipse) shows which sounds are currently playing.

In this video a random crash of the sound engine occurs:
https://www.youtube.com/watch?v=v9Nfe8RYxeA

Code: [Select]
[17:36:04] [Thread-11/INFO]: [STDERR]: java.lang.NullPointerException
[17:36:04] [Thread-11/INFO]: [STDERR]: at com.jcraft.jogg.StreamState.packetout(StreamState.java:186)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.codecs.CodecJOrbis.readBytes(CodecJOrbis.java:575)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.codecs.CodecJOrbis.read(CodecJOrbis.java:354)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.Source.stream(Source.java:953)
[17:36:04] [Thread-11/INFO]: [STDERR]: at paulscode.sound.StreamThread.run(StreamThread.java:129)

The second video shows the problem i was talking about before: https://www.youtube.com/watch?v=9TmNl-es50k at around 0:40 the engine unexpectedly ends some of the sounds.

Code: [Select]
[17:40:56] [Client thread/INFO]: [STDOUT]: ================Playing================
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.bird.bird-jungle-night, 0.023/0.0
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.cricket.cricket-jungle-night, 0.023/0.0
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.cricket.cricket-forest-night, 0.023/0.0
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.cricket.cricket-warm-night, 0.5029971/0.0
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.cricket.cricket, 0.0019999743/0.0
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.wolf.wolf, 0.057999957/0.0 pause: 136
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.seagull.seagull, 0.10300003/0.75 pause: 12
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:animals.seagull.seagull-long, 0.0/0.75 pause: 737
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:water.beach, 0.09900002/0.4
[17:40:56] [Client thread/INFO]: [STDOUT]: ambientsounds:wind.light-wind, 0.09900002/1.0
[17:40:56] [Client thread/INFO]: [STDOUT]: Unexpected ending sound ambientsounds:animals.cricket.cricket af7699ba-c5c7-4bf5-ae2d-298220803624
[17:40:56] [Client thread/INFO]: [STDOUT]: Unexpected ending sound ambientsounds:animals.cricket.cricket-jungle-night 5806f294-3cc4-43ac-8702-73a543136fd1

This seems to persist until those sounds fade out (since i left the area).

The code i'm currently using is a bit chaotic. I tried a lot of things to found out if a sound has stopped or not:
https://github.com/CreativeMD/AmbientSounds/blob/1.11/src/main/java/com/creativemd/ambientsounds/AmbientSoundEngine.java#L92. I hope i could explain my situation, so you can understand it.

Not having enough streaming channels might be the issue here, is there a way to increase it?



9
Other Support / Re: SoundEngine loop stream sound
« on: May 22, 2017, 10:18:12 AM »
Hey,

unfortunately there seem to be some more issues with the sound engine itself. Since the minecraft implementation has lot of bugs, i decided to write my own, but as i said before ran into some problems.

There seems to be one big issue and that is to tell whether a sound is playing or not. As you told me already, playing() will not return true immediately, which isn't that big kind of a problem. I could solve it by waiting until playing() is true for the first time.

To my concerns that did not fix it
- sometimes a sound does not event start to play. This occurs randomly (no idea why)
- playing() returns false although the sound is still playing (somehow depends on how many sounds are playing. It's difficult to find a pattern, but sometimes all the sounds return false for 1-4 seconds, eventually the seems to recover from that). I could record a video to demonstrate you what is happening

I also tried to use library directly (get the source), but that does not change anything. I tested it for hours tried to find a solution, but sadly without any success.

Maybe you have an idea? What i would need is a 100% safe method which tells me if a sound is playing or not, everything else works just fine.

10
Other Support / Re: SoundEngine loop stream sound
« on: May 17, 2017, 04:38:39 AM »
No, i was not talking about your sound engine. I mean your engine needs to be thread safe so it's a good idea to use a command queue for that.

It's about the SoundManager class:
Minecraft has an interface (ISound) for all sounds. It contains the location, pitch, volume etc. The SoundManager connects the minecraft way of using sounds with your sound engine. Once a sound will be played, minecraft generates a uuid for it and places it together with the ISound object in a hashmap (Map<String,ISound>). Through this way they can link a given uuid to a sound, but most commonly you would need it the other way round, that's why they are using a reversed hashmap (Map<ISound, string>) a so called HashBiMap (library from google). Those two hashmaps should be equal, but reversed. Sadly this is not the cause, since they will not be synchronized immediately, which causes a tone amount of issues.

I'm currently rewriting my mod AmbientSounds (https://minecraft.curseforge.com/projects/ambientsounds), which adds some more atmospheric sounds to minecraft. Theoretically it should play a sound, loop it until it will be stopped at some point, but that does not really work since minecraft acts quite strange (stopping sounds for no reason, continues to play the sound from the start every 2 seconds). :(

So all i have to do know, is to create my own connector to your sound engine and everything should work fine :D

11
Other Support / Re: SoundEngine loop stream sound
« on: May 16, 2017, 04:59:07 PM »
Sounds great :D

Unfortunately there are lot of issue with Minecraft's implementation. They use com.google.common.collect.HashBiMap to store all playing sound. Basically those are two HashMap connected together, one for finding the sound for a given source-name and one to get the source-name from a sound (reversed). Theoretically those should be equal, but eventually i found out that those HashMap's are not synchronized directly, but over time. So there are "threading" issues without using threads.

Example: If you play a sound and check if it is playing, it will return false for about 1-2 secs (depends on FPS) until the second hashmap will be updated. No idea who wrote that code ... but that person didn't know what those HashBiMap are used for.

12
Other Support / Re: SoundEngine loop stream sound
« on: May 15, 2017, 06:56:50 AM »
Ok, it looks like it's a weird Minecraft issue. Thanks for your help anyway. Wish you all the best.

13
Other Support / Re: SoundEngine loop stream sound
« on: May 09, 2017, 07:57:00 AM »
Could find anything out?

14
Other Support / Re: SoundEngine loop stream sound
« on: May 03, 2017, 04:30:07 PM »
Found it:
Code: [Select]
SoundSystemConfig.addLibrary(LibraryLWJGLOpenAL.class);
SoundSystemConfig.setCodec("ogg", CodecJOrbis.class);

Pages: [1] 2