報錯信息 fftw: alloc.c:269: assertion failed: p
#include <fftw3.h>
namespace gr {
namespace howto {
peak_extract::sptr
peak_extract::make(int upper_limit,int lower_limit,int samp_rate,bool boolean_timer)
{
return gnuradio::get_initial_sptr
(new peak_extract_impl(upper_limit,lower_limit,samp_rate,boolean_timer));
}
/*
* The private constructor
*/
peak_extract_impl::peak_extract_impl(int upper_limit,int lower_limit,int samp_rate,bool boolean_timer)
: gr::block("peak_extract",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(int))),
d_upper_limit(upper_limit),
d_lower_limit(lower_limit),
d_samp_rate(samp_rate),
d_boolean_timer(boolean_timer),
d_packet_len(packet_len),
d_buffer((fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex)*d_packet_len)),
d_fft_plan(fftwf_plan_dft_1d(d_packet_len, d_buffer, d_buffer, FFTW_FORWARD, FFTW_ESTIMATE))
{}
/*
* Our virtual destructor.
*/
peak_extract_impl::~peak_extract_impl()
{
fftwf_destroy_plan(d_fft_plan);
fftwf_free(d_buffer);
}
void
peak_extract_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required)
{
/* <+forecast+> e.g. ninput_items_required[0] = noutput_items */
ninput_items_required[0] = noutput_items;
}
int
peak_extract_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const gr_complex *in = (const gr_complex *) input_items[0];
int *out = (int *) output_items[0];
memcpy(d_buffer,in,d_packet_len*sizeof(fftwf_complex));
fftwf_execute(d_fft_plan);
int i,index,N;
N=d_packet_len;
//M=sizeof(in) / sizeof(in[0]);
double max,magnitude[N];
double real[N],imag[N];
for(i=0;i<d_packet_len;i++)
{
real[i]=d_buffer[i][0];
imag[i]=d_buffer[i][1];
magnitude[i]=sqrt((real[i]*real[i])+(imag[i]*imag[i]));
}
max=magnitude[0];
for (i=0;i<d_packet_len;i++)
{
if(magnitude[i]>max)
{
max=magnitude[i];
index=i;
}
}
*out=index*d_samp_rate/d_packet_len;
// Do <+signal processing+>
// Tell runtime system how many input items we consumed on
// each input stream.
// consume_each (noutput_items);
// Tell runtime system how many output items we produced.
return noutput_items;
}
} /* namespace howto */
} /* namespace gr */
分配空間的問題。。。發現只要去掉FFTblock就可以了