title: Programmatically increase the pitch of an array of audio samples
body: <p>Hello kind people of the audio computing world,</p>
  
  <p>I have an array of samples that respresent a recording. Let us say that it is 5 seconds at 44100Hz. How would I play this back at an increased pitch? And is it possible to increase and decrease the pitch dynamically? Like have the pitch slowly increase to double the speed and then back down.</p>
  
  <p>In other words I want to take a recording and play it back as if it is being 'scratched' by a d.j. </p>
  
  <p>Pseudocode is always welcomed. I will be writing this up in C. </p>
  
  <p>Thanks,</p>
  
  <hr>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Allow me to clarify my intentions. I want to keep the playback at 44100Hz and so therefore I need to <strong>manipulate the samples before playback</strong>. This is also because I would want to <strong>mix the audio that has an increased pitch with audio that is running at a normal rate</strong>. </p>
  
  <p>Expressed in another way, maybe I need to shrink the audio over the same number of samples somehow? That way when it is played back it will sound faster?</p>
  
  <hr>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Also, I would like to do this myself. No libraries please (unless you feel I could pick through the code and find something interesting). </p>
  
  <hr>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>A sample piece of code written in C that takes 2 arguments (array of samples and pitch factor) and then returns an array of the new audio would be fantastic!</p>
  
  <hr>
  
  <p>PS I've started a bounty on this not because I don't think the answers already given aren't valid. I just thought it would be good to get more feedback on the subject. </p>
  
  <hr>
  
  <hr>
  
  <p><strong>AWARD OF BOUNTY</strong></p>
  
  <p>Honestly I wish I could distribute the bounty over several different answers as they were quite a few that I thought were super helpful. Special shoutout to Daniel for passing me some code and AShelly and Hotpaw2 for putting in such detailed responses. </p>
  
  <p>Ultimately though I used an answer from <a href="https://stackoverflow.com/questions/1125666/how-do-you-do-bicubic-or-other-non-linear-interpolation-of-re-sampled-audio-dat">another SO question</a> referenced by datageist and so the award goes to him. </p>
  
  <p>Thanks again everyone!</p>