Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone low pass filter
    text
    copied!<p>I'm trying to implement a low-pass filter for an iphone app where I record a sound and then it gets played back slightly muffled; like the voice is coming from another room. </p> <p>I've looked into the different options for audio recording and manipulation and have found it a bit confusing...digital signal processing isn't a strong point at all. I've mainly looked into OpenAL and inside the EFX library there is a filter that specifically does what I need, but EFX is not included on the iPhone. Is there a way of replicating that behaviour using OpenAL for the iPhone? Is there another option such as Audio Units that could provide a solution?</p> <p>Thanks for your help</p> <p>EDIT:</p> <p>So after Tom's answer and links, I've come up with what I think is a correct implementation. However, I'm not getting a muffling effect at all, rather just a decrease in volume. Here's the (summarised) code I have currently:</p> <p>File is recorded using AVAudioRecorder and the following settings:</p> <pre><code>[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; [recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey]; [recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey]; [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; </code></pre> <p>I then read in the file and transform it with the code below:</p> <pre><code>// Read in the file using AudioFileOpenURL AudioFileID fileID = [self openAudioFile:filePath]; // find out how big the actual audio data is UInt32 fileSize = [self audioFileSize:fileID]; // allocate the memory to hold the file SInt16 * outData = (SInt16 *)malloc(fileSize); // Read in the file to outData OSStatus result = noErr; result = AudioFileReadBytes(fileID, false, 0, &amp;fileSize, outData); // close off the file AudioFileClose(fileID); // Allocate memory to hold the transformed values SInt16 * transformData = (SInt16 *)malloc(fileSize); // Start the transform - Need to set alpha to 0.15 or below to have a noticeable affect float alpha = 1; // Code as per Tom's example transformData[0] = outData[0]; for(int sample = 1; sample &lt; fileSize / sizeof(SInt16); sample ++) { transformData[sample] = transformData[sample - 1] + alpha * (outData[sample] - transformData[sample - 1]); } // Add the data to OpenAL buffer NSUInteger bufferID; // grab a buffer ID from openAL alGenBuffers(1, &amp;bufferID); // Add the audio data into the new buffer alBufferData(bufferID,AL_FORMAT_MONO16,transformData,fileSize,44100); </code></pre> <p>So after all that, I then play it through OpenAL using the standard method (I don't think it has any impact on my results so I won't include it here.)</p> <p>I've traced through the results, both before and after transform, and they seem correct to me i.e. the values before vary positively and negatively as I would expect and the for loop is definitely flattening out those values. But as I mentioned before I'm only seeing (what seems to me) a reduction in volume, so I'm able to increase the gain and cancel out what I've just done.</p> <p>It seems that I must be working on the wrong values. Any suggestions of what I'm doing wrong here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload