Hello,
 I am implementing transceiver based on acoustic waves. Now I have
started with receiver. Input to the receiver is from audio_alsa_source.
I have written a block named packet_detect based on sync_decimator to
accept samples from alsa_source.
Within the packet_detect block , I have been able to detect start of the
frame. Next how can I buffer the data beyond frame start point (ignoring
all the earlier samples) and pass it to the next higher blocks for
processing.
I have pasted packet_detect code below, Please help me.
Thanks in advance
Raman
short pkd_detected=0;
packetdetection::packetdetection(size_t item_size, size_t
nitems_per_block)
 : gr_sync_decimator (“packetdetection”,
         gr_make_io_signature(1,1, item_size),
         gr_make_io_signature(1,1,item_size * nitems_per_block),
         nitems_per_block )
{
   d_offset=0;
   d_sigma1=0;
   d_sigma2=0;
}
Â
/* ----------- transformation process : Phi -------------- */
int
packetdetection::work (int noutput_items,
          gr_vector_const_void_star &input_items,
          gr_vector_void_star &output_items)
{
 size_t block_size = output_signature()->sizeof_stream_item (0);
Â
 const float inbuf = ( const float) input_items[0];
 float outbuf = (float) output_items[0];
 unsigned int i,j,k,itemsize;
 float alpha1=0.125,alpha2=0.875,temp;
Â
 itemsize=block_size/sizeof(float);
Â
     if(!pkd_detected){
    d_sigma1=inbuf;
    for(i=1;i<noutput_items * itemsize;i++) {//for i=2:M
      temp=inbuf[i];
       d_sigma2=alpha1temptemp + alpha2d_sigma1 ;Â
//sigma(i)=alpha*Y(i)*Y(i)+(1-alpha)*sigma(i-1);
       d_sigma1=d_sigma2;
       if( d_sigma2>0.08){
     Â
       pkd_detected=1;
       printf(“packet detected at %d \n”,i);
       for(k=0;k<(noutput_items *itemsize-i);k++){
           outbuf[k] = inbuf[i];
       }
       d_offset+=k;
     Â
       d_sigma1=0,d_sigma2=0;
        return noutput_items;
       }
     Â
    }
    return noutput_items;
   Â
     }
     else{
 Â
   for(j=d_offset,i=0;j<(noutput_items * itemsize-d_offset);j++,i++){
     outbuf[j] = inbuf[i];
   }
   d_offset+=i;
   return noutput_items;
 Â
     }
  Â
}