[LAU] OT(ish): Strange coding problem (audio related)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: LAU Mail List <linux-audio-user@...>
Date: Friday, January 28, 2011 - 12:35 am

Hi All,

I have been working on the Neil tracker program recently, and hit a
weird bug that seems to affect only my computer! I get a segfault when
trying to use fft.h (which is used by the oomek 303 emulator, which has
incidentally now been released as open source - a really good sound
IMHO, but I digress). The following test code results in a segfault on
my computer - an AMD XP2500+ (but no-one elses as far as I can tell).

bt:

Program received signal SIGSEGV, Segmentation fault.
0x080486d7 in IFFT (fftBuffer=0x8049b00, fftFrameSize=2048, sign=1) at
fft.h:51
51 tr = *p2r * ur - *p2i * ui;

Any thoughts as to what might be happening?

James

test.cpp:

#include
#include
#include "fft.h"

float a[4096];

int main ()
{
for(int i=0; i<4096; i++)
{
a[i]=0;
}
IFFT(a,2048,1);
printf("%f",a[1]);
}

fft.h:
#define M_PI 3.14159265358979323846

void IFFT(float *fftBuffer, long fftFrameSize, long sign)
/*
FFT routine, (C)1996 S.M.Sprenger. 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 < log(fftFrameSize)/log(2.); k++) {
le <<= 1;
le2 = le>>1;
ur = 1.0;
ui = 0.0;
arg = (float)M_PI / (le2>>1);
wr = (float)cos(arg);
wi = sign*(float)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;
}
}
}

_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[LAU] OT(ish): Strange coding problem (audio related), James Stone, (Fri Jan 28, 12:35 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 3:01 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Fri Jan 28, 11:29 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Fri Jan 28, 12:04 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Fri Jan 28, 1:02 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sat Jan 29, 11:07 am)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Sat Jan 29, 12:47 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Jan 30, 1:29 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Feb 13, 3:30 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sat Jan 29, 12:22 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Sat Jan 29, 12:54 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Philipp Überbacher, (Sun Jan 30, 1:46 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 2:40 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel Beddingfield, (Fri Jan 28, 12:28 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Peter Nelson, (Fri Jan 28, 12:41 pm)
Re: [LAU] OT(ish): Strange coding problem (audio related), Gabriel M. Beddingfield, (Fri Jan 28, 2:31 pm)