mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-04-16 15:53:18 +00:00
Use Forge's new sound stream API
- Bump Forge version to latest RB. - Generate an 8-bit audio stream again, as we no longer need to be compatible with MC's existing streams. No functionality changes, just mildly less hacky.
This commit is contained in:
parent
42b98bce28
commit
2a4f75ba15
@ -105,8 +105,7 @@ minecraft {
|
||||
}
|
||||
}
|
||||
|
||||
// mappings channel: 'parchment', version: "${mapping_version}-${mc_version}"
|
||||
mappings channel: 'official', version: mc_version
|
||||
mappings channel: 'parchment', version: "${mapping_version}-${mc_version}"
|
||||
|
||||
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
accessTransformer file('src/testMod/resources/META-INF/accesstransformer.cfg')
|
||||
|
@ -5,6 +5,6 @@ mod_version=1.100.4
|
||||
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.18.2
|
||||
mapping_version=2022.02.13
|
||||
forge_version=40.0.24
|
||||
mapping_version=2022.03.13
|
||||
forge_version=40.1.0
|
||||
# NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING
|
||||
|
@ -20,12 +20,10 @@ import java.util.Queue;
|
||||
|
||||
class DfpwmStream implements AudioStream
|
||||
{
|
||||
public static final int SAMPLE_RATE = SpeakerPeripheral.SAMPLE_RATE;
|
||||
|
||||
private static final int PREC = 10;
|
||||
private static final int LPF_STRENGTH = 140;
|
||||
|
||||
private static final AudioFormat MONO_16 = new AudioFormat( SAMPLE_RATE, 16, 1, true, false );
|
||||
private static final AudioFormat MONO_8 = new AudioFormat( SpeakerPeripheral.SAMPLE_RATE, 8, 1, true, false );
|
||||
|
||||
private final Queue<ByteBuffer> buffers = new ArrayDeque<>( 2 );
|
||||
|
||||
@ -41,7 +39,7 @@ class DfpwmStream implements AudioStream
|
||||
void push( @Nonnull ByteBuf input )
|
||||
{
|
||||
int readable = input.readableBytes();
|
||||
ByteBuffer output = ByteBuffer.allocate( readable * 16 ).order( ByteOrder.nativeOrder() );
|
||||
ByteBuffer output = ByteBuffer.allocate( readable * 8 ).order( ByteOrder.nativeOrder() );
|
||||
|
||||
for( int i = 0; i < readable; i++ )
|
||||
{
|
||||
@ -73,9 +71,9 @@ class DfpwmStream implements AudioStream
|
||||
strength = nextStrength;
|
||||
previousBit = currentBit;
|
||||
|
||||
// Ideally we'd generate an 8-bit audio buffer. However, as we're piggybacking on top of another
|
||||
// audio stream (which uses 16 bit audio), we need to keep in the same format.
|
||||
output.putShort( (short) ((byte) (lowPassCharge & 0xFF) << 8) );
|
||||
// OpenAL expects signed data ([0, 255]) while we produce unsigned ([-128, 127]). Do some bit twiddling
|
||||
// magic to convert.
|
||||
output.put( (byte) ((lowPassCharge & 0xFF) ^ 0x80) );
|
||||
|
||||
inputByte >>= 1;
|
||||
}
|
||||
@ -92,7 +90,7 @@ class DfpwmStream implements AudioStream
|
||||
@Override
|
||||
public AudioFormat getFormat()
|
||||
{
|
||||
return MONO_16;
|
||||
return MONO_8;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -26,12 +26,9 @@ public class SpeakerManager
|
||||
@SubscribeEvent
|
||||
public static void playStreaming( PlayStreamingSourceEvent event )
|
||||
{
|
||||
if( !(event.getSound() instanceof SpeakerSound sound) ) return;
|
||||
if( sound.stream == null ) return;
|
||||
|
||||
event.getChannel().attachBufferStream( sound.stream );
|
||||
event.getChannel().play();
|
||||
if( !(event.getSound() instanceof SpeakerSound sound) || sound.stream == null ) return;
|
||||
|
||||
// Associate the sound with the current channel, so SpeakerInstance.pushAudio can queue audio immediately.
|
||||
sound.channel = event.getChannel();
|
||||
sound.executor = event.getEngine().executor;
|
||||
}
|
||||
|
@ -7,13 +7,16 @@ package dan200.computercraft.client.sound;
|
||||
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
|
||||
import net.minecraft.client.resources.sounds.Sound;
|
||||
import net.minecraft.client.resources.sounds.TickableSoundInstance;
|
||||
import net.minecraft.client.sounds.AudioStream;
|
||||
import net.minecraft.client.sounds.SoundBufferLibrary;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class SpeakerSound extends AbstractSoundInstance implements TickableSoundInstance
|
||||
@ -50,9 +53,10 @@ public class SpeakerSound extends AbstractSoundInstance implements TickableSound
|
||||
{
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AudioStream getStream()
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<AudioStream> getStream( @Nonnull SoundBufferLibrary soundBuffers, @Nonnull Sound sound, boolean looping )
|
||||
{
|
||||
return stream;
|
||||
return stream != null ? CompletableFuture.completedFuture( stream ) : super.getStream( soundBuffers, sound, looping );
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a
|
||||
[[dependencies.computercraft]]
|
||||
modId="forge"
|
||||
mandatory=true
|
||||
versionRange="[40.0.24,41)"
|
||||
versionRange="[40.1.0,41)"
|
||||
ordering="NONE"
|
||||
side="BOTH"
|
||||
|
Loading…
x
Reference in New Issue
Block a user