我停止工作在这个项目上有三个原因; 1)我必须专注于我的主要项目。这只是一个有趣的项目。 2)我不感到舒服滥用非个人使用受版权保护的材料,也不应该。 3)这是一个条目的竞争结束了。 我释放这个项目的源代码,因为我真的已经相当多的电子邮件 好的建议关于如何使这个更好,但我没有时间来实现自己。 代码(/ src /)发布的公共领域,所以你可以做你的愿望。 艺术(/ res /)仍然是版权任天堂,那么几乎可以肯定不可以做任何事情。问任天堂。 关于代码: 基本上是无证的代码,但应该是可读的,很干净。主要的入口点AppletLauncher FrameLauncher。MarioComponent的主要游戏。
核心代码public class SonarSoundEngine implements Runnable
{
private SonarSample silentSample;
private sourceDataLine sdl;
private int rate = 44100;
private listenerMixer listenerMixer;
private int bufferSize = rate / 100; // 10 ms
private ByteBuffer soundBuffer = ByteBuffer.allocate(bufferSize * 4);
private float[] leftBuf, rightBuf;
private float amplitude = 1;
private float targetAmplitude = 1;
private boolean alive = true;
protected SonarSoundEngine()
{
}
public SonarSoundEngine(int maxChannels) throws LineUnavaiLableException
{
silentSample = new SonarSample(new float[] {0}, 44100);
Mixer mixer = Audiosystem.getMixer(null);
sdl = (SourceDataLine) mixer.getLine(new Line.Info(SourceDataLine.class));
sdl.open(new AudioFormat(rate, 16, 2, true, false), bufferSize * 2 * 2 * 2 * 2 * 2);
soundBuffer.order(ByteOrder.LITTLE_ENDIAN);
sdl.start();
try
{
/* FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volumeControl.getMaximum());*/
}
catch (IllegalArgumentException e)
{
System.out.println("Failed to set the sound volume");
}
listenerMixer = new ListenerMixer(maxChannels);
leftBuf = new float[bufferSize];
rightBuf = new float[bufferSize];
Thread thread = new Thread(this);
thread.setDaemon(true);
thread.setPriority(10);
thread.start();
}
public void setListener(SoundListener soundListener)
{
listenerMixer.setSoundListener(soundListener);
}
public void shutDown()
{
alive = false;
}
public SonarSample loadSample(String resourceName)
{
try
{
return SampleLoader.loadSample(resourceName);
}
catch (Exception e)
{
System.out.println("Failed to load sample " resourceName ". USING silent sample");
e.printStackTrace();
return silentSample;
}
}
public void play(SonarSample sample, SoundSource soundSource, float volume, float priority, float rate)
{
synchronized (listenerMixer)
{
listenerMixer.addSoundProducer(new SamplePlayer((SonarSample) sample, rate), soundSource, volume, priority);
}
}
public void clientTick(float alpha)
{
synchronized (listenerMixer)
{
listenerMixer.update(alpha);
}
}
public void tick()
{
soundBuffer.clear();
// targetAmplitude = (targetAmplitude - 1) * 0.9f 1;
// targetAmplitude = (targetAmplitude - 1) * 0.9f 1;
synchronized (listenerMixer)
{
float maxAmplitude = listenerMixer.read(leftBuf, rightBuf, rate);
// if (maxAmplitude > targetAmplitude) targetAmplitude = maxAmplitude;
}
soundBuffer.clear();
float gain = 32000;
for (int i = 0; i < bufferSize; i )
{
// amplitude = (targetAmplitude - amplitude) / rate;
// amplitude = 1;
// float gain = 30000;
int l = (int) (leftBuf[i] * gain);
int r = (int) (rightBuf[i] * gain);
if (l > 32767) l = 32767;
if (r > 32767) r = 32767;
if (l < -32767) l = -32767;
if (r < -32767) r = -32767;
soundBuffer.putShort((short)l);
soundBuffer.putShort((short)r);
}
sdl.write(soundBuffer.array(), 0, bufferSize * 2 * 2);
}
public void run()
{
while (alive)
{
tick();
}
}
}
来源:搜素材网素材
搜素材网所有素材均为本站用户上传,仅供学习与参考,请勿用于商业用途,如有侵犯您的版权请联系客服服务QQ
本站提供各类html5响应式模板,前端js素材,网站模板,后台模板素材,程序源码素材。
由于技术有限本站不提供安装服务与bug修复,各类源码只提供分享服务,感谢您的理解。
如果对本站有任何意见请点击右侧侧边栏的反馈意见,我们会及时处理。