View Issue Details

IDProjectCategoryView StatusLast Update
0000015Industrial-Craft²general / otherpublic2012-11-29 22:42
ReporterDoctorBeard Assigned ToPlayer  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0000015: No Sound
DescriptionAll sound in the game is missing except for the interrupt sound of machines.
Steps To ReproduceJust use anything that would in any way create sound. To hear the only working sound, just put something in a macerator and immediately take it back out again.
TagsNo tags attached.
Minecraft Version

Relationships

has duplicate 0000079 closedRichardG The Console spams an error msg that I was directed to IC2 forums to as s source. 

Activities

TheBard

2012-10-31 21:20

reporter   ~0000013

Possible fix for this was documented here:
http://forum.industrial-craft.net/index.php?page=Thread&postID=83204#post83204

From user aidancbrady:
AudioManager is for some reason not being ticked anymore inside of IC2.

Code you need:
Platform.profilerEndStartSection("AudioManager");
AudioManager.onTick();

Put that inside of tickStart() between EnergyNet.onTick(world) and platform.profilerEndStartSection("Networking");

DoctorBeard

2012-11-03 03:15

reporter   ~0000059

Would just like to point out that the proposed fix did not work when I tried it in a decompiled version of 1.108.59. Could of course have been due to a multitude of other reasons what with having been decompiled.

RawCode

2012-11-03 03:20

reporter   ~0000063

looks like devs force disabled sounds atlast.

matjam

2012-11-05 13:09

reporter   ~0000084

So, I'm currently messing around with MCF, playing with an idea for an addon. Decided to take a look at this. I placed 20 geothermal generators down, no audio played. I added some println() into the code to see that the correct code is being called to initialize AudioManagerClient (it is) and when I load the world, I get a little audio played, and it sometimes crashes, if you're lucky:

java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
    at java.util.HashMap$ValueIterator.next(Unknown Source)
    at ic2.common.AudioManagerClient.onTick(AudioManagerClient.java:107)
    at ic2.common.IC2.tickStart(IC2.java:1457)
    at cpw.mods.fml.common.SingleIntervalHandler.tickStart(SingleIntervalHandler.java:16)
    at cpw.mods.fml.common.FMLCommonHandler.tickStart(FMLCommonHandler.java:116)
    at cpw.mods.fml.common.FMLCommonHandler.onPreWorldTick(FMLCommonHandler.java:292)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:652)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:590)
    at net.minecraft.src.IntegratedServer.tick(IntegratedServer.java:110)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:497)
    at net.minecraft.src.ThreadMinecraftServer.run(ThreadMinecraftServer.java:17)

line 107 in AudioManagerClient in my decompiled source is

                while (var4.hasNext())
                {
-----> List var10 = (List)var4.next();
                    Iterator var6 = var10.iterator();

Adding code to print the current thread ID stops sound from working, but seems to add enough delay to make this particular race condition rare. There appears to be two separate threads modifying the HashMap at the same time.

Using a ConcurrentHashMap fixes the crash; audio is still broken.

I think there are two bugs here; I'm trying to narrow it down but my knowledge of the APIs are limited.

matjam

2012-11-06 09:29

reporter   ~0000096

okay, so AudioManager.onTick() is being called from IC2.java in the TickType.WORLD section (so, server side part) and PlatformClient.java. That's the two threads trying to do stuff to the AudioManager.

I'm now reliably getting a tiny blip of sound every time I start the world. so just need to narrow down whats going on. I suspect an errant cull().

matjam

2012-11-06 09:59

reporter   ~0000098

Aha, so narrowed it down to somewhere in AudioSourceClient.updateVolume(); this part of code calculates what volume something should be based on your distance to it.

Multiple bugs here;

in AudioManagerClient.initialize(), need to add

        defaultVolume = 1.2F;
        fadingDistance = 16.0F;

and comment out the

    //public float defaultVolume = 1.2F;
    //public float fadingDistance = 16.0F;

at the top.

This gets sound to play! Because, in updateVolume() there is this:

            float var2 = AudioManager.fadingDistance * Math.max(this.configuredVolume, 1.0F);

Which is referencing the AudioManager static fields fadingDistance and configuredVolume, which are in that class, 0.0F. I guess this happened as a result of moving from 1.2.5 to 1.3.2+.

Next bug; the calculation of the volume seems not quite right. Volume is maximum when close; and continues to be high until you reach the fadingDistance at which point it drops off a cliff, and then the volume is set to 0.0 and the audio is stopped. And it never gets started again :)

Now I've kind of got this narrowed down, I'll try and come up with a comprehensive patch! Unless a real dev is working on it, and I'm just duplicating effort.

