CLAM-Development  1.4.0
SegmentDescriptors.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "SegmentDescriptors.hxx"
23 #include "Segment.hxx"
24 
25 namespace CLAM
26 {
27 
29 {
30  MandatoryInit();
31  mpSegment=pSegment;
32 }
33 
34 void SegmentDescriptors::DefaultInit() {
35  mpSegment=0;
36  mpStats=0;
37  mSegmentStats=0;
38  AddFramesD();
39  UpdateData();
40 }
41 
42 void SegmentDescriptors::CopyInit(const SegmentDescriptors & copied) {
43  mpSegment=copied.mpSegment;
44  mpStats=0;
45  mSegmentStats=0;
46 }
47 
49  return mpSegment;
50 }
51 
53  if (HasFramesD())
54  CLAM_ASSERT(mSegmentStats,"SegmentDescriptors::SetpSegment: Frame Prototype must be set before, please call SetFramePrototype");
55  mpSegment=pSegment;
56  if(mpSegment->HasAudio())
57  {
58  //with this operation we may lose pointer reference in Stats!
59  AddAudioD();
60  UpdateData();
61  if(HasFramesD())
62  mSegmentStats->SetArray(&GetFramesD());
63  }
64  if(mpSegment->HasAudio())
65  GetAudioD().SetpAudio(&mpSegment->GetAudio());
66  int nFrames=mpSegment->GetnFrames();
67  int i;
68  for (i=0;i<nFrames;i++){
69  GetFramesD()[i].SetpFrame(&(mpSegment->GetFrame(i)));}
70 }
71 
73 {
74  int i;
75  GetFramesD().Resize(nFrames);
76  GetFramesD().SetSize(nFrames);
77  for (i=0;i<nFrames;i++){
78  GetFramesD()[i].SetPrototype(proto);}
79  mSegmentStats= new StatsTmpl<false,FrameDescriptors,FrameDescriptors>(&GetFramesD());
80  if(HasMeanD())
81  GetMeanD().SetPrototype(proto);
82  if(HasMaxD())
83  GetMaxD().SetPrototype(proto);
84  if(HasMinD())
85  GetMinD().SetPrototype(proto);
86  if(HasVarianceD())
87  GetVarianceD().SetPrototype(proto);
88 }
89 
91 {
92  /*Overriding compute method in base class because right now I don't know
93  what to do with member statistics. The best thing would be passing the list of
94  FrameDescriptors as processing data but then Descriptors would have to be
95  template and I am not sure that statistics would work, I would need to add
96  some operators like + on FrameDescriptors.*/
98 }
99 
101 {
102  int nFrames=mpSegment->GetnFrames();
103  for (int i=0;i<nFrames;i++)
104  GetFramesD()[i].Compute();
105  if(HasMeanD())
106  SetMeanD(mSegmentStats->GetMean());
107  if(HasMaxD())
108  SetMaxD(mSegmentStats->GetMax());
109  if(HasMinD())
110  SetMinD(mSegmentStats->GetMin());
111  if(HasVarianceD())
112  SetVarianceD(mSegmentStats->GetVariance());
113  if(HasAudioD())
114  GetAudioD().Compute();
115 }
116 
117 } // namespace CLAM
118