com.sedmelluq.discord.lavaplayer.player.AudioConfiguration Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.player.AudioConfiguration. 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: JbAudioPlayerManagerImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
public void init() {
    WorkerProperties.Audio configuration = workerProperties.getAudio();
    getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality
            .valueOf(configuration.getResamplingQuality()));
    setFrameBufferDuration(configuration.getFrameBufferDuration());
    setItemLoaderThreadPoolSize(configuration.getItemLoaderThreadPoolSize());
    registerSourceManager(new YoutubeAudioSourceManager(true));
    registerSourceManager(new SoundCloudAudioSourceManager());
    registerSourceManager(new BandcampAudioSourceManager());
    registerSourceManager(new VimeoAudioSourceManager());
    registerSourceManager(new TwitchStreamAudioSourceManager());
    registerSourceManager(new BeamAudioSourceManager());
    if (CollectionUtils.isNotEmpty(audioSourceManagers)) {
        audioSourceManagers.forEach(this::registerSourceManager);
    }
}
 
Example #2
Source File: TrackStartRequestCodec.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public TrackStartRequestMessage decode(DataInput in, int version) throws IOException {
  long executorId = in.readLong();
  AudioTrackInfo trackInfo = new AudioTrackInfo(in.readUTF(), in.readUTF(), in.readLong(), in.readUTF(), in.readBoolean(), null);

  byte[] encodedTrack = new byte[in.readInt()];
  in.readFully(encodedTrack);

  int volume = in.readInt();
  AudioConfiguration configuration = new AudioConfiguration();
  configuration.setResamplingQuality(AudioConfiguration.ResamplingQuality.valueOf(in.readUTF()));
  configuration.setOpusEncodingQuality(in.readInt());

  if (version >= VERSION_WITH_FORMAT) {
    AudioDataFormat format = createFormat(in.readInt(), in.readInt(), in.readInt(), in.readUTF());
    configuration.setOutputFormat(format);
  }

  long position = 0;

  if (version >= VERSION_WITH_POSITION) {
    position = in.readLong();
  }

  return new TrackStartRequestMessage(executorId, trackInfo, encodedTrack, volume, configuration, position);
}
 
Example #3
Source File: BotApplicationManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
public BotApplicationManager() {
  guildContexts = new HashMap<>();
  controllerManager = new BotControllerManager();

  controllerManager.registerController(new MusicController.Factory());

  playerManager = new DefaultAudioPlayerManager();
  //playerManager.useRemoteNodes("localhost:8080");
  playerManager.getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality.LOW);
  playerManager.registerSourceManager(new YoutubeAudioSourceManager());
  playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
  playerManager.registerSourceManager(new BandcampAudioSourceManager());
  playerManager.registerSourceManager(new VimeoAudioSourceManager());
  playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
  playerManager.registerSourceManager(new BeamAudioSourceManager());
  playerManager.registerSourceManager(new HttpAudioSourceManager());
  playerManager.registerSourceManager(new LocalAudioSourceManager());

  executorService = Executors.newScheduledThreadPool(1, new DaemonThreadFactory("bot"));
}
 
Example #4
Source File: AudioProcessingContext.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param configuration Audio encoding or filtering related configuration
 * @param frameBuffer Frame buffer for the produced audio frames
 * @param playerOptions State of the audio player.
 * @param outputFormat Output format to use throughout this processing cycle
 */
public AudioProcessingContext(AudioConfiguration configuration, AudioFrameBuffer frameBuffer,
                              AudioPlayerOptions playerOptions, AudioDataFormat outputFormat) {

  this.configuration = configuration;
  this.frameBuffer = frameBuffer;
  this.playerOptions = playerOptions;
  this.outputFormat = outputFormat;
  this.filterHotSwapEnabled = configuration.isFilterHotSwapEnabled();
}
 
Example #5
Source File: LocalAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param audioTrack The audio track that this executor executes
 * @param configuration Configuration to use for audio processing
 * @param playerOptions Mutable player options (for example volume).
 * @param useSeekGhosting Whether to keep providing old frames continuing from the previous position during a seek
 *                        until frames from the new position arrive.
 * @param bufferDuration The size of the frame buffer in milliseconds
 */
public LocalAudioTrackExecutor(InternalAudioTrack audioTrack, AudioConfiguration configuration,
                               AudioPlayerOptions playerOptions, boolean useSeekGhosting, int bufferDuration) {

  this.audioTrack = audioTrack;
  AudioDataFormat currentFormat = configuration.getOutputFormat();
  this.frameBuffer = configuration.getFrameBufferFactory().create(bufferDuration, currentFormat, queuedStop);
  this.processingContext = new AudioProcessingContext(configuration, frameBuffer, playerOptions, currentFormat);
  this.useSeekGhosting = useSeekGhosting;
}
 
