Apply a low pass filter to a piece of audio

Hi guys I would like to apply a low pass filter to an audio file. I have this audio file playing through ofSoundPlayer but I believe this is done through FMOD is this correct?

Should I be setting up this audio with ofSoundStreamSetup instead? I am familiar with the DSP stuff, so I just need to get hold of the pointer to the output buffer.

Many thanks in advanced

Hi,
probably using FMOD will be easier, because it already was .wav and .mp3 sound file loading available. Download the FMOD SDK and check out the code examples - that will show you how to enable DSP objects (they already have an LPF DSP object you can use). You can do custom DSP stuff using FMOD as well if you want…again check out the examples.
However to do any of this you will need to modify/extend the ofSoundPlayer class.

The other alternative is to use ofSoundStream (which gives you direct access to the sample buffers), but then you will need to implement some sort of file loading…I recommend LibSndFile for .wav (and other formats, but not mp3) samples.

Hi grimus thanks for your reply. I have just visited the FMOD website. It looks like a very complete solution for sound stuff. I guess I will continue using FMOD to do all the nitty gritty. I will make a nice clean class which extends ofSoundPlayer for reverbs and other fx etc. Will share the code in a day or two.

Mark

1 Like

Yes, please share code. Always! :slight_smile:

OK so I have a ofMTSoundPlayer class that extends ofSoundPlayer.
Because I want to have a HPF applied to the audio (not supported by ofSoundPlayer), I am overriding the play() method.

Here is my code:

  
void ofMTSoundPlayer::play()  
{  
	// if it's a looping sound, we should try to kill it, no?  
	// or else people will have orphan channels that are looping  
	if (bLoop == true){  
		FMOD_Channel_Stop(channel);  
	}  
  
	// if the sound is not set to multiplay, then stop the current,  
	// before we start another  
	if (!bMultiPlay){  
		FMOD_Channel_Stop(channel);  
	}  
  
	FMOD_System_PlaySound(sys, FMOD_CHANNEL_FREE, sound, bPaused, &channel);  
	//FMOD_System_PlayDSP( sys, FMOD_CHANNEL_FREE, hpf1, bPaused, &channel );  
  
	FMOD_Channel_GetFrequency(channel, &internalFreq);  
	FMOD_Channel_SetVolume(channel,volume);  
	FMOD_Channel_SetPan(channel,pan);  
	FMOD_Channel_SetFrequency(channel, internalFreq * speed);  
	FMOD_Channel_SetMode(channel,  (bLoop == true) ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);  
  
	// Create DSP  
	FMOD_System_CreateDSPByType( sys, FMOD_DSP_TYPE_HIGHPASS, &hpf1 );  
	FMOD_Channel_AddDSP( channel, hpf1, NULL );  
  
	//fmod update() should be called every frame - according to the docs.  
	//we have been using fmod without calling it at all which resulted in channels not being able  
	//to be reused.  we should have some sort of global update function but putting it here  
	//solves the channel bug  
	FMOD_System_Update(sys);  
}  

I get the following link-time error:

  
ofMTSoundPlayer.obj : error LNK2019: unresolved external symbol _FMOD_Channel_AddDSP@12 referenced in function "public: void __thiscall ofMTSoundPlayer::play(void)" (?play@ofMTSoundPlayer@@QAEXXZ)  

Any idea what is wrong??? The FMOD_Channel_AddDSP is included with all other FMOD functions in fmod.h and I am linking with fmodex_vc.lib.

I did not understand the previous recommendations in this thread. Are you recommending an FMOD-only implementation, bypassing the ofSoundPlayer class?
The OF implementation of FMOD seems to use an old API … the calls are not done as in the latest documentation.

I am having the same question, and since almost 6 years have passed since the last reply, I’d like to ask: is there any development? Any new way of filtering sound in oF? This question might be stupid, but I am a beginner, so please don’t hate me too much :smiley:

I had fmod filters working in fmod a while back, I’ll see if i have my old code lying around. the error is probably an fmod lib is not being linked too. I don’t remember having that issue at the time though, maybe 3rd party linking has changed.

@hristod i would go for ofxMaxim, I’ve used it recently and I found it really nice, it has all what you need to work with sound. It has different kind of filters, lores, lopass, hipass ,hires and a bandpass
I’ve just added an example using a low res filter to this repository https://github.com/edap/examplesOfxMaxim