title: Objective C variable value not being preserved
body: <p>I'm doing some audio programming for a client and I've come across an issue which I just don't understand. </p>
  
  <p>I have a render callback which is called repeatedly by CoreAudio. Inside this callback I have the following:</p>
  
  <pre><code>// Get the audio sample data
  AudioSampleType *outA = (AudioSampleType *)ioData-&gt;mBuffers[0].mData;
  
  Float32 data;
  
  // Loop over the samples
  for (UInt32 frame = 0; frame &lt; inNumberFrames; frame++) {
  
      // Convert from SInt16 to Float32 just to prove it's possible
      data = (Float32) outA[frame] / (Float32) 32768;
  
      // Convert back to SInt16 to show that everything works as expected
      outA[frame] = (SInt16) round(next * 32768);
  
  }
  </code></pre>
  
  <p>This works as expected which shows there aren't any unexpected rounding errors. </p>
  
  <p>The next thing I want to do is add a small delay. I add a global variable to the class:</p>
  
  <p>i.e. below the @implementation line</p>
  
  <pre><code>Float32 last = 0;
  </code></pre>
  
  <p>Then I use this variable to get a one frame delay:</p>
  
  <pre><code>// Get the audio sample data
  AudioSampleType *outA = (AudioSampleType *)ioData-&gt;mBuffers[0].mData;
  
  Float32 data;
  Float32 next;
  
  // Loop over the samples
  for (UInt32 frame = 0; frame &lt; inNumberFrames; frame++) {
  
      // Convert from SInt16 to Float32 just to prove it's possible
      data = (Float32) outA[frame] / (Float32) 32768;
  
      next = last;
      last = data;
  
  
      // Convert back to SInt16 to show that everything works as expected
      outA[frame] = (SInt16) round(next * 32768);
  
  }
  </code></pre>
  
  <p>This time round there's a strange audio distortion on the signal. </p>
  
  <p>I just can't see what I'm doing wrong! Any advice would be greatly appreciated. </p>