Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KM3NeT_Audio_Data.cpp
Go to the documentation of this file.
1 #include "KM3NeT_Audio_Data.h"
2 
3 #include <netinet/in.h>
4 
5 #ifdef DEBUG_KM3NET_AUDIO_DATA
6 #include <stdlib.h>
7 #include <iostream>
8 #include <boost/date_time/posix_time/posix_time.hpp>
9 #include <Tools/KM3NeT_Debug.h>
10 #define DEBUG_MSG(str,lev) do { if (((uint8_t)lev)>=KM3NeT_Audio_Data::DEBUG_LEVEL) { DBG_MSG << boost::posix_time::microsec_clock::local_time() << " KM3NET_AUDIO_DATA(" << (void*)this << "): "<< str << '\n'; } }while( false )
11 #else
12 #define DEBUG_MSG(str,lev) do { } while ( false )
13 #endif
14 
15 /**
16  * \author fsimeone
17  */
18 
19 KM3NeT_Audio_Data::KM3NeT_Audio_Data(uint32_t window,uint32_t overlap)
20 {
21  DEBUG_MSG("Constructor",0);
22  if ((window==0)||(overlap==0)||(overlap>=window))
23  {
24  window=STD_WINDOW;
25  overlap=STD_OVERLAP;
26  }
27  window_=window;
28  overlap_=overlap;
30  write_=offset_=0;
31  data_=(real_type*)malloc(window_*sizeof(real_type));
34 }
35 
37 {
38  DEBUG_MSG("Desctructor",0);
39  free(data_);
40 }
41 
43 {
44  DEBUG_MSG("common header frame length="<<header.Common_Header.Frame_Length,1);
45  DEBUG_MSG("common header data type="<<header.Common_Header.Data_Type,1);
46  DEBUG_MSG("common header detector identifier="<<header.Common_Header.Detector_Identifier,1);
47  DEBUG_MSG("common header run number="<<header.Common_Header.Run_Number,1);
48  DEBUG_MSG("common header sequence number="<<header.Common_Header.Sequence_Number,1);
49  DEBUG_MSG("common header seconds="<<header.Common_Header.Time_Stamp_seconds,1);
50  DEBUG_MSG("common header ticks="<<header.Common_Header.Time_Stamp_ticks,1);
51  DEBUG_MSG("common header dom id="<<header.Common_Header.DOM_Identifier,1);
52  DEBUG_MSG("common header dq status="<<header.Common_Header.DQ_Status,1);
53  DEBUG_MSG("common header som status1="<<header.Common_Header.DOM_Status1,1);
54  DEBUG_MSG("common header som status2="<<header.Common_Header.DOM_Status2,1);
55  DEBUG_MSG("common header som status3="<<header.Common_Header.DOM_Status3,1);
56  DEBUG_MSG("common header som status4="<<header.Common_Header.DOM_Status4,1);
57  DEBUG_MSG("common header items="<<header.Common_Header.Number_of_Items,1);
58 
59  DEBUG_MSG("header time info="<<header.Info.Time_Info,1);
60  header.Info.Time_Info=ntohl(header.Info.Time_Info);
61 
63  {
64  DEBUG_MSG("cktime reset",3);
65  DEBUG_MSG("next s="<<next_.Time_Stamp_seconds,3);
66  DEBUG_MSG("next tick="<<next_.Time_Stamp_ticks,3);
67  DEBUG_MSG("head s="<<header.Common_Header.Time_Stamp_seconds,3);
68  DEBUG_MSG("head tick="<<(header.Common_Header.Time_Stamp_ticks+header.Info.Time_Info),3);
69  header_=header;
70  offset_=round(((float)header_.Info.Time_Info)/62.5);
73  write_=0;
74  }
75  else
76  {
77  DEBUG_MSG("cktime NO reset",0);
78  }
79 }
80 
81 bool KM3NeT_Audio_Data::Append(real_type d)
82 {
83  if (data_==NULL) return false;
84  data_[write_]=d;
85  write_++;
86  DEBUG_MSG("append sampling"<<header_.Info.Samplig_Rate,1);
88  if (next_.Time_Stamp_ticks>=62500000)
89  {
90  next_.Time_Stamp_ticks-=62500000;
92  }
93  if (write_ == window_) return true;
94  return false;
95 }
96 
98 {
99  real_type* l_dummy=data_;
100  data_=(real_type*)malloc(window_*sizeof(real_type));
101  memcpy((void*)data_,(void*)(l_dummy+bound_),overlap_*sizeof(real_type));
103  packet->Time.ToA=offset_;
104  packet->Header=header_.Common_Header;
107 
109  while (header_.Common_Header.Time_Stamp_ticks>=62500000)
110  {
113  }
114  return l_dummy;
115 }
#define DEBUG_MSG(str, lev)
bool Append(real_type sample)
Audio_Header header_
#define STD_OVERLAP
struct Info_Word::Info_Word_Bitfield::@0 Bits
uint32_t Time_Stamp_ticks
Acoustic_Time_of_Arrival Time
void Check_time(Audio_Header header)
uint32_t Time_Stamp_seconds
uint8_t Samplig_Rate
Info_Word Info
uint32_t Time_Stamp_seconds
real_type * Get_window(ToA_Packet *packet)
KM3NeT_Audio_Data(uint32_t window=STD_WINDOW, uint32_t overlap=STD_OVERLAP)
uint32_t Detector_Identifier
DAQ_Common_Header Common_Header
union Info_Word::Info_Word_Bitfield Info
DAQ_Common_Header Header
uint32_t Time_Info
#define STD_WINDOW