matjam

2012-11-06 11:06

reporter   ~0000099

Bug #1: AudioManager.onTick() should not be called in IC2 class.
Bug #2: AudioManagerClient.updateVolume() is using local fields that are set to 0.0F, which cause all sounds to be muted.
Bug #3: Implementation of the volume/distance calculation is not working as intended, and needs rework.

This seems to kinda work. Not sure what the original method was trying to do; but this might be ok as a stopgap. It's a "linear" type function, but the volume difference between max and min doesn't feel linear, so I think someone needs to spend some time really tweaking this one. If you want, I am happy to volunteer.

    public void updateVolume(EntityPlayer player)
    {
        float max_volume = IC2.audioManager.getMasterVolume();
        float max_distance = 16.0F;
        float distance = 0.0F;
        if (!valid) {
            realVolume = 0.0F;
            return;
        }
        
        if (this.position.world == player.worldObj)
        {
            float xdist = this.position.x - (float) player.posX;
            float ydist = this.position.y - (float) player.posY;
            float zdist = this.position.z - (float) player.posZ;
            distance = (float) Math.sqrt((double)(xdist * xdist + ydist * ydist + zdist * zdist));
        }
        else
        {
            distance = Float.POSITIVE_INFINITY;
        }
        
        realVolume = Math.max(0.0F, ((max_distance - distance) / max_distance) * configuredVolume);
        
        soundSystem.setVolume(sourceName, realVolume);
    }

Hope this helps!

I have working sounds now ;)

DoctorBeard

2012-11-06 11:27

reporter   ~0000100

Can confirm this working. I recompiled the source with the fixes and replaced the AudioManagerClient.class and AudioSourceClient.class files in the official jar with the fixed ones and sound works fine now. Even if distance calculation for sounds is off (which I didn't notice) it's a million times better than broken sounds for three versions in a row.

Thanks matjam for this awesome fix.

matjam

2012-11-06 12:03

reporter   ~0000102

just note you may get a ConcurrentModificationException bomb if you don't fix the IC2 class as well. I was able to cause that to happen with >20 machines in a room, on world load.

DoctorBeard

2012-11-06 12:53

reporter   ~0000106

Ah yes, you're right about that. I was using the 59 build of the beta to test it, since that's the one I currently have decompiled and that one doesn't have audioManager.onTick() in the IC2 class.

I assume the latest build (71?) implemented the first suggested fix then (and apparently without testing it).

As a sidenote, I keep seeing people saying "AudioManager.onTick()", but AudioManager.onTick is not a static function. It currently calls audioManager.onTick() on the local audioManager instance.

aidancbrady

2012-11-06 15:53

reporter   ~0000108

simple volume updating code pulled directly from my own mod:

        double distanceVolume = entityplayer.getDistanceSq(xCoord, yCoord, zCoord)*0.01;
        
        volume = (float)Math.max(1.0F-distanceVolume, 0);

        soundSystem.setVolume(identifier, volume);

really couldn't be easier than that.

there's also really no need to be ticking audioManager itself, would be more efficient to just tick the audioSources themselves.

-aidancbrady

DoctorBeard

2012-11-06 16:31

reporter   ~0000112

Woah there. You already had two tries at this bug, and your second one even made the problem worse (as YOU were the one who suggested we tick the AudioManager). You should just stay as far away from this bug as possible, mate.

aidancbrady

2012-11-06 16:38

reporter   ~0000113

I'm afraid I don't see where you're coming from, DoctorBeard.

the whole point of this bug tracker is for people who have experience to be able to pitch in their ideas of how to solve IC2's various bugs. and to say my idea made it worse...that is not exactly true. it's apparent that as of build 71, someone has removed the few lines of code that tick the audio manager inside of IC2. I didn't realize until a few days ago that audioManager WAS being ticked inside of PlatformClient.

I'd also like to say that the code matjam currently is using to update sound CAN be shortened by entityplayer.getDistanceSq, this does all the math for you.

DoctorBeard

2012-11-06 18:34

reporter   ~0000115

Nah, man. If they really wanted our input on how to actually FIX their bugs they'd give us the source, not makes us go through the hassle of decompiling it.

matjam

2012-11-06 22:01

reporter   ~0000118

Last edited: 2012-11-07 05:02

Aidan, the AudioManager onTick method is intended to be called because it does a bunch of things, not just setting volume for audio sources. I think they way it's been designed is so that they don't need to put any audio code in the base classes for the various entities.

I didn't know about getDistanceSq; that's a handy method. Using that would be appropriate, along with the computation to keep the volume of the source under the minecraft main mixer volume. Otherwise even if you mute minecraft, IC2 sounds will play :) Learned that while I was messing around.

