FFTW to visual studio?

Hi, I want to use FFTW with visual studio 2008. I have used the following precompiled version of FFTW.

http://www.fi.muni.cz/~xsvobod2/misc/fftw3/

I'm an error saying that ".\SoundPlayer.cpp(79) : error C3861: 'fftw_create_plan': identifier not found"


Following is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio.hpp>
#include <iomanip>
#include <iostream>
using namespace std;
#include <fftw3.h>


int main()
{
    // Load a sound buffer from a wav file
    sf::SoundBuffer Buffer;
    if (!Buffer.LoadFromFile("sound.wav"))
        return EXIT_FAILURE;

    // Display sound informations
    std::cout << "sound.wav :" << std::endl;
    std::cout << " " << Buffer.GetDuration()      << " sec"           << std::endl;
    std::cout << " " << Buffer.GetSampleRate()    << " samples / sec" << std::endl;
    std::cout << " " << Buffer.GetChannelsCount() << " channels"      << std::endl;

    // Create a sound instance and play it
    sf::Sound Sound(Buffer);
    Sound.Play();

    // Loop while the sound is playing
    while (Sound.GetStatus() == sf::Sound::Playing)
    {
        // Display the playing position
        std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";

        // Leave some CPU time for other threads
        sf::Sleep(0.1f);
    }
    std::cout << std::endl;

	std::cout<<"Samples...\n";
	
	// EDIT - get samples from the Buffer object
	const sf::Int16* Samples = Buffer.GetSamples();

	for (int i = 0; i < 100; i++)
	{
		std::cout <<Samples[i];
	}

	//FFT
	std::size_t N = Buffer.GetSamplesCount();
	cout<<"\nNumber of samples(a) :" <<N <<endl;
	fftw_plan p;
	p = fftw_create_plan(940800, 1, FFTW_ESTIMATE);


	system("PAUSE");
    return EXIT_SUCCESS;
}



Did you link with the FFTW libs?
It seems you shall specify name space sf:: before function name 'fftw_create_plan'
As the following

p = sf::fftw_create_plan(940800, 1, FFTW_ESTIMATE);
Last edited on
@kbw, I have included them to visual studio from Tools>Options>VC++ directories. Both the lib folder and the include folder is mentioned there.

And the .lib file is also mentioned in the Additional Dependencies section of the project properties. If that what you mean. Sorry, I'm an inexperienced programmer.
After including the required headers, write
#pragma comment(lib,/*Enter path to lib file here*/)
The path could be a complete path or a path relative to the library paths in the VC++ directories list

This #pragma is specific to Visual Studio
Thanks for the reply eklavya sharma, I was trying to change it according to this guide (http://nashruddin.com/fft-with-fftw-example.html) and then it worked.

Again I have another problem. The algorithm takes a fftw_complex, and output a similar object. What I have is signed 16bit int array. How do I pass this array to the algorithm? And how to read from the receiving data? Thanks.
Again I have another problem. The algorithm takes a fftw_complex, and output a similar object. What I have is signed 16bit int array. How do I pass this array to the algorithm?


You don't need fftw_complex for input data when converting. But you do need floating points.

You need to convert your signed 16 bit array to an array of real numbers (either floats or doubles) which scales the output to [-1, 1]. With 16-bit data, the output is scaled to [-32768, 32767], so the conversion is pretty simple:

1
2
3
4
5
6
7
void ShortToReal(signed short* shrt,double* real,int siz)
{
	for(int i = 0; i < siz; ++i)
	{
		real[i] = shrt[i] / 32768.0;
	}
}


You can the pass that double buffer to fftw_plan_dft_r2c_1d to do the FFT conversion. It will fill an output buffer that is fftw_complex. (r2c = real to complex)

Do your modifications to the fftw_complex buffer, then pass it back to fftw_plan_dft_c2r_1d (c2r = complex to real) to get back pcm samples in the form of floating point... then covert those floating points back to shorts by scaling them up.


EDIT:

Actually you might not have to do any scaling.... The FFT will probably work just as well if you keep the numbers scaled at [-32768, 32767], you'll just be working with much larger numbers in your calculations. You'll still need to convert to doubles/floats though ... no way around that.
Last edited on
Topic archived. No new replies allowed.