Example #6
Source File: TrackStartRequestMessage.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param executorId The ID for the track executor
 * @param trackInfo Generic track information
 * @param encodedTrack Track specific extra information that is required to initialise the track object
 * @param volume Initial volume of the track
 * @param configuration Configuration to use for audio processing
 * @param position Position to start playing at in milliseconds
 */
public TrackStartRequestMessage(long executorId, AudioTrackInfo trackInfo, byte[] encodedTrack, int volume,
                                AudioConfiguration configuration, long position) {

  this.executorId = executorId;
  this.encodedTrack = encodedTrack;
  this.trackInfo = trackInfo;
  this.volume = volume;
  this.configuration = configuration;
  this.position = position;
}
 
Example #7
Source File: RemoteAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param track Audio track to play
 * @param configuration Configuration for audio processing
 * @param remoteNodeManager Manager of remote nodes
 * @param volumeLevel Mutable volume level
 */
public RemoteAudioTrackExecutor(AudioTrack track, AudioConfiguration configuration,
                                RemoteNodeManager remoteNodeManager, AtomicInteger volumeLevel) {

  this.track = track;
  this.configuration = configuration.copy();
  this.remoteNodeManager = remoteNodeManager;
  this.volumeLevel = volumeLevel;
  this.executorId = System.nanoTime();
  this.frameBuffer = configuration.getFrameBufferFactory().create(BUFFER_DURATION_MS, configuration.getOutputFormat(), null);
}
 
Example #8
Source File: ResamplingPcmAudioFilter.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * @param configuration Configuration to use
 * @param channels Number of channels in input data
 * @param downstream Next filter in chain
 * @param sourceRate Source sample rate
 * @param targetRate Target sample rate
 */
public ResamplingPcmAudioFilter(AudioConfiguration configuration, int channels, FloatPcmAudioFilter downstream,
                                int sourceRate, int targetRate) {

  this.downstream = downstream;
  converters = new SampleRateConverter[channels];
  outputSegments = new float[channels][];

  SampleRateConverter.ResamplingType type = getResamplingType(configuration.getResamplingQuality());

  for (int i = 0; i < channels; i++) {
    outputSegments[i] = new float[BUFFER_SIZE];
    converters[i] = new SampleRateConverter(type, 1, sourceRate, targetRate);
  }
}
 
Example #9
Source File: ResamplingPcmAudioFilter.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private static SampleRateConverter.ResamplingType getResamplingType(AudioConfiguration.ResamplingQuality quality) {
  switch (quality) {
    case HIGH:
      return SampleRateConverter.ResamplingType.SINC_MEDIUM_QUALITY;
    case MEDIUM:
      return SampleRateConverter.ResamplingType.SINC_FASTEST;
    case LOW:
    default:
      return SampleRateConverter.ResamplingType.LINEAR;
  }
}
 
Example #10
Source File: AudioFrameVolumeChanger.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private AudioFrameVolumeChanger(AudioConfiguration configuration, AudioDataFormat format, int newVolume) {
  this.configuration = configuration;
  this.format = format;
  this.newVolume = newVolume;

  this.sampleBuffer = ByteBuffer
      .allocateDirect(format.totalSampleCount() * 2)
      .order(ByteOrder.nativeOrder())
      .asShortBuffer();
  this.volumeProcessor = new PcmVolumeProcessor(100);
}
 
Example #11
Source File: OpusChunkEncoder.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
/**
 * @param configuration Audio configuration used for configuring the encoder
 * @param format Target audio format.
 */
public OpusChunkEncoder(AudioConfiguration configuration, AudioDataFormat format) {
  encodedBuffer = ByteBuffer.allocateDirect(format.maximumChunkSize());
  encoder = new OpusEncoder(format.sampleRate, format.channelCount, configuration.getOpusEncodingQuality());
  this.format = format;
}
 
Example #12
Source File: Pcm16AudioDataFormat.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public AudioChunkEncoder createEncoder(AudioConfiguration configuration) {
  return new PcmChunkEncoder(this, bigEndian);
}
 
Example #13
Source File: OpusAudioDataFormat.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public AudioChunkEncoder createEncoder(AudioConfiguration configuration) {
  return new OpusChunkEncoder(configuration, this);
}
 
Example #14
Source File: AudioDataFormat.java    From lavaplayer with Apache License 2.0 2 votes vote down vote up
/**
 * @param configuration Configuration to use for encoding.
 * @return Encoder to convert data in short PCM format to this format.
 */
public abstract AudioChunkEncoder createEncoder(AudioConfiguration configuration);
 
Example #15
Source File: RemoteAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @return The configuration to use for processing audio
 */
public AudioConfiguration getConfiguration() {
  return configuration;
}