当前位置: 首页>>代码示例>>Java>>正文


Java AudioDevice类代码示例

本文整理汇总了Java中com.badlogic.gdx.audio.AudioDevice的典型用法代码示例。如果您正苦于以下问题:Java AudioDevice类的具体用法?Java AudioDevice怎么用?Java AudioDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AudioDevice类属于com.badlogic.gdx.audio包,在下文中一共展示了AudioDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
protected AudioDevice createAudioDevice() 
{
	// It could be done like this :
	// AudioDevice device = Gdx.audio.newAudioDevice(config.sampleRate, config.outputChannels < 2);
	// but we need to align buffer size : Pd.process and device.write.
	int samplePerFrame = config.bufferSize;
	int samplePerBuffer = samplePerFrame * config.outputChannels;
	int bufferSizeBytes = samplePerBuffer * 2;
	return new OpenALAudioDevice((OpenALAudio)Gdx.audio, config.sampleRate, config.outputChannels<2, bufferSizeBytes, config.bufferCount);
}
 
开发者ID:mgsx-dev,项目名称:gdx-pd,代码行数:12,代码来源:PdAudioOpenAL.java

示例2: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
	if (soundPool == null) {
		throw new GdxRuntimeException("Android audio is not enabled by the application config.");
	}
	return new AndroidAudioDevice(samplingRate, isMono);
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:9,代码来源:AndroidAudio.java

示例3: create

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@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();
	}
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:29,代码来源:AudioDeviceTest.java

示例4: main

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
public static void main(String[] args) 
{
	LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
	config.audioDeviceBufferSize = 512;
	config.audioDeviceBufferCount = 17;
	new LwjglApplication(new Game(){
		@Override
		public void create() 
		{
			// play a pd patch
			Pd.audio.create(new PdConfiguration());
			Pd.audio.open(Gdx.files.local("resources/test.pd"));
			
			// and write on raw device at the same time
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					int channels = 2;
					
					int sampleRate = 44100;
					AudioDevice device = Gdx.audio.newAudioDevice(sampleRate, channels < 2);
					
					// simple sinus
					float duration = 4.f;
					float pitch = 440;
					
					int samples = (int)(duration * sampleRate) * channels;
					float [] data = new float[samples];
					int stride = samples/channels;
					for(int i=0 ; i<stride ; i+=1){
						float s = (float)i/(float)stride;
						float t = s * duration * pitch;
						float value = MathUtils.sin(MathUtils.PI2 * t);
						for(int j=0 ; j<channels ; j++)
							data[i+j*stride] = value;
					}
					device.writeSamples(data, 0, data.length);
					
					device.dispose();
				}
			}).start();
			
			
		}}, config);
	
}
 
开发者ID:mgsx-dev,项目名称:gdx-pd,代码行数:48,代码来源:AudioGdxRawTest.java

示例5: createAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
protected AudioDevice createAudioDevice()
{
	return Gdx.audio.newAudioDevice(config.sampleRate, config.outputChannels<2);
}
 
开发者ID:mgsx-dev,项目名称:gdx-pd,代码行数:5,代码来源:PdAudioThread.java

