gpt4 book ai didi

java - 了解 AudioFormat 、 AudioInputStream 和 start 方法的构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:22:59 24 4
gpt4 key购买 nike

我曾尝试编写播放声音文件的程序,但到目前为止还没有成功。我无法理解代码的某些部分:

InputStream is = new FileInputStream("sound file");
AudioFormat af = new AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian); // I don't understand it's constructor
long length ; // length in sample frames
// how cani i know the length of frames ?
AudioInputStream ais = new AudioInputStream( is , af , length );
// open ( ais );
// start playing by invoking start method
  • AudioFormat的构造函数中如何预先知道采样率、文件大小、声道是什么以及最后的2个 boolean 变量?
  • 如何获取样本帧的值(length)
  • 另外,如何调用启动方法?我不想要来自任何行的数据,而是来自保存在文件夹中的文件 (即剪辑)

最佳答案

In addition to the encoding, the audio format includes other properties that further specify the exact arrangement of the data. These include the number of channels, sample rate, sample size, byte order, frame rate, and frame size. Sounds may have different numbers of audio channels: one for mono, two for stereo. The sample rate measures how many "snapshots" (samples) of the sound pressure are taken per second, per channel. (If the sound is stereo rather than mono, two samples are actually measured at each instant of time: one for the left channel, and another for the right channel; however, the sample rate still measures the number per channel, so the rate is the same regardless of the number of channels. This is the standard use of the term.) The sample size indicates how many bits are used to store each snapshot; 8 and 16 are typical values. For 16-bit samples (or any other sample size larger than a byte), byte order is important; the bytes in each sample are arranged in either the "little-endian" or "big-endian" style. For encodings like PCM, a frame consists of the set of samples for all channels at a given point in time, and so the size of a frame (in bytes) is always equal to the size of a sample (in bytes) times the number of channels. However, with some other sorts of encodings a frame can contain a bundle of compressed data for a whole series of samples, as well as additional, non-sample data. For such encodings, the sample rate and sample size refer to the data after it is decoded into PCM, and so they are completely different from the frame rate and frame size.

Link

关于java - 了解 AudioFormat 、 AudioInputStream 和 start 方法的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6863384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com