I try to implement an iPhone sound processing app using SpeakHere sample app as a starting point. The app involves manipulating buffered audio samples during playback. When I multiply the samples by a fractional number (0.9 for instance) I get noise as a result. The strangest thing about it is that when multiplying samples by whole numbers (like 1.0, 2.0) or adding or subtracting from them the playback sounds as expected.
I'm doing it in the playbackCallback function of AudioPlayer.m with the following code snippet:
//------------------
//If buffer samples are multiplied by 0.9 we get noise. If we multiply it by 1.0 or add to it everything's fine.
short *buffer = (short *)calloc(1, numPackets * 2);
memmove(buffer, bufferReference->mAudioData, numPackets * 2);
for (int i = 0; i < numPackets; i++)
{
buffer[i] *= 0.9;
//buffer[i] *= 1.0;
//buffer[i] += 10.0;
}
memmove(bufferReference->mAudioData, buffer, numPackets * 2);
free(buffer);
buffer = NULL;
//-------------------
The full project could be downloaded here: http://depositfiles.com/files/lmnkq68n8
Could anyone point me to what am I doing wrong? I've been struggling with it for a couple of days already and I'm completely lost.
Thank you!