Thread: Can anyone get this to build in windows?

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    6

    Can anyone get this to build in windows?

    Hi,

    I found this program on the internet but I can't build it under windows. Here is the link: AwesomeBox | Open-Source Real-Time Pitch-Correction (is that enough hyphens for ya?) Can anyone get it to work? I am using Code::Blocks.

    A couple of things I have already figured out:
    It requires OpenGL
    You have to convert usleep to sleep (and add the <windows.h> header for it to work)
    You have to include <stdio.h> here and there for some functions.

    I finally got it to compile but I am getting some linker errors.

    Thanks

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well... as always, read the error messages and try to fix the problem.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It sounds like it is not currently made to build on Windows, so you're essentially asking someone here to do the port for you, and that is likely to be a lot of work.
    Post some of the specific error messages and see if others can guide you through those instead.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    Hi,

    Thanks for the replies. This is the error message I am getting from the linker. I did modify the code so it would compile by adding some headers but I still get this.

    Code:
    Linking executable: ab.exe
    .objs\smbPitchShift.o:smbPitchShift.cpp:(.text+0x0): multiple definition of `smbPitchShift(float, long, long, long, float, float*, float*)'
    .objs\PitchShifter.o:PitchShifter.cpp:(.text+0x67): first defined here
    .objs\smbPitchShift.o:smbPitchShift.cpp:(.text+0x6b1): multiple definition of `smbFft(float*, long, long)'
    .objs\PitchShifter.o:PitchShifter.cpp:(.text+0x718): first defined here
    .objs\smbPitchShift.o:smbPitchShift.cpp:(.text+0x937): multiple definition of `smbAtan2(double, double)'
    .objs\PitchShifter.o:PitchShifter.cpp:(.text+0x99e): first defined here
    .objs\PitchSource.o:PitchSource.cpp:(.text+0x12d): undefined reference to `RtMidiIn::RtMidiIn(std::string)'
    .objs\PitchSource.o:PitchSource.cpp:(.text+0x345): undefined reference to `RtMidiIn::ignoreTypes(bool, bool, bool)'
    .objs\PitchSource.o:PitchSource.cpp:(.text+0x511): undefined reference to `RtMidiIn::RtMidiIn(std::string)'
    .objs\PitchSource.o:PitchSource.cpp:(.text+0x729): undefined reference to `RtMidiIn::ignoreTypes(bool, bool, bool)'
    .objs\PitchSource.o:PitchSource.cpp:(.text+0x836): undefined reference to `RtMidiIn::getMessage(std::vector<unsigned char, std::allocator<unsigned char> >*)'

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The errors about multiply defined functions probably mean those functions are implemented in a header file, which is included in multiple source files. Move the function definitions out of the header file(s), into a single source file.

    The undefined references mean that some needed code (in compiled form in a library or an object file) is not being supplied to the linker. You need to find the library files, and ensure they are specified in the link. Bear in mind that the order of files specified when linking is often important, particularly when libraries are included in the link.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    Hi,

    I fixed one of the errors. But it is showing an error for this one:

    Code:
    .objs\smbPitchShift.o:smbPitchShift.cpp:(.text+0x6b1): multiple definition of `smbFft(float*, long, long)'
    I did a search for smbFft in the whole project it only showed four hits. All are in this one file. I don't understand why it is showing this. Sorry the code is so long.


    Code:
    #include <string.h>
    #include <math.h>
    #include <stdio.h>
    
    #define M_PI_VAL 3.14159265358979323846
    #define MAX_FRAME_LENGTH 8192
    
    void smbFft(float *fftBuffer, long fftFrameSize, long sign);
    
    
    // -----------------------------------------------------------------------------------------------------------------
    
    
    void smbPitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata)
    /*
    	Routine smbPitchShift(). See top of file for explanation
    	Purpose: doing pitch shifting while maintaining duration using the Short
    	Time Fourier Transform.
    	Author: (c)1999-2009 Stephan M. Bernsee <smb [AT] dspdimension [DOT] com>
    */
    {
    
    	static float gInFIFO[MAX_FRAME_LENGTH];
    	static float gOutFIFO[MAX_FRAME_LENGTH];
    	static float gFFTworksp[2*MAX_FRAME_LENGTH];
    	static float gLastPhase[MAX_FRAME_LENGTH/2+1];
    	static float gSumPhase[MAX_FRAME_LENGTH/2+1];
    	static float gOutputAccum[2*MAX_FRAME_LENGTH];
    	static float gAnaFreq[MAX_FRAME_LENGTH];
    	static float gAnaMagn[MAX_FRAME_LENGTH];
    	static float gSynFreq[MAX_FRAME_LENGTH];
    	static float gSynMagn[MAX_FRAME_LENGTH];
    	static long gRover = false, gInit = false;
    	double magn, phase, tmp, window, real, imag;
    	double freqPerBin, expct;
    	long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;
    
    	/* set up some handy variables */
    	fftFrameSize2 = fftFrameSize/2;
    	stepSize = fftFrameSize/osamp;
    	freqPerBin = sampleRate/(double)fftFrameSize;
    	expct = 2.*M_PI_VAL*(double)stepSize/(double)fftFrameSize;
    	inFifoLatency = fftFrameSize-stepSize;
    	if (gRover == false) gRover = inFifoLatency;
    
    	/* initialize our static arrays */
    	if (gInit == false) {
    		memset(gInFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
    		memset(gOutFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
    		memset(gFFTworksp, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
    		memset(gLastPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
    		memset(gSumPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
    		memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
    		memset(gAnaFreq, 0, MAX_FRAME_LENGTH*sizeof(float));
    		memset(gAnaMagn, 0, MAX_FRAME_LENGTH*sizeof(float));
    		gInit = true;
    	}
    
    	/* main processing loop */
    	for (i = 0; i < numSampsToProcess; i++){
    
    		/* As long as we have not yet collected enough data just read in */
    		gInFIFO[gRover] = indata[i];
    		outdata[i] = gOutFIFO[gRover-inFifoLatency];
    		gRover++;
    
    		/* now we have enough data for processing */
    		if (gRover >= fftFrameSize) {
    			gRover = inFifoLatency;
    
    			/* do windowing and re,im interleave */
    			for (k = 0; k < fftFrameSize;k++) {
    				window = -.5*cos(2.*M_PI_VAL*(double)k/(double)fftFrameSize)+.5;
    				gFFTworksp[2*k] = gInFIFO[k] * window;
    				gFFTworksp[2*k+1] = 0.;
    			}
    
    
    			/* ***************** ANALYSIS ******************* */
    			/* do transform */
    			smbFft(gFFTworksp, fftFrameSize, -1);
    
    			/* this is the analysis step */
    			for (k = 0; k <= fftFrameSize2; k++) {
    
    				/* de-interlace FFT buffer */
    				real = gFFTworksp[2*k];
    				imag = gFFTworksp[2*k+1];
    
    				/* compute magnitude and phase */
    				magn = 2.*sqrt(real*real + imag*imag);
    				phase = atan2(imag,real);
    
    				/* compute phase difference */
    				tmp = phase - gLastPhase[k];
    				gLastPhase[k] = phase;
    
    				/* subtract expected phase difference */
    				tmp -= (double)k*expct;
    
    				/* map delta phase into +/- Pi interval */
    				qpd = tmp/M_PI_VAL;
    				if (qpd >= 0) qpd += qpd&1;
    				else qpd -= qpd&1;
    				tmp -= M_PI_VAL*(double)qpd;
    
    				/* get deviation from bin frequency from the +/- Pi interval */
    				tmp = osamp*tmp/(2.*M_PI_VAL);
    
    				/* compute the k-th partials' true frequency */
    				tmp = (double)k*freqPerBin + tmp*freqPerBin;
    
    				/* store magnitude and true frequency in analysis arrays */
    				gAnaMagn[k] = magn;
    				gAnaFreq[k] = tmp;
    
    			}
    
    			/* ***************** PROCESSING ******************* */
    			/* this does the actual pitch shifting */
    			memset(gSynMagn, 0, fftFrameSize*sizeof(float));
    			memset(gSynFreq, 0, fftFrameSize*sizeof(float));
    			for (k = 0; k <= fftFrameSize2; k++) {
    				index = k*pitchShift;
    				if (index <= fftFrameSize2) {
    					gSynMagn[index] += gAnaMagn[k];
    					gSynFreq[index] = gAnaFreq[k] * pitchShift;
    				}
    			}
    
    			/* ***************** SYNTHESIS ******************* */
    			/* this is the synthesis step */
    			for (k = 0; k <= fftFrameSize2; k++) {
    
    				/* get magnitude and true frequency from synthesis arrays */
    				magn = gSynMagn[k];
    				tmp = gSynFreq[k];
    
    				/* subtract bin mid frequency */
    				tmp -= (double)k*freqPerBin;
    
    				/* get bin deviation from freq deviation */
    				tmp /= freqPerBin;
    
    				/* take osamp into account */
    				tmp = 2.*M_PI_VAL*tmp/osamp;
    
    				/* add the overlap phase advance back in */
    				tmp += (double)k*expct;
    
    				/* accumulate delta phase to get bin phase */
    				gSumPhase[k] += tmp;
    				phase = gSumPhase[k];
    
    				/* get real and imag part and re-interleave */
    				gFFTworksp[2*k] = magn*cos(phase);
    				gFFTworksp[2*k+1] = magn*sin(phase);
    			}
    
    			/* zero negative frequencies */
    			for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.;
    
    			/* do inverse transform */
    			smbFft(gFFTworksp, fftFrameSize, 1);
    
    			/* do windowing and add to output accumulator */
    			for(k=0; k < fftFrameSize; k++) {
    				window = -.5*cos(2.*M_PI_VAL*(double)k/(double)fftFrameSize)+.5;
    				gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
    			}
    			for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k];
    
    			/* shift accumulator */
    			memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float));
    
    			/* move input FIFO */
    			for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize];
    		}
    	}
    }
    
    // -----------------------------------------------------------------------------------------------------------------
    
    
    void smbFft(float *fftBuffer, long fftFrameSize, long sign)
    /*
    	FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse)
    	Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the
    	time domain data in fftBuffer[0...2*fftFrameSize-1]. The FFT array takes
    	and returns the cosine and sine parts in an interleaved manner, ie.
    	fftBuffer[0] = cosPart[0], fftBuffer[1] = sinPart[0], asf. fftFrameSize
    	must be a power of 2. It expects a complex input signal (see footnote 2),
    	ie. when working with 'common' audio signals our input signal has to be
    	passed as {in[0],0.,in[1],0.,in[2],0.,...} asf. In that case, the transform
    	of the frequencies of interest is in fftBuffer[0...fftFrameSize].
    */
    {
    	float wr, wi, arg, *p1, *p2, temp;
    	float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i;
    	long i, bitm, j, le, le2, k;
    
    	for (i = 2; i < 2*fftFrameSize-2; i += 2) {
    		for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) {
    			if (i & bitm) j++;
    			j <<= 1;
    		}
    		if (i < j) {
    			p1 = fftBuffer+i; p2 = fftBuffer+j;
    			temp = *p1; *(p1++) = *p2;
    			*(p2++) = temp; temp = *p1;
    			*p1 = *p2; *p2 = temp;
    		}
    	}
    	for (k = 0, le = 2; k < (long)(log(fftFrameSize)/log(2.)+.5); k++) {
    		le <<= 1;
    		le2 = le>>1;
    		ur = 1.0;
    		ui = 0.0;
    		arg = M_PI_VAL / (le2>>1);
    		wr = cos(arg);
    		wi = sign*sin(arg);
    		for (j = 0; j < le2; j += 2) {
    			p1r = fftBuffer+j; p1i = p1r+1;
    			p2r = p1r+le2; p2i = p2r+1;
    			for (i = j; i < 2*fftFrameSize; i += le) {
    				tr = *p2r * ur - *p2i * ui;
    				ti = *p2r * ui + *p2i * ur;
    				*p2r = *p1r - tr; *p2i = *p1i - ti;
    				*p1r += tr; *p1i += ti;
    				p1r += le; p1i += le;
    				p2r += le; p2i += le;
    			}
    			tr = ur*wr - ui*wi;
    			ui = ur*wi + ui*wr;
    			ur = tr;
    		}
    	}
    }

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    At a guess: is that file smbPitchShift.cpp, or is it a header file? (If it's the latter, you are entitled to go hit somebody, after you move the actual code into a .cpp file.)

  8. #8
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Code:
    #include "smbPitchShift.cpp" // Pitchshifter.cpp
    There's your problem. While it's not technically a header, you are still entitled to go hit them.

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    That was my problem indeed. I just moved everything in smbPitchShift.cpp to Pitchshifter.cpp.

    I fixed those errors. Now I just have the library errors.

    Code:
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x174): undefined reference to `vtable for RtMidiIn'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x1a2): undefined reference to `RtMidiIn::initialize(std::string const&)'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x266): undefined reference to `vtable for RtMidiIn'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x294): undefined reference to `RtMidiIn::initialize(std::string const&)'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x596): undefined reference to `vtable for RtMidiOut'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x5af): undefined reference to `RtMidiOut::initialize(std::string const&)'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x64a): undefined reference to `vtable for RtMidiOut'
    .objs\RtMidi.o:RtMidi.cpp:(.text+0x663): undefined reference to `RtMidiOut::initialize(std::string const&)'
    The program uses the RtMidi. It says in the help file to use the library winmm.lib. Here is the website: The RtMidi Tutorial

    I tired adding the library to the linker options but it doesn't work. I really don't know anything about the linker. Do I need to added other things? Does anyone have any other advice?

    Thanks so much, every one has been very helpful.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    In order to see what's going on, it's probably easiest to make C::B spit out the entire command line. (Under settings->Compiler and debugger->Other settings, and set Compiler logging to full.)

    In that case you should see a bunch of compiling of source code (actually this time you won't, since they are already compiled), and then at the end the linker. You want the linker command to end with "-lwinmm" (with a lowercase L). If it doesn't then that's what you need to fix.

    EDIT: Also looking at that link, you may want to define __WINDOWS_MM__, as it looks like that may enable the Windows-specific parts of the code. Easiest is to do it as they show for the other OSes, by putting -D__WINDOWS_MM__ as a compiler option. You'd have to recompile everything (Ctrl-F11).
    Last edited by tabstop; 01-22-2011 at 08:48 PM.

  11. #11
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    lol I finally got it to build after adding __WINDOWS_MM__ , __WINDOWS_DS__ , and __MINGW32__ to the #define section of the compiler. As soon as I ran it, it froze my computer for about a minute until I was able to kill it. At least it kind-of worked, it was repeating what I was saying in the microphone. I think I messed with the code too much. Now that I learned you have to define and link the libraries properly I will download the source again and try tomorrow.

    Thanks for everyone's help, I will post back if I run into anymore problems.

  12. #12
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    So I downloaded the code again. I created a new project. I added some needed headers, fixed the problem where it would include .cpp files, added some defines for windows. I decided to start fresh because I messed with the code too much. Now I get "undefined reference to `CoUninitialize@0'" multiple times. I googled CoUninitialize and I found this. Should I add -lOle32 to the linker settings. On the RtAudio website it says nothing about CoUninitialize (This happens in RtAudio.cpp). It says under ApiNotes that you should use "-with-ds" I tired that but the compiler doesn't know what it means.

    Here are my current linker settings. How do I know if they are out of order?

    Code:
    -lopengl32
    -lglu32
    -lglut32
    -ldsound
    -lwinmm
    Thanks,
    Mitch88

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM