Search in sources :

Example 1 with AudioStreamOpenAL

use of pl.asie.charset.lib.audio.manager.AudioStreamOpenAL in project Charset by CharsetMC.

the class PacketAudioData method apply.

@Override
public void apply(INetHandler handler) {
    AudioData audioData = packet.getData();
    if (audioData instanceof IDataGameSound) {
        IDataGameSound sound = (IDataGameSound) audioData;
        playSoundNote(packet, sound);
        return;
    }
    if (!(audioData instanceof IAudioDataPCM) || ((IAudioDataPCM) audioData).getSampleSize() != 1) {
        // Nope!
        return;
    }
    IAudioDataPCM pcmPacket = (IAudioDataPCM) audioData;
    byte[] data = pcmPacket.getSamplePCMData();
    if (pcmPacket.isSampleSigned()) {
        byte[] data2 = new byte[data.length];
        for (int i = 0; i < data.length; i++) {
            data2[i] = (byte) (data[i] ^ 0x80);
        }
        data = data2;
    }
    IAudioStream stream = AudioStreamManagerClient.INSTANCE.get(id);
    if (stream == null) {
        stream = new AudioStreamOpenAL(false, false, 8);
        AudioStreamManagerClient.INSTANCE.put(id, stream);
    }
    stream.setSampleRate(pcmPacket.getSampleRate());
    stream.push(data);
    for (AudioSink sink : packet.getSinks()) {
        try {
            stream.play((float) sink.getPos().x, (float) sink.getPos().y, (float) sink.getPos().z, sink.getDistance(), sink.getVolume() * packet.getVolume());
        } catch (Exception e) {
        }
    }
}
Also used : AudioSink(pl.asie.charset.api.audio.AudioSink) AudioData(pl.asie.charset.api.audio.AudioData) IAudioStream(pl.asie.charset.lib.audio.manager.IAudioStream) AudioStreamOpenAL(pl.asie.charset.lib.audio.manager.AudioStreamOpenAL) IAudioDataPCM(pl.asie.charset.api.audio.IAudioDataPCM) IDataGameSound(pl.asie.charset.lib.audio.types.IDataGameSound)

Aggregations

AudioData (pl.asie.charset.api.audio.AudioData)1 AudioSink (pl.asie.charset.api.audio.AudioSink)1 IAudioDataPCM (pl.asie.charset.api.audio.IAudioDataPCM)1 AudioStreamOpenAL (pl.asie.charset.lib.audio.manager.AudioStreamOpenAL)1 IAudioStream (pl.asie.charset.lib.audio.manager.IAudioStream)1 IDataGameSound (pl.asie.charset.lib.audio.types.IDataGameSound)1