1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +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:
Jonathan Coates 2022-04-27 10:56:57 +01:00
parent 42b98bce28
commit 2a4f75ba15
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
6 changed files with 20 additions and 22 deletions

View File

@ -105,8 +105,7 @@
}
}
// 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')

View File

@ -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

View File

@ -20,12 +20,10 @@
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 @@ void push( @Nonnull ByteBuf input )
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 @@ void push( @Nonnull ByteBuf input )
@Override
public AudioFormat getFormat()
{
return MONO_16;
return MONO_8;
}
@Nonnull

View File

@ -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;
}

View File

@ -7,13 +7,16 @@
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 void tick()
{
}
@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 );
}
}

View File

@ -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"