From 9fee0ec4ca0c5b7a334cc29dbb58e76c7a4c736e Mon Sep 17 00:00:00 2001 From: Michiel Van Der Kolk Date: Mon, 11 Jul 2005 15:42:37 +0000 Subject: Songdb java version, source. only 1.5 compatible git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7101 a1c6a512-1295-4272-9138-f99709370657 --- .../convert/TEncodingFormatConversionProvider.java | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 songdbj/org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java (limited to 'songdbj/org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java') diff --git a/songdbj/org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java b/songdbj/org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java new file mode 100644 index 0000000..6b83403 --- /dev/null +++ b/songdbj/org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java @@ -0,0 +1,129 @@ +/* + * TEncodingFormatConversionProvider.java + * + * This file is part of Tritonus: http://www.tritonus.org/ + */ + +/* + * Copyright (c) 2000 by Florian Bomers + * + * + * 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. + * + */ + +/* +|<--- this code is formatted to fit into 80 columns --->| +*/ + +package org.tritonus.share.sampled.convert; + +import java.util.Collection; +import java.util.Iterator; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioSystem; + +import org.tritonus.share.TDebug; +import org.tritonus.share.ArraySet; + + +// this class depends on handling of AudioSystem.NOT_SPECIFIED in AudioFormat.matches() + +/** + * This is a base class for FormatConversionProviders that only + * change the encoding, i.e. they never + * + *

It is assumed that each source format can be encoded to all + * target formats. + *

In the sourceFormats and targetFormats collections that are passed to + * the constructor of this class, fields may be set to AudioSystem.NOT_SPECIFIED. + * This means that it handles all values of that field, but cannot change it. + *

This class prevents that a conversion is done (e.g. for sample rates), + * because the overriding class specified AudioSystem.NOT_SPECIFIED as sample rate, + * meaning it handles all sample rates. + *

Overriding classes must implement at least + * AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream) + * and provide a constructor that calls the protected constructor of this class. + * + * @author Florian Bomers + */ +public abstract class TEncodingFormatConversionProvider +extends TSimpleFormatConversionProvider +{ + protected TEncodingFormatConversionProvider( + Collection sourceFormats, + Collection targetFormats) + { + super(sourceFormats, targetFormats); + } + + + + /** + * This implementation assumes that the converter can convert + * from each of its source formats to each of its target + * formats. If this is not the case, the converter has to + * override this method. + *

When conversion is supported, for every target encoding, + * the fields sample size in bits, channels and sample rate are checked: + *

+ * For this, replaceNotSpecified(sourceFormat, targetFormat) in the base + * class TSimpleFormatConversionProvider is used - and accordingly, the frameSize + * is recalculated with getFrameSize(...) if a field with AudioSystem.NOT_SPECIFIED + * is replaced. Inheriting classes may wish to override this method if the + * default mode of calculating the frame size is not appropriate. + */ + public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat) { + if (TDebug.TraceAudioConverter) { + TDebug.out(">TEncodingFormatConversionProvider.getTargetFormats(AudioFormat.Encoding, AudioFormat):"); + TDebug.out("checking if conversion possible"); + TDebug.out("from: " + sourceFormat); + TDebug.out("to: " + targetEncoding); + } + if (isConversionSupported(targetEncoding, sourceFormat)) { + // TODO: check that no duplicates may occur... + ArraySet result=new ArraySet(); + Iterator iterator = getCollectionTargetFormats().iterator(); + while (iterator.hasNext()) { + AudioFormat targetFormat = iterator.next(); + targetFormat=replaceNotSpecified(sourceFormat, targetFormat); + result.add(targetFormat); + } + if (TDebug.TraceAudioConverter) { + TDebug.out("< returning "+result.size()+" elements."); + } + return result.toArray(EMPTY_FORMAT_ARRAY); + } else { + if (TDebug.TraceAudioConverter) { + TDebug.out("< returning empty array."); + } + return EMPTY_FORMAT_ARRAY; + } + } + +} + +/*** TEncodingFormatConversionProvider.java ***/ -- cgit v1.1