OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4SoundLoaders.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2010-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef INC_C4SoundLoaders
17 #define INC_C4SoundLoaders
18 
19 #include <vector>
21 #include "platform/C4SoundSystem.h"
22 
23 namespace C4SoundLoaders
24 {
25  struct SoundInfo
26  {
27  public:
28  double sample_length;
29  uint32_t sample_rate;
30  std::vector<BYTE> sound_data;
31 #if AUDIO_TK == AUDIO_TK_OPENAL
32  ALenum format;
33 #endif
35 
36  SoundInfo(): sound_data(), final_handle(0) {}
37  };
38 
40  {
41  public:
42  static const int OPTION_Raw = 1;
43  public:
47  {
48  next = first_loader;
49  first_loader = this;
50  }
51  virtual ~SoundLoader() {}
52  virtual bool ReadInfo(SoundInfo* info, BYTE* data, size_t data_length, uint32_t options = 0) = 0;
53  };
54 
55 #if AUDIO_TK == AUDIO_TK_OPENAL && defined(__APPLE__)
56  class AppleSoundLoader: public SoundLoader
57  {
58  public:
59  AppleSoundLoader(): SoundLoader() {}
60  virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t);
61  protected:
62  static AppleSoundLoader singleton;
63  };
64 #endif
65 
66 #if AUDIO_TK == AUDIO_TK_OPENAL
67  class VorbisLoader: public SoundLoader
68  {
69  public: // needed by C4MusicFileOgg
71  {
72  public:
74  size_t data_length;
75  size_t data_pos;
76  bool is_data_owned; // if true, dtor will delete data
77  CompressedData(BYTE* data, size_t data_length): data(data), data_length(data_length), data_pos(0), is_data_owned(false) {}
78  CompressedData() : data(nullptr), data_length(0), data_pos(0), is_data_owned(false) {}
79  void SetOwnedData(BYTE* data, size_t data_length)
80  { clear(); this->data=data; this->data_length=data_length; this->data_pos=0; is_data_owned=true; }
81 
83  void clear() { if (is_data_owned) delete [] data; data=nullptr; }
84  };
85  // load from compressed data held in memory buffer
86  static size_t mem_read_func(void* ptr, size_t byte_size, size_t size_to_read, void* datasource);
87  static int mem_seek_func(void* datasource, ogg_int64_t offset, int whence);
88  static int mem_close_func(void* datasource);
89  static long mem_tell_func(void* datasource);
90  // load directly from file
91  static size_t file_read_func(void* ptr, size_t byte_size, size_t size_to_read, void* datasource);
92  static int file_seek_func(void* datasource, ogg_int64_t offset, int whence);
93  static int file_close_func(void* datasource);
94  static long file_tell_func(void* datasource);
95  public:
96  virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t);
97  protected:
99  };
100 #ifndef __APPLE__
101  // non-apple wav loader: using ALUT
102  class WavLoader: public SoundLoader
103  {
104  public:
105  virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t);
106  protected:
108  };
109 #endif // apple
110 
111 #elif AUDIO_TK == AUDIO_TK_SDL_MIXER
112  class SDLMixerSoundLoader: public SoundLoader
113  {
114  public:
115  static SDLMixerSoundLoader singleton;
116  virtual bool ReadInfo(SoundInfo* result, BYTE* data, size_t data_length, uint32_t);
117  };
118 #endif
119 }
120 
121 #endif
CompressedData(BYTE *data, size_t data_length)
static SoundLoader * first_loader
static int mem_seek_func(void *datasource, ogg_int64_t offset, int whence)
static long mem_tell_func(void *datasource)
static int mem_close_func(void *datasource)
uint8_t BYTE
static VorbisLoader singleton
virtual bool ReadInfo(SoundInfo *info, BYTE *data, size_t data_length, uint32_t options=0)=0
std::vector< BYTE > sound_data
struct Mix_Chunk * C4SoundHandle
static size_t mem_read_func(void *ptr, size_t byte_size, size_t size_to_read, void *datasource)
static const int OPTION_Raw
static size_t file_read_func(void *ptr, size_t byte_size, size_t size_to_read, void *datasource)
void SetOwnedData(BYTE *data, size_t data_length)
static WavLoader singleton
virtual bool ReadInfo(SoundInfo *result, BYTE *data, size_t data_length, uint32_t)
static long file_tell_func(void *datasource)
virtual bool ReadInfo(SoundInfo *result, BYTE *data, size_t data_length, uint32_t)
static int file_seek_func(void *datasource, ogg_int64_t offset, int whence)
static int file_close_func(void *datasource)