sample.h
1 /*************************************************************************/
2 /* sample.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef SAMPLE_H
30 #define SAMPLE_H
31 
32 #include "servers/audio_server.h"
33 #include "resource.h"
34 
35 class Sample : public Resource {
36 
37  OBJ_TYPE(Sample, Resource );
38  RES_BASE_EXTENSION("smp");
39 public:
40 
41  enum Format {
42 
43  FORMAT_PCM8,
44  FORMAT_PCM16,
45  FORMAT_IMA_ADPCM
46  };
47 
48  enum LoopFormat {
49  LOOP_NONE,
50  LOOP_FORWARD,
51  LOOP_PING_PONG // not supported in every platform
52 
53  };
54 
55 private:
56 
57  Format format;
58  int length;
59  bool stereo;
60 
61  LoopFormat loop_format;
62  int loop_begin;
63  int loop_end;
64  int mix_rate;
65 
66  RID sample;
67 
68 
69  void _set_data(const Dictionary& p_data);
70  Dictionary _get_data() const;
71 
72 protected:
73 
74  static void _bind_methods();
75 
76 public:
77 
78  void create(Format p_format, bool p_stereo, int p_length);
79 
80  Format get_format() const;
81  bool is_stereo() const;
82  int get_length() const;
83 
84  void set_data(const DVector<uint8_t>& p_buffer);
85  DVector<uint8_t> get_data() const;
86 
87  void set_mix_rate(int p_rate);
88  int get_mix_rate() const;
89 
90  void set_loop_format(LoopFormat p_format);
91  LoopFormat get_loop_format() const;
92 
93  void set_loop_begin(int p_pos);
94  int get_loop_begin() const;
95 
96  void set_loop_end(int p_pos);
97  int get_loop_end() const;
98 
99  virtual RID get_rid() const;
100  Sample();
101  ~Sample();
102 };
103 
104 VARIANT_ENUM_CAST( Sample::Format );
105 VARIANT_ENUM_CAST( Sample::LoopFormat );
106 
107 #endif // SAMPLE_H
Definition: resource.h:89
Definition: rid.h:47
Definition: dictionary.h:42
Definition: sample.h:35