如何在Java中获取所有有效系统AudiOoforMat对象的数组
我正在创建一个可以在Java中播放合成音频的对象,但是我需要能够将其设置为具有操作系统可能播放的最高音频比特率的AudiooFormat。
(合成器生成64位浮动音频,可以将其划分为32位浮点或PCM,24位,16位和8位PCM音频。)
我将需要过滤所有操作系统的有效视听器并选择系统可以使用的比特率最高的格式。
如何获得系统可以播放的所有有声构架的批准数组?
public class AudioSettings {
// instance variables
private int sampleRate;
private AudioFormat audioFormat;
private SourceDataLine sourceDataLine;
public AudioSettings(int sampleRate) {
this.sampleRate = sampleRate;
// get highest possible quality bitrate for system
int highestBitRate = 16;
AudioFormat currentFormat = new AudioFormat(new Encoding("PCM_SIGNED"), (float) sampleRate, highestBitRate,
2, highestBitRate / 8 * 2, sampleRate, true);
for (AudioFormat format : /* What goes here? */) {
if (format.getSampleSizeInBits() > highestBitRate
&& format.isBigEndian()
&& format.getChannels() == 2) {
currentFormat = format;
highestBitRate = format.getSampleSizeInBits();
}
}
audioFormat = currentFormat;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据本文档frpm java 8天,,Java支持最多16位编码,最高的样本率为48 kHz。
IDK如果从那以后有任何进步。例如,必须有Java 17的规范,例如,列出了规格。
至于向系统查询支持的文件类型,在教程中提到使用文件和格式转换器,在最后一节中:学习可用的转换。
According to this document frpm the Java 8 days, Java Sound Technology, Java supports a max of 16-bit encoding, and a highest sample rate of 48 kHz.
IDK if there's been any advancement since then. There must be a specification for Java 17, for example, where the specs are listed.
As far as querying the system for supported file types, there is a mention of in the tutorial Using File and Format Converters, in the last section: Learning What Conversions Are Available.
多亏了@gpasch,我从他的链接中找到了答案。尽管我认为您只需要读取line.info []数组的一个实例,因为它似乎打印出三个完全相同的组。
Thanks to @gpasch I found my answer from his link. Although I think you only need to read one instance of the Line.Info[] array because it seems to print out three groups that are exactly the same.