PDA

View Full Version : Wav Files



Maluko_Da_Tola
17th September 2010, 13:08
Hello,

I am trying to create and read wav files. Does anyone know of a good c++ library (that will work on Qt creator) or tutorial on this?

Thank you

mcosta
17th September 2010, 13:17
Hi,

I used libsndfile libsndfile (http://www.mega-nerd.com/libsndfile/) with c++ interface.
It's simple to use and has good performance!

Maluko_Da_Tola
17th September 2010, 15:09
Thanks for the posting!

One more question:

I tried to run the following c++ example code from http://parumi.wordpress.com/2007/12/16/how-to-write-wav-files-in-c-using-libsndfile/:

#include <sndfile.hh>

02 #include <iostream>

03 #include <cmath>

04 int main()

05 {

06 const int format=SF_FORMAT_WAV | SF_FORMAT_PCM_16;

07 // const int format=SF_FORMAT_WAV | SF_FORMAT_FLOAT;

08 const int channels=1;

09 const int sampleRate=48000;

10 const char* outfilename="foo.wav";

11

12 SndfileHandle outfile(outfilename, SFM_WRITE, format, channels, sampleRate);

13 if (not outfile) return -1;

14

15 // prepare a 3 seconds buffer and write it

16 const int size = sampleRate*3;

17 float sample[size];

18 float current=0.;

19 for (int i=0; i<size; i++) sample[i]=sin(float(i)/size*M_PI*1500);

20 outfile.write(&sample[0], size);

21 return 0;

22 }


but it gives an errors: undefined reference to 'sf_close' and undefined reference to 'sf_open'! I have added the sndfile.h file to the project folder. Do you know what is wrong?

Thank you

mcosta
17th September 2010, 15:41
You have to link the libsndfile library

Maluko_Da_Tola
17th September 2010, 16:38
How do I link it? Is it not enough to include the libsndfile.h in the project folder?

Cheers

mcosta
17th September 2010, 16:58
If you use qmake you have to add this line to your .pro file


LIBS += -lsndfile


If you are compiling by hand with GCC you have to add "-lsndfile" to command line.

If you using other compiler refer to documentation for linking libraries.

Maluko_Da_Tola
7th October 2010, 01:04
When I do so, Qt displays the following error:

: error: cannot find -lsndfile

Why is it happening?

Cheers

Lykurg
7th October 2010, 06:20
Please show us all relevant parts of your pro file.

nish
7th October 2010, 07:21
you also have to add -L/path/to/libsnd/ in your pro file

Maluko_Da_Tola
11th October 2010, 22:13
It does not work. The project is running on a folder "C:\Qt\2010.04\qt\untitled2". I have added the .lib and the .h files to this folder. My .pro file is the following:

SOURCES += \
main.cpp

HEADERS += \
sndfile.h

LIBS += \
C:\Qt\2010.04\qt\untitled2\libsndfile-1.lib

tbscope
12th October 2010, 06:07
It does not work.
Please explain

Maluko_Da_Tola
14th October 2010, 13:16
It seems that Qt compiles the program well, but the application crashes imediatly, without doing anything. The messages left by the compiler are:

At the Application output:
"Starting C:\Qt\2010.04\qt\untitled2-build-desktop\debug\untitled2.exe...
C:\Qt\2010.04\qt\untitled2-build-desktop\debug\untitled2.exe exited with code -1073741515"

At the compile output:
"Running build steps for project untitled2...
Configuration unchanged, skipping qmake step.
Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug all
mingw32-make[1]: Entering directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
mingw32-make[1]: Nothing to be done for `all'.
mingw32-make[1]: Leaving directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Release all
mingw32-make[1]: Entering directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
mingw32-make[1]: Nothing to be done for `all'.
mingw32-make[1]: Leaving directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
mingw32-make: Leaving directory `C:/Qt/2010.04/qt/untitled2-build-desktop'
The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited normally."

Is this an error with the code or is the libsndfile.lib not linked correctly?

Thank you

stijn
26th November 2010, 16:22
Hello,

I am having the exact same problem. I am trying to use libsndfile in a Qt project under windows. It seems to build fine but crashes on startup. Debugging doesnt seem to help because the crash occurs before entering the first line of the program. Very strange. Did you or anyone find a solution or figure out more about the cause?

Thanks,

Stijn.

Added after 25 minutes:

Hi again,

I went to

http://www.mega-nerd.com/tmp/

and downloaded the pre-release of libsndfile. That solved this problem for me!

Hope it will help you too.

Stijn.

franco.amato
26th November 2010, 16:29
Hello,

I am trying to create and read wav files. Does anyone know of a good c++ library (that will work on Qt creator) or tutorial on this?

Thank you

Hi,
I did some audio processing projects using without problems fmod (http://www.fmod.org/).
It has many features and a very good quality. You can download the ex version here (http://www.fmod.org/index.php/download#FMODExProgrammersAPI).
Regards