Choreonoid  1.8
AudioItem.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_MEDIA_PLUGIN_AUDIO_ITEM_H
7 #define CNOID_MEDIA_PLUGIN_AUDIO_ITEM_H
8 
9 #include <cnoid/Item>
10 #include <memory>
11 #include <vector>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class CNOID_EXPORT AudioItem : public Item
17 {
18 public:
19  static void initialize(ExtensionManager* ext);
20 
21  AudioItem();
22  AudioItem(const AudioItem& org);
23 
24  int numChannels() {
25  return numChannels_;
26  }
27 
28  int numFrames() {
29  return samplingData_->size() / numChannels_;
30  }
31 
32  double timeLength() {
33  return numFrames() / samplingRate_;
34  }
35 
36  double samplingRate() {
37  return samplingRate_;
38  }
39 
40  void setOffsetTime(double offset);
41 
42  double offsetTime() {
43  return offsetTime_;
44  }
45 
46  int offsetFrame() {
47  return offsetTime_ * samplingRate_;
48  }
49 
50  const std::vector<float>& samplingData() {
51  return *samplingData_;
52  }
53 
54 protected:
55  ~AudioItem();
56 
57  virtual Item* doDuplicate() const;
58  virtual void doPutProperties(PutPropertyFunction& putProperty);
59  virtual bool store(Archive& archive);
60  virtual bool restore(const Archive& archive);
61 
62 private:
63  std::shared_ptr< std::vector<float> > samplingData_;
64  double offsetTime_;
65  int numChannels_;
66  double samplingRate_;
67  std::string title;
68  std::string copyright;
69  std::string artists;
70  std::string comment;
71  std::string date;
72 
73  void clear();
74  bool loadAudioFile(const std::string& filename, std::ostream& os, Item* parentItem);
75 };
76 
78 
79 };
80 
81 #endif
cnoid::AudioItem::numChannels
int numChannels()
Definition: AudioItem.h:24
cnoid::AudioItem::numFrames
int numFrames()
Definition: AudioItem.h:28
cnoid::ExtensionManager
Definition: ExtensionManager.h:23
cnoid::PutPropertyFunction
Definition: PutPropertyFunction.h:51
cnoid::AudioItemPtr
ref_ptr< AudioItem > AudioItemPtr
Definition: AudioItem.h:77
cnoid::Archive
Definition: Archive.h:22
cnoid::AudioItem
Definition: AudioItem.h:16
cnoid::ref_ptr
Definition: Referenced.h:103
cnoid::AudioItem::samplingRate
double samplingRate()
Definition: AudioItem.h:36
cnoid::AudioItem::offsetFrame
int offsetFrame()
Definition: AudioItem.h:46
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::Item
Definition: Item.h:29
cnoid::AudioItem::timeLength
double timeLength()
Definition: AudioItem.h:32
cnoid::AudioItem::samplingData
const std::vector< float > & samplingData()
Definition: AudioItem.h:50
cnoid::AudioItem::offsetTime
double offsetTime()
Definition: AudioItem.h:42