CLAM-Development
1.1
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 #include "SegmentDescriptors.hxx" 00023 #include "Segment.hxx" 00024 00025 namespace CLAM 00026 { 00027 00028 SegmentDescriptors::SegmentDescriptors(Segment* pSegment): Descriptor(eNumAttr) 00029 { 00030 MandatoryInit(); 00031 mpSegment=pSegment; 00032 } 00033 00034 void SegmentDescriptors::DefaultInit() { 00035 mpSegment=0; 00036 mpStats=0; 00037 mSegmentStats=0; 00038 AddFramesD(); 00039 UpdateData(); 00040 } 00041 00042 void SegmentDescriptors::CopyInit(const SegmentDescriptors & copied) { 00043 mpSegment=copied.mpSegment; 00044 mpStats=0; 00045 mSegmentStats=0; 00046 } 00047 00048 const Segment* SegmentDescriptors::GetpSegment() const { 00049 return mpSegment; 00050 } 00051 00052 void SegmentDescriptors::SetpSegment(const Segment* pSegment) { 00053 if (HasFramesD()) 00054 CLAM_ASSERT(mSegmentStats,"SegmentDescriptors::SetpSegment: Frame Prototype must be set before, please call SetFramePrototype"); 00055 mpSegment=pSegment; 00056 if(mpSegment->HasAudio()) 00057 { 00058 //with this operation we may lose pointer reference in Stats! 00059 AddAudioD(); 00060 UpdateData(); 00061 if(HasFramesD()) 00062 mSegmentStats->SetArray(&GetFramesD()); 00063 } 00064 if(mpSegment->HasAudio()) 00065 GetAudioD().SetpAudio(&mpSegment->GetAudio()); 00066 int nFrames=mpSegment->GetnFrames(); 00067 int i; 00068 for (i=0;i<nFrames;i++){ 00069 GetFramesD()[i].SetpFrame(&(mpSegment->GetFrame(i)));} 00070 } 00071 00072 void SegmentDescriptors::SetFramePrototype(const FrameDescriptors& proto, int nFrames) 00073 { 00074 int i; 00075 GetFramesD().Resize(nFrames); 00076 GetFramesD().SetSize(nFrames); 00077 for (i=0;i<nFrames;i++){ 00078 GetFramesD()[i].SetPrototype(proto);} 00079 mSegmentStats= new StatsTmpl<false,FrameDescriptors,FrameDescriptors>(&GetFramesD()); 00080 if(HasMeanD()) 00081 GetMeanD().SetPrototype(proto); 00082 if(HasMaxD()) 00083 GetMaxD().SetPrototype(proto); 00084 if(HasMinD()) 00085 GetMinD().SetPrototype(proto); 00086 if(HasVarianceD()) 00087 GetVarianceD().SetPrototype(proto); 00088 } 00089 00090 void SegmentDescriptors::Compute() 00091 { 00092 /*Overriding compute method in base class because right now I don't know 00093 what to do with member statistics. The best thing would be passing the list of 00094 FrameDescriptors as processing data but then Descriptors would have to be 00095 template and I am not sure that statistics would work, I would need to add 00096 some operators like + on FrameDescriptors.*/ 00097 ConcreteCompute(); 00098 } 00099 00100 void SegmentDescriptors::ConcreteCompute() 00101 { 00102 int nFrames=mpSegment->GetnFrames(); 00103 for (int i=0;i<nFrames;i++) 00104 GetFramesD()[i].Compute(); 00105 if(HasMeanD()) 00106 SetMeanD(mSegmentStats->GetMean()); 00107 if(HasMaxD()) 00108 SetMaxD(mSegmentStats->GetMax()); 00109 if(HasMinD()) 00110 SetMinD(mSegmentStats->GetMin()); 00111 if(HasVarianceD()) 00112 SetVarianceD(mSegmentStats->GetVariance()); 00113 if(HasAudioD()) 00114 GetAudioD().Compute(); 00115 } 00116 00117 } // namespace CLAM 00118