在改变价值的同时补偿价值变化?

发布于 2024-08-20 06:53:32 字数 1662 浏览 3 评论 0原文

我试图通过将声音的音调分配给正弦波的路径来将我自己的连续音调调制(颤音)添加到我的 OpenAL 对象中。这是我的回调方法,每 1/30 秒重复一次,以及音调的 getter 和 setter。

#define kMaximumAplitude 0.025
#define kVibratoDegreeIncrements is 45
#define kDegreesToRadians(x) (M_PI * (x) / 180)

- (void)vibratoCallBack:(NSTimer *)timer
       {
       float newPitch = kMaximumAplitude * sin(kDegreesToRadians(vibratoDegreeIncrements));
       self.pitch += newPitch;

       vibratoDegreeIncrements += kVibratoDegreeIncrements;
       }

- (void)setPitch:(ALfloat)newPitch
 {
 pitch = newPitch; 
 alSourcef(sourceID, AL_PITCH, pitch);
 }

- (ALfloat)pitch
 {
 return pitch;
 }

默认音高设置为 1.0,因此上面输出以下正弦波周期:

Wrong Pitch: 1.000000
Wrong Pitch: 1.017678
Wrong Pitch: 1.042678
Wrong Pitch: 1.060355
Wrong Pitch: 1.060355
Wrong Pitch: 1.042678
Wrong Pitch: 1.017678
Wrong Pitch: 1.000000

但是,如果您查看这些数字,它们并不是一个正弦波。据我所知,原因是 self.pitch 与正弦波增量一起添加自身。我希望基本音高(未调制音高)在颤音方法的音高变化之前保持恒定。这样做将使我能够继续使用 UISlider(例如)控制基本音高,同时可以选择性地准确地发生调制效果,而不会影响基本音高。我找不到办法。

下面是我想添加到当前音调的正确正弦波输出:

Correct Pitch: 0.000000
Correct Pitch: 0.017678
Correct Pitch: 0.025000
Correct Pitch: 0.017678
Correct Pitch: 0.000000
Correct Pitch: -0.017678
Correct Pitch: -0.025000
Correct Pitch: -0.017678
Correct Pitch: -0.000000

因此,如果当前未调制的音调为 1.5,我希望输出如下所示:

Desired Pitch: 1.500000
Desired Pitch: 1.517678
Desired Pitch: 1.525000
Desired Pitch: 1.517678
Desired Pitch: 1.500000
Desired Pitch: 1.482322
Desired Pitch: 1.475000
Desired Pitch: 1.482322
Desired Pitch: 1.500000

如何在不真正改变音调的情况下改变音调影响球场?有没有一种方法可以补偿方法内部发生的调制,以便在移动(或可移动)的基音上产生效果?

i'm attempting to add my own continuous pitch modulation (vibrato) to my OpenAL object by assigning the sound's pitch to the path of a sine wave. this is my callback method, which is repeating every 1/30 of a second, as well as the getter and setter for the pitch.

#define kMaximumAplitude 0.025
#define kVibratoDegreeIncrements is 45
#define kDegreesToRadians(x) (M_PI * (x) / 180)

- (void)vibratoCallBack:(NSTimer *)timer
       {
       float newPitch = kMaximumAplitude * sin(kDegreesToRadians(vibratoDegreeIncrements));
       self.pitch += newPitch;

       vibratoDegreeIncrements += kVibratoDegreeIncrements;
       }

- (void)setPitch:(ALfloat)newPitch
 {
 pitch = newPitch; 
 alSourcef(sourceID, AL_PITCH, pitch);
 }

- (ALfloat)pitch
 {
 return pitch;
 }

the default pitch is set at 1.0, so the above outputs the following sine wave cycle:

Wrong Pitch: 1.000000
Wrong Pitch: 1.017678
Wrong Pitch: 1.042678
Wrong Pitch: 1.060355
Wrong Pitch: 1.060355
Wrong Pitch: 1.042678
Wrong Pitch: 1.017678
Wrong Pitch: 1.000000

however, if you look at those numbers they are not much of a sine wave. the reason, as far as i can see, is that self.pitch is adding itself along with the sine wave increments. i would like the base pitch (unmodulated pitch) to remain constant prior to the vibrato method's pitch change. doing so would allow me to continue to control the base pitch using a UISlider (for example) while the modulation effect can optionally and accuratelyoccur without affecting the base pitch. i can't find a way.

below is the proper sine wave output that i would like to add to the current pitch:

Correct Pitch: 0.000000
Correct Pitch: 0.017678
Correct Pitch: 0.025000
Correct Pitch: 0.017678
Correct Pitch: 0.000000
Correct Pitch: -0.017678
Correct Pitch: -0.025000
Correct Pitch: -0.017678
Correct Pitch: -0.000000

therefore, if the current, unmodulated pitch is at 1.5, i would like the output to look like this:

Desired Pitch: 1.500000
Desired Pitch: 1.517678
Desired Pitch: 1.525000
Desired Pitch: 1.517678
Desired Pitch: 1.500000
Desired Pitch: 1.482322
Desired Pitch: 1.475000
Desired Pitch: 1.482322
Desired Pitch: 1.500000

how is it possible to change the pitch without really effecting the pitch? is there a way to compensate for the modulation to take place inside the method so that the effect can occur on a moving (or movable) base pitch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2024-08-27 06:53:32

我认为你只需要把数据分开。让一个音高存储您的基本音高,这将是未经修改的正弦波。然后,您需要另一种方法来产生与基音同步的颤音声波。然后您需要一个 getter 来返回最终波形的当前音调。换句话说,您不需要像现在一样存储最终波形的音高,只需根据需要计算它即可。

- (ALfloat) getFinalPitch
{
return getBasePitch() + getVibratoPitch();
} 

I think you just need to separate the data apart. Have one pitch store your base pitch, which would he an unmodified sine wave. Then you need another method to produce a vibrato sound wave, that is in sync with your base pitch. Then you need a getter to return the current pitch of the final waveform. In other words, you don't need to store the pitch of the final waveform, as you're doing now, you just need to calculate it on demand.

- (ALfloat) getFinalPitch
{
return getBasePitch() + getVibratoPitch();
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文