use of pl.asie.charset.lib.audio.manager.IAudioStream 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) {
}
}
}
Aggregations