开发者

Changing duration of Guitar pluck in PCM data

开发者 https://www.devze.com 2023-04-11 12:22 出处:网络
Folks, I am struggling with a simple concept related to the duration of play of PCM data. I would appreciate your feedback.

Folks,

I am struggling with a simple concept related to the duration of play of PCM data. I would appreciate your feedback.

The application I am developing plays guitar notes from a music sheet.

I have implemented Jaffe-Smith Algorithm for guitar plucking.

https://ccrma.stanford.edu/~jos/Mohonk05/Extended_Karplus_Strong_EKS_Algorithm.html.

Let's say I compute sam开发者_JAVA百科ples for note A (440 Hz) for one second.

At the sample rate of 11025, I will be storing 11025 samples that can be send to the computer speakers as PCM audio.

For all the unique notes on the guitar, it takes quite some time to compute samples for all the notes. I am thinking I will pre-compute and save them as binary data and simply load them when the application is run.

So far so good.

Now, let's say I want to play a song (a list of various notes). Let's say the song needs to be played at 100 beats per minute. Let's say I have to play note A for one beat or 0.6 seconds (60/100).

Recalculating samples for 0.6 seconds may take quite some time.

Can I simply play (11025 * 0.6) samples? Will this create any side effect?

Is there a better way to achieve what I am trying to do?

Thank you in advance for your help.

Regards, Peter


What you're basically trying to do is create a synthesized guitar, yes? I might suggest that you go with the sampler route instead.

By sample, I mean a small clip of audio (not a single sample in the sense of ADC or DAC).

Basically, you can flatten what you need into 4 parts:

  • Attack
  • Decay
  • Sustain
  • Release

These four parts work in that order, and are generally referred to as an ADSR envelope. The attack of the note is the initial sound. For a guitar, you are going to hear a pluck and the start of a pitch. The decay is going to be the sample of the string as it starts to fade away. The sustain is a sample repeated over and over again until you release the key. The release sample is what is played when you release the key. For a guitar, you might hear a sample of lightly putting fingers back on the string to stop their vibration.

Now, you could generate all of these samples in real-time, but will likely be very CPU intensive.

Regarding your question: "Can I simply play (11025 * 0.6) samples?" Yes, at a sample rate of 11025, that will be 0.6 seconds of audio. Also keep in mind though that you should be sending a continuous stream of data to the sound card, filling any empty spots with 0 (for signed PCM).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号