vol
以下のコードでわかるように、変数を使用して Java でサウンドを再生する関数があります。この変数vol
は 0 から 1 の間の 10 進数です。私が を演奏するとき0
、サウンドは基本的に可能な限り最小の音量になり、1 で演奏するときは可能な限り大きな音量になります。プログラムのサウンドがどのような決定を下しているかを知るにはどうすればよいですか? 与えられた の decibles を知りたいですvol
。
public static final AudioFormat DEFAULTAUDIOFORMAT = new AudioFormat(44100, 16, 2, true, true);
private void generateTone() {
int channels = DEFAULTAUDIOFORMAT.getChannels();
int sampleSizeInBytes = DEFAULTAUDIOFORMAT.getSampleSizeInBits() /8;
float sampleRate = DEFAULTAUDIOFORMAT.getSampleRate();
int timedSample = (int) (sampleRate * msecs / 1000f);
int len = timedSample * channels * sampleSizeInBytes;
int shapeLen = (int) (.05 * timedSample);
buf = new byte[len];
double scale;
for ( int i = 0, j = 0; i < timedSample; ++i )
{
int wave = (int)(vol * 32767.0 * Math.sin(2.0 * Math.PI * hz * i / sampleRate));
scale = 1.0;
if (i <= shapeLen) {
scale = i/(double)shapeLen;
}
else if (i >= timedSample - shapeLen) {
scale = 1.0-((i- timedSample + shapeLen)/(double)(shapeLen-1));
}
wave = (int)(scale * wave);
buf[j++] = (byte)(wave >>> 8);
buf[j++] = (byte) wave;
buf[j++] = (byte)(wave >>> 8);
buf[j++] = (byte) wave;
}
}