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


Java TAudioFileFormat类代码示例

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


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

示例1: getDuration

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Returns the duration of the current track, in milliseconds.
 * Currently only works for MP3s.
 * @return the duration, or -1 if no track exists, else the {@code endTime}
 *         field of the beatmap loaded
 * @author Tom Brito (http://stackoverflow.com/a/3056161)
 */
public static int getDuration() {
	if (!trackExists() || lastBeatmap == null)
		return -1;

	if (duration == 0) {
		// TAudioFileFormat method only works for MP3s
		if (lastBeatmap.audioFilename.getName().endsWith(".mp3")) {
			try {
				AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(lastBeatmap.audioFilename);
				if (fileFormat instanceof TAudioFileFormat) {
					Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties();
					Long microseconds = (Long) properties.get("duration");
					duration = (int) (microseconds / 1000);
					return duration;
				}
			} catch (UnsupportedAudioFileException | IOException e) {}
		}

		// fallback: use beatmap end time (often not the track duration)
		duration = lastBeatmap.endTime;
	}
	return duration;
}
 
开发者ID:yugecin,项目名称:opsu-dance,代码行数:31,代码来源:MusicController.java

示例2: updateLength

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Description of the Method
 */
public void updateLength() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    Long dur = (Long) properties.get("duration");
                    long sec = Math.round(dur.longValue() / 1000000.0);
                    s.setLength(sec + "");
                    s.setSaved(false);
                    changed = true;
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:39,代码来源:YassSongList.java

示例3: updateAlbum

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Description of the Method
 */
public void updateAlbum() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    String a = (String) properties.get("album");
                    if (a != null && a.trim().length() > 0) {
                        s.setAlbum(a);
                        s.setSaved(false);
                        changed = true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:40,代码来源:YassSongList.java

示例4: updateYear

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Description of the Method
 */
public void updateYear() {
    int i = getSelectedRow();
    if (i < 0) {
        return;
    }

    boolean changed = false;
    Vector<YassSong> sel = getSelectedSongs();
    for (Enumeration<YassSong> en = sel.elements(); en.hasMoreElements(); ) {
        YassSong s = en.nextElement();

        String dir = s.getDirectory();
        String mp3 = s.getMP3();

        File file = new File(dir + File.separator + mp3);
        if (file.exists()) {
            try {
                AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
                if (baseFileFormat instanceof TAudioFileFormat) {
                    Map<?, ?> properties = baseFileFormat.properties();
                    String y = (String) properties.get("year");
                    if (y != null && y.trim().length() > 0) {
                        s.setYear(y);
                        s.setSaved(false);
                        changed = true;
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (changed) {
        setSaved(false);
    }
    repaint();
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:40,代码来源:YassSongList.java

示例5: AudioFileSegmentReader

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
public AudioFileSegmentReader(AudioInputStream inStream) 
		throws UnsupportedAudioFileException, IOException {
	
    this.inStream = inStream;
    this.streamLength = inStream.available();
    this.audioFileFormat = AudioSystem.getAudioFileFormat(inStream);
    this.audioFormat = this.audioFileFormat.getFormat();
    this.isMpeg = this.audioFormat.getEncoding().toString().startsWith("MPEG");

    openStream();

    this.audioFormat = this.audioInputStream.getFormat(); // needs to be read again in
    // case of mp3s (for wav layer values)
    this.sampleRate = (int) this.audioFormat.getSampleRate();
    this.sampleSizeInBits = this.audioFormat.getSampleSizeInBits();
    this.nChannels = this.audioFormat.getChannels();

    if ((this.isMpeg) && (this.audioFileFormat instanceof TAudioFileFormat)) {
        Map<?, ?> properties = ((TAudioFileFormat) this.audioFileFormat).properties();
        long bitrate = ((Integer) properties.get("mp3.bitrate.nominal.bps")).longValue();
        this.durationMicrosec = ((this.streamLength * 8L) / bitrate) * 1000000L;

    } else {
    	this.durationMicrosec = this.audioInputStream.getFrameLength() * 1000 * 1000 / this.sampleRate;
    }

}
 
开发者ID:AntonioCollarino,项目名称:MusicFeatureExtractor,代码行数:28,代码来源:AudioFileSegmentReader.java

示例6: getData

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Gets the data attribute of the YassUtils class
 *
 * @param s Description of the Parameter
 * @return The data value
 */
public static String[] getData(String s) {
    if (s == null) {
        return null;
    }
    File f = new File(s);
    if (!f.exists()) {
        return null;
    }
    try {
        AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(f);
        if (baseFileFormat instanceof TAudioFileFormat) {
            Map<?, ?> properties = baseFileFormat.properties();
            String artist = (String) properties.get("author");
            String title = (String) properties.get("title");

            String genre;
            s = f.getName();
            int i = s.indexOf(" - ");
            if (i >= 0) {
                if (artist == null || artist.trim().length() < 1) {
                    artist = s.substring(0, i).trim();
                }
                if (title == null || title.trim().length() < 1) {
                    title = s.substring(i + 3).trim();
                    i = title.indexOf("[");
                    if (i > 0) {
                        title = title.substring(0, i).trim();
                    }
                    i = title.lastIndexOf(".");
                    if (i > 0) {
                        title = title.substring(0, i).trim();
                    }
                }
            }

            genre = (String) properties.get("mp3.id3tag.genre");
            if (genre == null) {
                genre = "Unknown";
            }

            String data[] = new String[3];
            data[0] = title;
            data[1] = artist;
            data[2] = genre;
            return data;
        }
    } catch (Exception ignored) {
    }
    return null;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:57,代码来源:YassUtils.java

示例7: determineProperties

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
/**
 * Determines Properties when the File/URL/InputStream is opened.
 */
private void determineProperties() {
	logger.info("Entered determineProperties()!\n");
	
	// Add AudioFileFormat properties.
	// Expect if it is null(something bad happened).
	if (audioFileFormat == null)
		return;
	
	if (! ( audioFileFormat instanceof TAudioFileFormat ))
		audioProperties = new HashMap<>();
	else {
		// Tritonus SPI compliant audio file format.
		audioProperties = ( (TAudioFileFormat) audioFileFormat ).properties();
		
		// Clone the Map because it is not mutable.
		audioProperties = deepCopy(audioProperties);
		
	}
	
	// Add JavaSound properties.
	if (audioFileFormat.getByteLength() > 0)
		audioProperties.put("audio.length.bytes", audioFileFormat.getByteLength());
	if (audioFileFormat.getFrameLength() > 0)
		audioProperties.put("audio.length.frames", audioFileFormat.getFrameLength());
	if (audioFileFormat.getType() != null)
		audioProperties.put("audio.type", audioFileFormat.getType());
	
	// AudioFormat properties.
	AudioFormat audioFormat = audioFileFormat.getFormat();
	if (audioFormat.getFrameRate() > 0)
		audioProperties.put("audio.framerate.fps", audioFormat.getFrameRate());
	if (audioFormat.getFrameSize() > 0)
		audioProperties.put("audio.framesize.bytes", audioFormat.getFrameSize());
	if (audioFormat.getSampleRate() > 0)
		audioProperties.put("audio.samplerate.hz", audioFormat.getSampleRate());
	if (audioFormat.getSampleSizeInBits() > 0)
		audioProperties.put("audio.samplesize.bits", audioFormat.getSampleSizeInBits());
	if (audioFormat.getChannels() > 0)
		audioProperties.put("audio.channels", audioFormat.getChannels());
	// Tritonus SPI compliant audio format.
	if (audioFormat instanceof TAudioFormat)
		audioProperties.putAll( ( (TAudioFormat) audioFormat ).properties());
	
	// Add SourceDataLine
	audioProperties.put("basicplayer.sourcedataline", sourceDataLine);
	
	// Keep this final reference for the lambda expression
	final Map<String,Object> audioPropertiesCopy = audioProperties;
	
	// Notify all registered StreamPlayerListeners
	listeners.forEach(listener -> listener.opened(dataSource, audioPropertiesCopy));
	
	logger.info("Exited determineProperties()!\n");
	
}
 
开发者ID:goxr3plus,项目名称:java-stream-player,代码行数:59,代码来源:StreamPlayer.java

示例8: SignalIterator

import org.tritonus.share.sampled.file.TAudioFileFormat; //导入依赖的package包/类
public SignalIterator(File f) throws UnsupportedAudioFileException, IOException {		
	AudioInputStream ain;
	AudioFileFormat fileFormat;
	AudioFormat format;
	try {
		ain = AudioSystem.getAudioInputStream(f);
		fileFormat = AudioSystem.getAudioFileFormat(f);
		format = ain.getFormat();
	}
	catch (UnsupportedAudioFileException ex) {
		FlacAudioFileReader r = new FlacAudioFileReader();
		ain = r.getAudioInputStream(f);
		fileFormat = r.getAudioFileFormat(ain);
		format = fileFormat.getFormat();
	}
	long length = -1;
	if (fileFormat instanceof TAudioFileFormat) {
		AudioFormat newFormat = new AudioFormat(format.getSampleRate(), 16,
				format.getChannels(), true, false);
		ain = AudioSystem.getAudioInputStream(newFormat, ain);
		format = ain.getFormat();
		long duration = (Long)fileFormat.properties().get("duration");
		length = (long)(duration / 1000000 * format.getSampleRate());
		this.decoded = true;
	}
	else if (fileFormat.getType() == FlacFileFormatType.FLAC) {
		/*
		AudioFormat newFormat = new AudioFormat(format.getSampleRate(), 16,
				format.getChannels(), true, false);
		// Flac2PcmAudioInputStream(ain, newFormat, ?)
		// how to get the number of samples?
		*/
		throw new UnsupportedAudioFileException("FLAC");
	}
	else {
		length = ain.getFrameLength();
		this.decoded = false;
	}
	if (length <= 0)
		throw new IllegalArgumentException("Too short");
	if (length > Integer.MAX_VALUE)
		throw new IllegalArgumentException("Too long");
	AudioFormat.Encoding encoding = format.getEncoding();
	if (encoding != AudioFormat.Encoding.PCM_SIGNED)
		throw new IllegalArgumentException("Unsupported encoding: " + encoding);
	this.hertz = (int)format.getSampleRate();
	this.channels = format.getChannels();
	int bytesPerFrame = format.getFrameSize();
	this.bytesPerSample = bytesPerFrame / channels;
	if (bytesPerSample != 2)
		throw new IllegalArgumentException("16-bit samples required");
	this.bigEndian = format.isBigEndian();
	this.in = new BufferedInputStream(ain, bytesPerFrame * BUFFERED_FRAMES);
	this.maxSample = Math.pow(2, bytesPerSample * 8 - 1);
	this.buffer = new byte[bytesPerFrame];
	this.remaining = (int)length;
}
 
开发者ID:roukaour,项目名称:spectrogram,代码行数:58,代码来源:SignalIterator.java


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