AnnAudioFile.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "systemMacro.h"
4 #include "AnnTypes.h"
5 
6 #include <OgreSharedPtr.h>
7 #include <OgreResourceManager.h>
8 #include <vector>
9 #include <algorithm>
10 
11 namespace Annwvyn
12 {
14  class AnnDllExport AnnAudioFile : public Ogre::Resource
15  {
18 
20  void readFromStream(Ogre::DataStreamPtr& stream);
21 
23  inline static AnnAudioFile* cast(void* audioFileRawPtr);
24 
25  protected:
27  void loadImpl() override;
28 
30  void unloadImpl() override;
31 
33  size_t calculateSize() const override;
34 
35  public:
37  AnnAudioFile(Ogre::ResourceManager* creator,
38  const Ogre::String& name,
39  Ogre::ResourceHandle handle,
40  const Ogre::String& group,
41  bool isManual = false,
42  Ogre::ManualResourceLoader* loader = nullptr);
43 
44  virtual ~AnnAudioFile();
45 
47  const byte* getData() const;
48 
50  size_t getSize() const override;
51 
52  //Virtual IO interface
53 
56 
58  static sf_count_t sfVioGetFileLen(void* audioFileRawPtr);
59 
61  static sf_count_t sfVioSeek(sf_count_t offset, int whence, void* audioFileRawPtr);
62 
64  static sf_count_t sfVioRead(void* ptr, sf_count_t count, void* audiFileRawPtr);
65 
67  static sf_count_t sfVioWriteDummy(const void*, sf_count_t, void*);
68 
70  static sf_count_t sfVioTell(void* audioFileRawPtr);
71 
73  static SF_VIRTUAL_IO* getSndFileVioStruct();
74 
76  static void clearSndFileVioStruct();
77 
79  size_t sf_offset;
80  };
81 
82  using AnnAudioFilePtr = Ogre::SharedPtr<AnnAudioFile>;
83 
85  class AnnAudioFileManager : public Ogre::ResourceManager, public Ogre::Singleton<AnnAudioFileManager>
86  {
87  protected:
89  Ogre::Resource* createImpl(const Ogre::String& name, Ogre::ResourceHandle handle, const Ogre::String& group, bool isManual, Ogre::ManualResourceLoader* loader, const Ogre::NameValuePairList* createParams) override;
90 
91  public:
94 
95  // ReSharper disable once CppHidingFunction
97  virtual ~AnnAudioFileManager();
98 
100  virtual AnnAudioFilePtr load(const Ogre::String& name, const Ogre::String& group);
101 
104 
107  };
108 }
file for defining macros used for symbol export regarding the way the OS does things.
virtual AnnAudioFilePtr load(const Ogre::String &name, const Ogre::String &group)
Load a file via the AudioFileManager.
std::vector< byte > data
Where the data is actually stored, as bytes.
uint8_t byte
Definition: AnnTypes.h:38
Ogre::SharedPtr< AnnAudioFile > AnnAudioFilePtr
Namespace containing the totality of Annwvyn components.
Definition: AnnGetter.cpp:8
Ogre::Resource * createImpl(const Ogre::String &name, Ogre::ResourceHandle handle, const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader, const Ogre::NameValuePairList *createParams) override
Create the audio file resource itself.
static std::unique_ptr< SF_VIRTUAL_IO > sfVioStruct
Structure that will contain function pointers to all the functions defined below. ...
Ogre resource that contain the data from a binary file for the audio engine importing.
size_t sf_offset
Current cursor position. the only "state" used while reading the file from libsndfile (except for the...
Audio file ResourceManager.
AnnAudioFileManager()
Construct an AnnAudioFileManager. Will register itsel to the Ogre ResourceGroupManager.
Data types definition for Annwvyn.
static AnnAudioFileManager & getSingleton()
Get singleton ref.
#define AnnDllExport
Definition: systemMacro.h:24
static AnnAudioFileManager * getSingletonPtr()
Get singleton pointer.
virtual ~AnnAudioFileManager()
Will unregister itself to the Ogre ResourceGroupManager.