gpt4 book ai didi

java - 如何从以毫秒为单位的长度中找到以帧、字节和整数为单位的音符长度

转载 作者:行者123 更新时间:2023-12-03 02:36:38 29 4
gpt4 key购买 nike

我需要在 Java 中创建一个函数,为音频添加一定频率和长度的音符。我的频率是双倍的,音符长度以毫秒为单位。

完整功能说明:
This method takes one AudioInputStream and adds the sound of a certain pure frequency to the FRONT of it, lasting a certain length of time.
So the method takes two additional parameters: frequency and noteLengthInMilliseconds. The amplitude of the additional sound should be 64*256.

但是,我需要在 Frames 以及 Bytes 和 Ints 中找到笔记的长度。

此外,关于如何将音符创建为样本数据数组(我正在使用 java.sound.sampled 包)的任何建议都会有所帮助。

帧和采样率:44100.0hz
编码:PCM_SIGNED

最佳答案

由于您的帧速率和采样率是相同的,假设您指的是 PCM 帧。一个 PCM 帧是每个 channel 一个样本。如果您只有一个音频 channel ,每个样本 16 位,则每两个字节获得一帧。如果您有每个样本 16 位的立体声音频,则每四个字节获得一帧。

要计算长度,请取采样率并将其除以。如果我的采样率为 44.1 kHz,并且我希望音符持续半秒:

44,100 * 0.5 = 22,050 samples (22,050 frames)

如果您知道音频是 16 位,并且只有一个 channel ,则从那里开始:
22,050 * 2 (bytes per channel) * 1 (channels) = 44,100 bytes

关于java - 如何从以毫秒为单位的长度中找到以帧、字节和整数为单位的音符长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42521130/

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