On the way to work this morning, I realised I wasn't scaling the output properly based on the master volume. This method does that:

    public void updateVolume(EntityPlayer player)
    {
        realVolume = 0.0F;

        if (!valid) {
            return;
        }
        
        float maxVolume = 1.0F;
        float masterVolume = IC2.audioManager.getMasterVolume();
        float scaledVolume = configuredVolume / (maxVolume / masterVolume);
        float maxDistance = 12.0F;
        float distance = (float) player.getDistanceSq(this.position.x, this.position.y, this.position.z) * 0.01F;

        realVolume = (float) Math.max(0.0F, ((maxDistance - distance) / maxDistance) * scaledVolume);
        
        soundSystem.setVolume(sourceName, realVolume);
    }

Remember, the updateVolume method needs to

a) Respect the globally configured minecraft master volume.
b) Respect the configured volume for the Entity.
c) Reduce the volume as the player moves further away.

I don't think you can make it easier than that, and keep the code readable.

I think the original method was doing some fancy stuff, such as occlusion. Also, looking at the PaulsCode API there are a bunch of methods in there that would probably help with providing a distance based volume scaling method.

I think there is significant work there just to clean up the audio code. For example, I think it would be a good idea to not call updateVolume if the player hasn't moved. If you're standing on the spot, spinning around, the realVolume doesn't need to change - there is other code that handles all of the stereo stuff so that you hear it from the closest ear, etc.

I've offered my time to Alblaka. Hope he's willing :) But I understand why he would be reluctant to open his source code to an unknown person. I quite like fixing bugs. It's fun. I'm a bit weird, aren't I.

aidancbrady

2012-11-11 06:31

reporter   ~0000184

Just tested your fix and can confirm this works. Just a matter of RichardG adding the required code.

RichardG

2012-11-17 15:06

administrator   ~0000229

Sounds are force-disabled in the 1.4.4 version.

onTick is being called, but that still didn't fix the sounds.

DoctorBeard

2012-11-18 17:10

reporter   ~0000249

What the shit Richard? It's says RIGHT HERE IN THE NOTES how to fix the sound bug. Just follow matjams last couple of notes and you're good to go. It WORKS god damn. I have a working version of your latest 1.108 1.42 beta with WORKING sounds and all you need to do is REMOVE onTick from the IC2 class and change a couple of lines in AudioManagerClient and AudioSourceClient.

Heck, if you can't manage to do that yourself ask matjam to walk you through it. I bet he's more than happy to do so.

aidancbrady

2012-11-18 18:42

reporter   ~0000250

Beard came off a bit harsh, but yes, at least look over the notes before you close it. The bug isn't even fixed -- these reports should be open until there are no more problems.

Forcing-disabling sounds is NOT the option, that's like removing the jetpack from the game because you can't figure out why it won't work.

matjam

2012-11-19 20:10

reporter   ~0000259

the lack of sound is fixed. There are other bugs to do with sound, yes, but they deserve their own bugs. I'm not going to open them though because there is no official release currently with working sound, so it's premature.

 - popping when the samples are started/stopped (relatively easy fix).
 - better algorithm to scale on distance is needed.
 - some machines stop playing sound and then you never hear them again.

RawCode

2012-11-20 03:20

reporter   ~0000261

sounds provide no function at all, this is not jtpack that allow to fly, they did nothing

Silentspy

2012-11-21 03:30

reporter   ~0000273

Sounds provide a lot more feel to the mod then just being blocks on the ground, at least in my opinion its fairly awesome to have a factory that actually sound like one

aidancbrady

2012-11-21 04:00

reporter   ~0000274

RawCode, as Silentspy said, sounds have become a special part of IC. The jetpack was a reference to what SHOUDN'T happen, not something that happened. It's simple -- a dev implements the fix, and we no longer need to worry about this lingering bug.

rsoul

2012-11-22 09:30

reporter   ~0000282

Last edited: 2012-11-22 15:56

I fell really uncomfortable without any sounds, so precious to my ears (feels like you kinda rule a giant facility). It seems that you, guys, fixed the problem. But how can I change the code inside of IC2.class? It needs to be decompilated? I just want to test your solution. Or maybe anyone can send me edited file on my mail: nechaev.main[]gmail.com I will appreciate for your help, really. This mod without any sounds drives me crazy. (I have same issue on 1.106, 1.107, 1.108, 1.109 (both mac and win versions)).

Boone

2012-11-22 11:48

reporter   ~0000284