示例6: run

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public void run() 
{
	int ticks = Math.max(1, config.bufferSize / PdBase.blockSize());
	
	short [] inBuffer = new short[config.bufferSize * config.inputChannels];
	short [] outBuffer = new short[config.bufferSize * config.outputChannels];
	
	AudioDevice device = createAudioDevice();
	
	AudioRecorder recorder = null;
	if(config.inputChannels > 0){
		recorder = Gdx.audio.newAudioRecorder(config.sampleRate, config.inputChannels < 2);
	}
	PdBase.openAudio(config.inputChannels, config.outputChannels, config.sampleRate);
	PdBase.computeAudio(true);
	
	final Runnable pollRunnable = new Runnable() {
		
		@Override
		public void run() {
			PdBase.pollPdMessageQueue();
			PdBase.pollMidiQueue();
			requirePolling = true;
		}
	};
	
	long nanoDuration = (long)(1e9 * (double)config.bufferSize / (double)config.sampleRate);
	
	long realTime = System.nanoTime();
	long logicTime = realTime;
	
	while(processing){
		if(recorder != null){
			recorder.read(inBuffer, 0, inBuffer.length);
		}
		
		realTime = System.nanoTime();
		long waitTime = (logicTime - realTime) / 1000000;
		if(waitTime > 0){
			try {
				Thread.sleep(waitTime);
			} catch (InterruptedException e) {
			}
		}else{
			logicTime = realTime;
		}
		logicTime += nanoDuration;
		
		PdBase.process(ticks, inBuffer, outBuffer);
		
		device.writeSamples(outBuffer, 0, outBuffer.length);
		
		if(requirePolling){
			Gdx.app.postRunnable(pollRunnable);
		}
	}
	
	device.dispose();
	
	if(recorder != null){
		recorder.dispose();
	}
}
 
开发者ID:mgsx-dev,项目名称:gdx-pd,代码行数:65,代码来源:PdAudioThread.java

示例7: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice(int samplingRate, boolean isMono) {
    throw new GdxRuntimeException("AudioDevice not supported by TeaVM backend");
}
 
开发者ID:konsoletyper,项目名称:teavm-libgdx,代码行数:5,代码来源:TeaVMAudio.java

示例8: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
	throw new GdxRuntimeException("AudioDevice not supported by GWT backend");
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:5,代码来源:GwtAudio.java

示例9: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice(int samplingRate, boolean isMono) {
	return new MockAudioDevice();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:5,代码来源:MockAudio.java

示例10: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
	// TODO Auto-generated method stub
	return null;
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:6,代码来源:IOSAudio.java

示例11: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice(int samplingRate, boolean isMono) {
	return new TestAudioDevice();
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:5,代码来源:MockAudio.java

示例12: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
@Override
public AudioDevice newAudioDevice(int samplingRate, boolean isMono) {
	throw new ServerAudioException();
}
 
开发者ID:Olloth,项目名称:LibGDXServer,代码行数:5,代码来源:ServerAudio.java

示例13: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
public final AudioDevice newAudioDevice(int paramInt, boolean paramBoolean)
{
  return new AndroidAudioDevice(paramInt, paramBoolean);
}
 
开发者ID:isnuryusuf,项目名称:ingress-indonesia-dev,代码行数:5,代码来源:AndroidAudio.java

示例14: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
/** Creates a new {@link AudioDevice} either in mono or stereo mode. The AudioDevice has to be disposed via its
 * {@link AudioDevice#dispose()} method when it is no longer used.
 * 
 * @param samplingRate the sampling rate.
 * @param isMono whether the AudioDevice should be in mono or stereo mode
 * @return the AudioDevice
 * 
 * @throws GdxRuntimeException in case the device could not be created */
public AudioDevice newAudioDevice (int samplingRate, boolean isMono);
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:10,代码来源:Audio.java

示例15: newAudioDevice

import com.badlogic.gdx.audio.AudioDevice; //导入依赖的package包/类
/**
 * Creates a new {@link AudioDevice} either in mono or stereo mode. The AudioDevice has to be disposed via its
 * {@link AudioDevice#dispose()} method when it is no longer used.
 *
 * @param samplingRate the sampling rate.
 * @param isMono whether the AudioDevice should be in mono or stereo mode
 * @return the AudioDevice
 *
 * @throws GdxRuntimeException in case the device could not be created
 */
public AudioDevice newAudioDevice(int samplingRate, boolean isMono);
 
开发者ID:kovertopz,项目名称:libGDX-LWJGL-Audio,代码行数:12,代码来源:Audio.java


注:本文中的com.badlogic.gdx.audio.AudioDevice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。