com.badlogic.gdx.Audio.newAudioDevice()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中com.badlogic.gdx.Audio.newAudioDevice()方法的一些代码示例,展示了Audio.newAudioDevice()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Audio.newAudioDevice()方法的具体详情如下:
包路径:com.badlogic.gdx.Audio
类名称:Audio
方法名:newAudioDevice

Audio.newAudioDevice介绍

[英]Creates a new AudioDevice either in mono or stereo mode. The AudioDevice has to be disposed via its AudioDevice#dispose() method when it is no longer used.
[中]以单声道或立体声模式创建新的音频设备。当不再使用AudioDevice时,必须通过其AudioDevice#dispose()方法对其进行处置。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
  public void resume () {
    device = Gdx.audio.newAudioDevice(44100, true);
    recorder = Gdx.audio.newAudioRecorder(44100, true);
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  device = Gdx.audio.newAudioDevice(44100, true);
  recorder = Gdx.audio.newAudioRecorder(44100, true);
  Thread t = new Thread(new Runnable() {
    @Override
    public void run () {
      while (true) {
        recorder.read(samples, 0, samples.length);
        device.writeSamples(samples, 0, samples.length);
      }
    }
  });
  t.setDaemon(true);
  t.start();
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  if (thread == null) {
    final AudioDevice device = Gdx.app.getAudio().newAudioDevice(44100, false);
    thread = new Thread(new Runnable() {
      @Override
      public void run () {
        final float frequency = 440;
        float increment = (float)(2 * Math.PI) * frequency / 44100; // angular increment for each sample
        float angle = 0;
        float samples[] = new float[1024];
        while (!stop) {
          for (int i = 0; i < samples.length; i += 2) {
            samples[i] = 0.5f * (float)Math.sin(angle);
            samples[i + 1] = 2 * samples[i];
            angle += increment;
          }
          device.writeSamples(samples, 0, samples.length);
        }
        device.dispose();
      }
    });
    thread.start();
  }
}

代码示例来源:origin: tube42/drumon

public void open()
{
  if(ad != null) {
    close();
  }
  System.out.println("DEVICE OUTPUT: opening...");
  int freq = World.freq;
  ad = Gdx.audio.newAudioDevice(freq, true);
  int lat = ad.getLatency();
  System.out.println(
       "AudioDevice latency=" + lat + "samp/" +
       (1000 * lat / (float)freq) + " ms " +
       " freq=" + freq +
       " mono=" + ad.isMono()
       );
}

相关文章