Pregunta

I'm trying to make a simple "virtual scratcher" but I don't know the theory behind it. Since I've found nothing useful on google I'm asking it here:

  • What happen when I scratch (move the track forward)? Do I raise the pitch and/or rate of the sample?
  • How can I emulate this phenomena with audio processing algorithms?

Sample code / tutorials would be reeeally appreciated :-)

¿Fue útil?

Solución

What happen when I scratch (move the track forward)? Do I raise the pitch and/or rate of the sample?

Think about what is actually happening: A record contains audio data. The record needle reads the audio data from the record. As the record spins, the playback position changes. (It's very similar to watching the playhead move through an audio file in a digital audio editor.)

When you physically spin the record faster, you are increasing the playback rate. The audio is both quicker and higher in pitch. Increase the playback rate by two and the audio will playback an octave higher.

When you physically spin the record slower, you are decreasing the playback rate. The audio is both slower and lower in pitch. Decrease the playback rate by two and the audio will playback an octave lower.

Records can only modify the audio playback by speeding up or slowing down the physical record, this effects both pitch and playback rate together. Some audio software can change the pitch and rate independently. Record players can not.

(Get a record player and experiment to hear what it sounds like.)

How can I emulate this phenomena with audio processing algorithms?

To emulate a DJ scratching a record you need to be able to adjust the playback rate of the audio as the user is "scratching".

When the user speeds up the record, speed up the playback rate. When the user slows the record, slow the playback rate.

When the user stops the record, stop playback altogether.

When the user spins the record in reverse, reverse the playback.

You don't need to change the pitch of the audio. Changing the playback rate will do that automatically. Any further adjustments to the pitch will sound incorrect.

I don't have any advice with regard to libraries but something like this isn't too difficult to implement if you take your time.

Otros consejos

When you scratch, you're just moving the record back and forth under the needle. So it's equivalent to looping forward and backwards repeatedly over the same part of the audio file. I would guess that the speed is somewhere between a sine wave and a triangle wave. You'll need to do linear interpolation on the sample.

For a mobile app, I'd start by mapping one axis of the screen to a time range in the audio file. Keep a buffer containing the last MotionEvent. When the next MotionEvent arrives, calculate the mapped start and end positions based on the (X,Y) coordinates. Then, calculate the elapsed time between the two MotionEvents. This gives you enough information to play from the file at the right position and speed, constantly updating with each motion event.

You might need to do some kind of smoothing on the data, but this is a starting point.

A variable rate resampler might be appropriate. This will speed up the play rate and increase the pitch by the same ratio.

You would track ratio between the angular velocity of the "scratch" movement and the normal rate of platter rotation, and use that as the local resampling ratio.

There are a lot better (higher audio quality) DSP methods of doing rate resampling than linear interpolation, such as using a variable width Sinc interpolation kernel.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top