com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.track.playback.MutableAudioFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerManagerTestTools.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
public static long consumeTrack(AudioPlayer player) throws Exception {
  ByteBuffer buffer = ByteBuffer.allocate(960 * 2 * 2);

  MutableAudioFrame frame = new MutableAudioFrame();
  frame.setBuffer(buffer);

  CRC32 crc = new CRC32();
  int count = 0;

  while (player.getPlayingTrack() != null && player.provide(frame, 10, TimeUnit.SECONDS)) {
    buffer.flip();
    crc.update(buffer.array(), buffer.position(), buffer.remaining());
    count++;
  }

  System.out.println("Consumed " + count + " samples");

  return crc.getValue();
}
 
Example #2
Source File: LocalSendHandler.java    From kyoko with MIT License 5 votes vote down vote up
public LocalSendHandler(LocalPlayerWrapper audioPlayer) {
    this.audioPlayer = audioPlayer.getPlayer();
    this.frame = new MutableAudioFrame();

    this.frameBuffer = ByteBuffer.allocate(DISCORD_OPUS.maximumChunkSize());
    this.opusBuffer = ByteBuffer.allocate(DISCORD_OPUS.maximumChunkSize());

    frame.setBuffer(frameBuffer);
    frame.setFormat(DISCORD_OPUS);
}
 
Example #3
Source File: AudioPlayerSendHandler.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
    this.audioPlayer = audioPlayer;
    if (ExtraRuntimeOptions.DISABLE_NON_ALLOCATING_BUFFER) {
        this.frame = null;
    } else {
        this.frame = new MutableAudioFrame();
        frame.setFormat(StandardAudioDataFormats.DISCORD_OPUS);
        frame.setBuffer(ByteBuffer.allocate(StandardAudioDataFormats.DISCORD_OPUS.maximumChunkSize()));
    }
}
 
Example #4
Source File: AudioPlayerSendHandler.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param audioPlayer Audio player to wrap.
 */
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
  this.audioPlayer = audioPlayer;
  this.buffer = ByteBuffer.allocate(1024);
  this.frame = new MutableAudioFrame();
  this.frame.setBuffer(buffer);
}
 
Example #5
Source File: BufferingPostProcessor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param context Processing context to determine the destination buffer from.
 * @param encoder Encoder to encode the chunk with.
 */
public BufferingPostProcessor(AudioProcessingContext context, AudioChunkEncoder encoder) {
  this.encoder = encoder;
  this.context = context;
  this.offeredFrame = new MutableAudioFrame();
  this.outputBuffer = ByteBuffer.allocateDirect(context.outputFormat.maximumChunkSize());

  offeredFrame.setFormat(context.outputFormat);
}
 
Example #6
Source File: RemoteAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame, long timeout, TimeUnit unit)
    throws TimeoutException, InterruptedException {

  if (frameBuffer.provide(targetFrame, timeout, unit)) {
    processProvidedFrame(targetFrame);
    return true;
  }

  return true;
}
 
Example #7
Source File: RemoteAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame) {
  if (frameBuffer.provide(targetFrame)) {
    processProvidedFrame(targetFrame);
    return true;
  }

  return true;
}
 
Example #8
Source File: OpusPacketRouter.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param context Configuration and output information for processing
 * @param inputFrequency Sample rate of the opus track
 * @param inputChannels Number of channels in the opus track
 */
public OpusPacketRouter(AudioProcessingContext context, int inputFrequency, int inputChannels) {
  this.context = context;
  this.inputFrequency = inputFrequency;
  this.inputChannels = inputChannels;
  this.headerBytes = new byte[2];
  this.offeredFrame = new MutableAudioFrame();
  this.lastFrameSize = 0;

  offeredFrame.setVolume(100);
  offeredFrame.setFormat(context.outputFormat);
}
 
Example #9
Source File: DefaultAudioPlayer.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame, long timeout, TimeUnit unit)
    throws TimeoutException, InterruptedException {

  InternalAudioTrack track;

  lastRequestTime = System.currentTimeMillis();

  if (timeout == 0 && paused.get()) {
    return false;
  }

  while ((track = activeTrack) != null) {
    if (timeout > 0 ? track.provide(targetFrame, timeout, unit) : track.provide(targetFrame)) {
      lastReceiveTime = System.nanoTime();
      shadowTrack = null;

      if (targetFrame.isTerminator()) {
        handleTerminator(track);
        continue;
      }

      return true;
    } else if (timeout == 0) {
      checkStuck(track);
      return provideShadowFrame(targetFrame);
    } else {
      return false;
    }
  }

  return false;
}
 
Example #10
Source File: DefaultAudioPlayer.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame) {
  try {
    return provide(targetFrame, 0, TimeUnit.MILLISECONDS);
  } catch (TimeoutException | InterruptedException e) {
    ExceptionTools.keepInterrupted(e);
    throw new RuntimeException(e);
  }
}
 
Example #11
Source File: DefaultAudioPlayer.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private boolean provideShadowFrame(MutableAudioFrame targetFrame) {
  InternalAudioTrack shadow = shadowTrack;

  if (shadow != null && shadow.provide(targetFrame)) {
    if (targetFrame.isTerminator()) {
      shadowTrack = null;
      return false;
    }

    return true;
  }

  return false;
}
 
Example #12
Source File: StreamAudioPlayer.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame, long timeout, TimeUnit unit) throws TimeoutException,
    InterruptedException {

  synchronized (lock) {
    if (streamCursor != null) {
      throw new UnsupportedOperationException();
    }

    return fallback.provide(targetFrame, timeout, unit);
  }
}
 
Example #13
Source File: StreamAudioPlayer.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame) {
  synchronized (lock) {
    if (streamCursor != null) {
      throw new UnsupportedOperationException();
    }

    return fallback.provide(targetFrame);
  }
}
 
Example #14
Source File: BaseAudioTrack.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame) {
  return getActiveExecutor().provide(targetFrame);
}
 
Example #15
Source File: BaseAudioTrack.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean provide(MutableAudioFrame targetFrame, long timeout, TimeUnit unit)
    throws TimeoutException, InterruptedException {

  return getActiveExecutor().provide(targetFrame, timeout, unit);
}
 
Example #16
Source File: AudioPlayerSenderHandler.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
AudioPlayerSenderHandler(IPlayer audioPlayer) {
    this.audioPlayer = (LavaplayerPlayerWrapper) audioPlayer;
    this.buffer = ByteBuffer.allocate(1024);
    this.frame = new MutableAudioFrame();
    this.frame.setBuffer(buffer);
}
 
Example #17
Source File: AudioPlayerSendHandler.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
public AudioPlayerSendHandler(AudioPlayer audioPlayer) {
  this.audioPlayer = audioPlayer;
  this.buffer = ByteBuffer.allocate(1024);
  this.frame = new MutableAudioFrame();
  this.frame.setBuffer(buffer);
}
 
Example #18
Source File: LavaplayerAudioProvider.java    From Shadbot with GNU General Public License v3.0 4 votes vote down vote up
public LavaplayerAudioProvider(AudioPlayer audioPlayer) {
    super(ByteBuffer.allocate(StandardAudioDataFormats.DISCORD_OPUS.maximumChunkSize()));
    this.audioPlayer = audioPlayer;
    this.frame = new MutableAudioFrame();
    this.frame.setBuffer(this.getBuffer());
}
 
Example #19
Source File: LavaplayerPlayerWrapper.java    From Lavalink-Client with MIT License 4 votes vote down vote up
public boolean provide(MutableAudioFrame targetFrame) {
    return player.provide(targetFrame);
}