Search in sources :

Example 1 with SoundSource

use of io.xol.chunkstories.api.sound.SoundSource in project chunkstories by Hugobros3.

the class PacketSoundSource method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
    String soundName = in.readUTF();
    long UUID = in.readLong();
    boolean hasPosition = in.readBoolean();
    Vector3dc position = null;
    if (hasPosition) {
        position = new Vector3d(in.readFloat(), in.readFloat(), in.readFloat());
    }
    // boolean loop = in.readBoolean();
    // boolean isAmbient = in.readBoolean();
    // boolean buffered = in.readBoolean();
    byte modeByte = in.readByte();
    Mode mode = Mode.values()[modeByte];
    boolean stopped = in.readBoolean();
    float pitch = in.readFloat();
    float gain = in.readFloat();
    float attenuationStart = in.readFloat();
    float attenuationEnd = in.readFloat();
    if (!(processor instanceof ClientPacketsProcessor))
        return;
    ClientPacketsProcessor cpe = (ClientPacketsProcessor) processor;
    SoundSource soundSource = cpe.getContext().getSoundManager().getSoundSourceByUUID(UUID);
    // ALSoundSource soundSource = (ALSoundSource) Client.getInstance().getSoundManager().getSoundSourceByUUID(UUID);
    if (soundSource == null && stopped)
        return;
    if (soundSource == null) {
        soundSource = cpe.getContext().getSoundManager().replicateServerSoundSource(soundName, mode, position, pitch, gain, attenuationStart, attenuationEnd, UUID);
        return;
    }
    if (stopped) {
        soundSource.stop();
        return;
    }
    // Update the soundSource with all we can
    soundSource.setPosition(position);
    soundSource.setPitch(pitch);
    soundSource.setGain(gain);
    soundSource.setAttenuationStart(attenuationStart);
    soundSource.setAttenuationEnd(attenuationEnd);
}
Also used : Vector3dc(org.joml.Vector3dc) SoundSource(io.xol.chunkstories.api.sound.SoundSource) ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d) Mode(io.xol.chunkstories.api.sound.SoundSource.Mode)

Example 2 with SoundSource

use of io.xol.chunkstories.api.sound.SoundSource in project chunkstories by Hugobros3.

the class VirtualSoundManager method getAllPlayingSounds.

@Override
public Iterator<SoundSource> getAllPlayingSounds() {
    return new Iterator<SoundSource>() {

        Iterator<WeakReference<SoundSourceVirtual>> iterator = allPlayingSoundSources.iterator();

        SoundSource next = null;

        @Override
        public boolean hasNext() {
            if (next != null)
                return true;
            while (iterator.hasNext() && next == null) {
                WeakReference<SoundSourceVirtual> weakReference = iterator.next();
                SoundSourceVirtual soundSource = weakReference.get();
                if (soundSource == null || soundSource.isDonePlaying()) {
                    iterator.remove();
                    continue;
                }
                next = soundSource;
            }
            return false;
        }

        @Override
        public SoundSource next() {
            if (next == null)
                hasNext();
            SoundSource oldNext = next;
            next = null;
            return oldNext;
        }
    };
}
Also used : PacketSoundSource(io.xol.chunkstories.net.packets.PacketSoundSource) SoundSource(io.xol.chunkstories.api.sound.SoundSource) SoundSourceVirtual(io.xol.chunkstories.sound.source.SoundSourceVirtual) Iterator(java.util.Iterator)

Example 3 with SoundSource

use of io.xol.chunkstories.api.sound.SoundSource in project chunkstories by Hugobros3.

the class ALSoundManager method removeUnplayingSources.

int removeUnplayingSources() {
    int j = 0;
    Iterator<ALSoundSource> i = playingSoundSources.iterator();
    while (i.hasNext()) {
        SoundSource soundSource = i.next();
        if (soundSource.isDonePlaying()) {
            soundSource.stop();
            i.remove();
            j++;
        }
    }
    return j;
}
Also used : DummySoundSource(io.xol.chunkstories.sound.source.DummySoundSource) ALBufferedSoundSource(io.xol.chunkstories.sound.source.ALBufferedSoundSource) ALSoundSource(io.xol.chunkstories.sound.source.ALSoundSource) SoundSource(io.xol.chunkstories.api.sound.SoundSource) ALSoundSource(io.xol.chunkstories.sound.source.ALSoundSource)

Aggregations

SoundSource (io.xol.chunkstories.api.sound.SoundSource)3 ClientPacketsProcessor (io.xol.chunkstories.api.client.net.ClientPacketsProcessor)1 Mode (io.xol.chunkstories.api.sound.SoundSource.Mode)1 PacketSoundSource (io.xol.chunkstories.net.packets.PacketSoundSource)1 ALBufferedSoundSource (io.xol.chunkstories.sound.source.ALBufferedSoundSource)1 ALSoundSource (io.xol.chunkstories.sound.source.ALSoundSource)1 DummySoundSource (io.xol.chunkstories.sound.source.DummySoundSource)1 SoundSourceVirtual (io.xol.chunkstories.sound.source.SoundSourceVirtual)1 Iterator (java.util.Iterator)1 Vector3d (org.joml.Vector3d)1 Vector3dc (org.joml.Vector3dc)1