+1
I can decompile it, but can't compile it again.

Please, send me a fixed IC2.class file.

matjam

2012-11-23 08:02

reporter   ~0000294

Richard, I'm sorry. My instructions were unclear. I looked again at the problem, and realised the fix is really a lot simpler than I thought:-

1. IC2.java: Remove call to audioManager.onTick(); It's already being called in PlatformClient.java.

2. AudioManagerClient.java: Remove the following variables:

    public float defaultVolume = 1.2F;
    public float fadingDistance = 16.0F;

3. AudioManagerClient.java: Add the following to initialize();

        defaultVolume = 0.8F;
        fadingDistance = 12.0F;

I suggest tweaking the values, because machines are a bit loud normally.

4. AudioSourceClient.java: Find the updateVolume() method and change the following:

            float var2 = AudioManager.fadingDistance * Math.max(this.configuredVolume, 1.0F);

to

            float var2 = AudioManagerClient.fadingDistance * Math.max(this.configuredVolume, 1.0F);


You don't need to use my updateVolume method. The original one works fine with that modification to AudioManagerClient.java, though the volume does "drop off a cliff" once you reach the fadingDistance.

Again, not a perfect fix but it at least fixes things to work at least as well as they did in 1.2.5.

matjam

2012-11-23 08:35

reporter   ~0000295

http://forum.industrial-craft.net/index.php?page=Thread&postID=87418

I would appreciate any feedback.

rsoul

2012-11-23 08:37

reporter   ~0000296

matjam, thank you very much. I will test your fix right after my job is finished today. You really made my day.

Boone

2012-11-23 09:20

reporter   ~0000297

Soundfix is working!

rsoul

2012-11-24 19:43

reporter   ~0000302

For me working too!

Player

2012-11-29 22:42

administrator   ~0000332

should be fixed, tyvm for your great work :)

Issue History

Date Modified Username Field Change
2012-10-31 21:12 DoctorBeard New Issue
2012-10-31 21:20 TheBard Note Added: 0000013
2012-11-01 09:38 Gornakosh Status new => acknowledged
2012-11-03 03:15 DoctorBeard Note Added: 0000059
2012-11-03 03:20 RawCode Note Added: 0000063
2012-11-03 03:42 xKillerbees Status acknowledged => confirmed
2012-11-05 13:09 matjam Note Added: 0000084
2012-11-06 09:29 matjam Note Added: 0000096
2012-11-06 09:59 matjam Note Added: 0000098
2012-11-06 11:06 matjam Note Added: 0000099
2012-11-06 11:27 DoctorBeard Note Added: 0000100
2012-11-06 12:03 matjam Note Added: 0000102
2012-11-06 12:53 DoctorBeard Note Added: 0000106
2012-11-06 15:53 aidancbrady Note Added: 0000108
2012-11-06 16:31 DoctorBeard Note Added: 0000112
2012-11-06 16:38 aidancbrady Note Added: 0000113
2012-11-06 18:34 DoctorBeard Note Added: 0000115
2012-11-06 22:01 matjam Note Added: 0000118
2012-11-06 22:01 matjam Note Edited: 0000118
2012-11-06 22:02 matjam Note Edited: 0000118
2012-11-07 05:02 matjam Note Edited: 0000118
2012-11-11 06:31 aidancbrady Note Added: 0000184
2012-11-17 15:06 RichardG Note Added: 0000229
2012-11-17 22:52 RichardG Relationship added has duplicate 0000079
2012-11-18 17:10 DoctorBeard Note Added: 0000249
2012-11-18 18:42 aidancbrady Note Added: 0000250
2012-11-19 20:10 matjam Note Added: 0000259
2012-11-20 03:20 RawCode Note Added: 0000261
2012-11-21 03:30 Silentspy Note Added: 0000273
2012-11-21 04:00 aidancbrady Note Added: 0000274
2012-11-22 09:30 rsoul Note Added: 0000282
2012-11-22 11:48 Boone Note Added: 0000284
2012-11-22 15:56 rsoul Note Edited: 0000282
2012-11-23 08:02 matjam Note Added: 0000294
2012-11-23 08:35 matjam Note Added: 0000295
2012-11-23 08:37 rsoul Note Added: 0000296
2012-11-23 09:20 Boone Note Added: 0000297
2012-11-24 19:43 rsoul Note Added: 0000302
2012-11-26 20:55 Player Assigned To => Player
2012-11-26 20:55 Player Status confirmed => assigned
2012-11-29 22:42 Player Note Added: 0000332
2012-11-29 22:42 Player Status assigned => resolved
2012-11-29 22:42 Player Resolution open => fixed