On Sat, Jul 25, 2009 at 8:08 AM, Guilherme Longo<[email protected]> wrote: > Hi every one. > This is my first mail to the list. > Hope I can help you as well. > > I am using the fftw3 library to implement a transform in a array of 5120 > elements . > I have this array from a program that I created modifying the arecord > program. > > If someone could gimme a little help solving that problem. > > I have that array been filled with value in this function: > > static void compute_max_peak(u_char *data, size_t count) > { > signed int val, max, max_peak = 0, perc; > size_t ocount = count; > int arrayt[5120][1], l, cc; > > int t = 0; > int tcount = 0; > > //zero o array > for (cc = 0; cc <= 1; cc++) { > for (l = 0; l <= 5119; l++) { > arrayt[l][cc] = 0; > } > } > > signed short *valp = (signed short *)data; //Dados no buffer > signed short mask = snd_pcm_format_silence_16(hwparams.format); > //Frames de silencio > count /= 2; // 5120 > printf("Count = %i\n", count); > > while (count-- > 0) { > val = *valp++ ^ mask; > val = abs(val); > // armazeno dados nos indices [x][0] > * for (cc = 0; cc <= 0; cc++) { > for (l = tcount; l <= tcount; l++) { > printf("TCOUNT = %i <=> cc = %i\n", tcount, cc); > arrayt[l][cc] = val; > } > }* > tcount++; > > if (max_peak < val) //Armazena a maior amostra em max_peak > max_peak = val; > printf("val[%i] = %i\n", t, val); > t++; > } > > fftw_calculation(arrayt); > > for (cc = 1; cc <= 1; cc++) { > for (l = 0; l <= 5119; l++) { > arrayt[l][cc] = 0; > } > }*/ > > max = 1 << (bits_per_sample-1); //2#15 = 32768 > printf("Max peak (%li samples): %05i (0x%04x) \n", (long)ocount, > max_peak, max_peak); > perc = max_peak * 100 / max; > for (val = 0; val < 20; val++) > if (val <= perc / 5) > putc('#', stdout); > else > putc(' ', stdout); > printf(" %i%%\n", perc); > > for (cc = 0; cc <= 1; cc++) { > for (l = 0; l <= 5119; l++) { > printf("arrayt[%i][%i] = %i\n", l, cc, arrayt[l][cc]); > } > } > } > > and the transform is calculated by this fucntion: > > fftw_calculation(int data[5120][1]) { > > > fftw_complex *out, *in; > fftw_plan p; > int N, l, cc; > > N = 1024; > > in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); > out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); > > in = (fftw_complex *)data; > > for (cc = 0; cc <= 1; cc++) { > for (l = 0; l <= 1023; l++) { > out[l][cc] = 0; > } > } > > p = fftw_plan_dft_1d(N, in, out, -1, FFTW_ESTIMATE); > > fftw_execute(p); > > > for (cc = 0; cc <= 1; cc++) { > for (l = 0; l <= 1023; l++) { > printf("out[%i][%i] = %i\n", l, cc, out[l][cc]); > } > } > > //fftw_destroy_plan(p); > > } > > The problem is, I can't user N as any number higher than 1024, or I get > segfault. > But if you see, the array been transformed is a array of [5120][1] elements. > > Is there anybody here familiar with the fftw3 implementation. > Tks in advanced. > > _______________________________________________ > Linux-audio-dev mailing list > [email protected] > http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev >
I don't know fftw specifically, but I am fairly certain that you need a table size that is an even power of two for fft in general (maybe you can adjust your code to use 4096 or 8192?). _______________________________________________ Linux-audio-dev mailing list [email protected] http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
