⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 esdmixer.java

📁 java处理声音文件
💻 JAVA
字号:
/* *	EsdMixer.java *//* *  Copyright (c) 1999, 2000 by Matthias Pfisterer <Matthias.Pfisterer@gmx.de> * * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU Library General Public License as published *   by the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU Library General Public License for more details. * *   You should have received a copy of the GNU Library General Public *   License along with this program; if not, write to the Free Software *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */package	org.tritonus.sampled.mixer.esd;import	java.util.Arrays;import	java.util.HashMap;import	java.util.Map;import	java.util.HashSet;import	java.util.Set;import	java.util.Iterator;import	javax.sound.sampled.AudioFormat;import	javax.sound.sampled.AudioSystem;import	javax.sound.sampled.Clip;import	javax.sound.sampled.DataLine;import	javax.sound.sampled.SourceDataLine;import	javax.sound.sampled.TargetDataLine;import	javax.sound.sampled.LineUnavailableException;import	javax.sound.sampled.Line;import	javax.sound.sampled.Mixer;import	org.tritonus.TDebug;import	org.tritonus.sampled.mixer.TMixer;import	org.tritonus.sampled.mixer.TMixerInfo;import	org.tritonus.sampled.mixer.TSoftClip;import	org.tritonus.util.GlobalInfo;public class EsdMixer	extends		TMixer{	// default buffer size in bytes.	private static final int	DEFAULT_BUFFER_SIZE = 32768;	private static AudioFormat[]	FORMATS =	{		// hack for testing.		// new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 11025/*AudioSystem.NOT_SPECIFIED*/, 16, 1, 2, 11025/*AudioSystem.NOT_SPECIFIED*/, false),		// Formats supported directely by esd.		new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, 1, 1, AudioSystem.NOT_SPECIFIED, true),		new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, 1, 1, AudioSystem.NOT_SPECIFIED, false),		new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, 2, 2, AudioSystem.NOT_SPECIFIED, true),		new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, AudioSystem.NOT_SPECIFIED, 8, 2, 2, AudioSystem.NOT_SPECIFIED, false),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 16, 1, 2, AudioSystem.NOT_SPECIFIED, false),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 16, 2, 4, AudioSystem.NOT_SPECIFIED, false),		/*		 *	Format supported through "simple" conversions.		 *	"Simple" conversions are changes in the byte order		 *	and changing signed/unsigned for 8 bit.		 */		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, 1, 1, AudioSystem.NOT_SPECIFIED, true),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, 1, 1, AudioSystem.NOT_SPECIFIED, false),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, 2, 2, AudioSystem.NOT_SPECIFIED, true),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 8, 2, 2, AudioSystem.NOT_SPECIFIED, false),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 16, 1, 2, AudioSystem.NOT_SPECIFIED, true),		new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioSystem.NOT_SPECIFIED, 16, 2, 4, AudioSystem.NOT_SPECIFIED, true),	};	private static Line.Info[]	SOURCE_LINE_INFOS =	{		new DataLine.Info(SourceDataLine.class, FORMATS, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED),	};	private static Line.Info[]	TARGET_LINE_INFOS =	{		new DataLine.Info(TargetDataLine.class, FORMATS, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED),	};	public EsdMixer()	{		super(new TMixerInfo(			"Esd Mixer",			GlobalInfo.getVendor(),			"Mixer for the Enlightened Sound Daemon (esd) running on the local machine",			GlobalInfo.getVersion()),		      new Line.Info(Mixer.class),		      Arrays.asList(FORMATS),		      Arrays.asList(FORMATS),		      Arrays.asList(SOURCE_LINE_INFOS),		      Arrays.asList(TARGET_LINE_INFOS));		if (TDebug.TraceMixer)		{			TDebug.out("EsdMixer.<init>: beginning.");		}		if (TDebug.TraceMixer)		{			TDebug.out("EsdMixer.<init>: end.");		}	}	//////////////// Line //////////////////////////////////////	// TODO: allow real close and reopen of mixer	public void open()	{	}	public void close()	{	}	// TODO: should do this to be able to report open/active lines	// with getSourceLines() and getTargetLines()	/*	  public void registerChannel(EsdChannel channel)	  {	  int	nFlowID = channel.getFlowID();	  synchronized (m_channels)	  {	  m_channels.put(new Integer(nFlowID), channel);	  }	  }	  public void unregisterChannel(EsdChannel channel)	  {	  int	nFlowID = channel.getFlowID();	  synchronized (m_channels)	  {	  m_channels.remove(new Integer(nFlowID));	  }	  }	*/	//////////////// Mixer //////////////////////////////////////	public Line getLine(Line.Info info)		throws	LineUnavailableException	{		DataLine.Info	dataLineInfo = (DataLine.Info) info;		Class		lineClass = info.getLineClass();		AudioFormat[]	aFormats = dataLineInfo.getFormats();		AudioFormat	format = null;		if (lineClass == SourceDataLine.class)		{			format = getSupportedSourceFormat(aFormats);			return getSourceDataLine(format, dataLineInfo.getMaxBufferSize());		}		else if (lineClass == Clip.class)		{			format = getSupportedSourceFormat(aFormats);			return getClip(format);		}		else if (lineClass == TargetDataLine.class)		{			format = getSupportedTargetFormat(aFormats);			return getTargetDataLine(format, dataLineInfo.getMaxBufferSize());		}		else		{			throw new LineUnavailableException("unknown line class: " + lineClass);		}	}	private AudioFormat getSupportedSourceFormat(AudioFormat[] aFormats)	{		for (int i = 0; i < aFormats.length; i++)		{			if (isSourceFormatSupported(aFormats[i]))			{				return aFormats[i];			}		}		throw new IllegalArgumentException("no line matchine one of the passed formats");	}	private AudioFormat getSupportedTargetFormat(AudioFormat[] aFormats)	{		for (int i = 0; i < aFormats.length; i++)		{			if (isTargetFormatSupported(aFormats[i]))			{				return aFormats[i];			}		}		throw new IllegalArgumentException("no line matchine one of the passed formats");	}/*	public Line.Info getLineInfo(Line.Info info)	{		// TODO:		return null;	}*/	public int getMaxLines(Line.Info info)	{		// TODO:		return 0;	}	//////////////// private //////////////////////////////////////	// nBufferSize is in bytes!	private SourceDataLine getSourceDataLine(AudioFormat format, int nBufferSize)		throws	LineUnavailableException	{		if (TDebug.TraceMixer)		{			TDebug.out("EsdMixer.getSourceDataLine(): format: " + format);			TDebug.out("EsdMixer.getSourceDataLine(): buffer size: " + nBufferSize);		}		if (nBufferSize < 1)		{			nBufferSize = DEFAULT_BUFFER_SIZE;		}		// int			nBufferSizeInBytes = nBufferSize * format.getFrameSize();		EsdSourceDataLine	sourceDataLine = new EsdSourceDataLine(this, format, nBufferSize);		// registerChannel(sourceDataLine);		sourceDataLine.start();		if (TDebug.TraceMixer)		{			TDebug.out("EsdMixer.getSourceDataLine(): returning: " + sourceDataLine);		}		return sourceDataLine;	}	// nBufferSize is in bytes!	private TargetDataLine getTargetDataLine(AudioFormat format, int nBufferSize)		throws	LineUnavailableException	{		int			nBufferSizeInBytes = nBufferSize * format.getFrameSize();		EsdTargetDataLine	targetDataLine = new EsdTargetDataLine(this, format, nBufferSizeInBytes);		// registerChannel(sourceDataLine);		targetDataLine.start();		if (TDebug.TraceMixer)		{			TDebug.out("EsdMixer.getTargetDataLine(): returning: " + targetDataLine);		}		return targetDataLine;	}	private Clip getClip(AudioFormat format)		throws	LineUnavailableException	{		// return new EsdClip(this);		return new TSoftClip(this, format);	}	// -------------------------------------------------------------}/*** EsdMixer.java ***/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -