1 /** 2 Stores audio data loaded from WAV files. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.audiostreamsample; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.audiostream; 25 import godot.resource; 26 /** 27 Stores audio data loaded from WAV files. 28 29 AudioStreamSample stores sound samples loaded from WAV files. To play the stored sound, use an $(D AudioStreamPlayer) (for non-positional audio) or $(D AudioStreamPlayer2D)/$(D AudioStreamPlayer3D) (for positional audio). The sound can be looped. 30 This class can also be used to store dynamically-generated PCM audio data. 31 */ 32 @GodotBaseClass struct AudioStreamSample 33 { 34 package(godot) enum string _GODOT_internal_name = "AudioStreamSample"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ AudioStream _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_data") GodotMethod!(PoolByteArray) getData; 45 @GodotName("get_format") GodotMethod!(AudioStreamSample.Format) getFormat; 46 @GodotName("get_loop_begin") GodotMethod!(long) getLoopBegin; 47 @GodotName("get_loop_end") GodotMethod!(long) getLoopEnd; 48 @GodotName("get_loop_mode") GodotMethod!(AudioStreamSample.LoopMode) getLoopMode; 49 @GodotName("get_mix_rate") GodotMethod!(long) getMixRate; 50 @GodotName("is_stereo") GodotMethod!(bool) isStereo; 51 @GodotName("save_to_wav") GodotMethod!(GodotError, String) saveToWav; 52 @GodotName("set_data") GodotMethod!(void, PoolByteArray) setData; 53 @GodotName("set_format") GodotMethod!(void, long) setFormat; 54 @GodotName("set_loop_begin") GodotMethod!(void, long) setLoopBegin; 55 @GodotName("set_loop_end") GodotMethod!(void, long) setLoopEnd; 56 @GodotName("set_loop_mode") GodotMethod!(void, long) setLoopMode; 57 @GodotName("set_mix_rate") GodotMethod!(void, long) setMixRate; 58 @GodotName("set_stereo") GodotMethod!(void, bool) setStereo; 59 } 60 /// 61 pragma(inline, true) bool opEquals(in AudioStreamSample other) const 62 { return _godot_object.ptr is other._godot_object.ptr; } 63 /// 64 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 65 { _godot_object.ptr = n; return null; } 66 /// 67 pragma(inline, true) bool opEquals(typeof(null) n) const 68 { return _godot_object.ptr is n; } 69 /// 70 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 71 mixin baseCasts; 72 /// Construct a new instance of AudioStreamSample. 73 /// Note: use `memnew!AudioStreamSample` instead. 74 static AudioStreamSample _new() 75 { 76 static godot_class_constructor constructor; 77 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AudioStreamSample"); 78 if(constructor is null) return typeof(this).init; 79 return cast(AudioStreamSample)(constructor()); 80 } 81 @disable new(size_t s); 82 /// 83 enum LoopMode : int 84 { 85 /** 86 Audio does not loop. 87 */ 88 loopDisabled = 0, 89 /** 90 Audio loops the data between $(D loopBegin) and $(D loopEnd), playing forward only. 91 */ 92 loopForward = 1, 93 /** 94 Audio loops the data between $(D loopBegin) and $(D loopEnd), playing back and forth. 95 */ 96 loopPingPong = 2, 97 /** 98 Audio loops the data between $(D loopBegin) and $(D loopEnd), playing backward only. 99 */ 100 loopBackward = 3, 101 } 102 /// 103 enum Format : int 104 { 105 /** 106 8-bit audio codec. 107 */ 108 format8Bits = 0, 109 /** 110 16-bit audio codec. 111 */ 112 format16Bits = 1, 113 /** 114 Audio is compressed using IMA ADPCM. 115 */ 116 formatImaAdpcm = 2, 117 } 118 /// 119 enum Constants : int 120 { 121 format8Bits = 0, 122 loopDisabled = 0, 123 loopForward = 1, 124 format16Bits = 1, 125 loopPingPong = 2, 126 formatImaAdpcm = 2, 127 loopBackward = 3, 128 } 129 /** 130 131 */ 132 PoolByteArray getData() const 133 { 134 checkClassBinding!(typeof(this))(); 135 return ptrcall!(PoolByteArray)(GDNativeClassBinding.getData, _godot_object); 136 } 137 /** 138 139 */ 140 AudioStreamSample.Format getFormat() const 141 { 142 checkClassBinding!(typeof(this))(); 143 return ptrcall!(AudioStreamSample.Format)(GDNativeClassBinding.getFormat, _godot_object); 144 } 145 /** 146 147 */ 148 long getLoopBegin() const 149 { 150 checkClassBinding!(typeof(this))(); 151 return ptrcall!(long)(GDNativeClassBinding.getLoopBegin, _godot_object); 152 } 153 /** 154 155 */ 156 long getLoopEnd() const 157 { 158 checkClassBinding!(typeof(this))(); 159 return ptrcall!(long)(GDNativeClassBinding.getLoopEnd, _godot_object); 160 } 161 /** 162 163 */ 164 AudioStreamSample.LoopMode getLoopMode() const 165 { 166 checkClassBinding!(typeof(this))(); 167 return ptrcall!(AudioStreamSample.LoopMode)(GDNativeClassBinding.getLoopMode, _godot_object); 168 } 169 /** 170 171 */ 172 long getMixRate() const 173 { 174 checkClassBinding!(typeof(this))(); 175 return ptrcall!(long)(GDNativeClassBinding.getMixRate, _godot_object); 176 } 177 /** 178 179 */ 180 bool isStereo() const 181 { 182 checkClassBinding!(typeof(this))(); 183 return ptrcall!(bool)(GDNativeClassBinding.isStereo, _godot_object); 184 } 185 /** 186 Saves the AudioStreamSample as a WAV file to `path`. Samples with IMA ADPCM format can't be saved. 187 $(B Note:) A `.wav` extension is automatically appended to `path` if it is missing. 188 */ 189 GodotError saveToWav(in String path) 190 { 191 checkClassBinding!(typeof(this))(); 192 return ptrcall!(GodotError)(GDNativeClassBinding.saveToWav, _godot_object, path); 193 } 194 /** 195 196 */ 197 void setData(in PoolByteArray data) 198 { 199 checkClassBinding!(typeof(this))(); 200 ptrcall!(void)(GDNativeClassBinding.setData, _godot_object, data); 201 } 202 /** 203 204 */ 205 void setFormat(in long format) 206 { 207 checkClassBinding!(typeof(this))(); 208 ptrcall!(void)(GDNativeClassBinding.setFormat, _godot_object, format); 209 } 210 /** 211 212 */ 213 void setLoopBegin(in long loop_begin) 214 { 215 checkClassBinding!(typeof(this))(); 216 ptrcall!(void)(GDNativeClassBinding.setLoopBegin, _godot_object, loop_begin); 217 } 218 /** 219 220 */ 221 void setLoopEnd(in long loop_end) 222 { 223 checkClassBinding!(typeof(this))(); 224 ptrcall!(void)(GDNativeClassBinding.setLoopEnd, _godot_object, loop_end); 225 } 226 /** 227 228 */ 229 void setLoopMode(in long loop_mode) 230 { 231 checkClassBinding!(typeof(this))(); 232 ptrcall!(void)(GDNativeClassBinding.setLoopMode, _godot_object, loop_mode); 233 } 234 /** 235 236 */ 237 void setMixRate(in long mix_rate) 238 { 239 checkClassBinding!(typeof(this))(); 240 ptrcall!(void)(GDNativeClassBinding.setMixRate, _godot_object, mix_rate); 241 } 242 /** 243 244 */ 245 void setStereo(in bool stereo) 246 { 247 checkClassBinding!(typeof(this))(); 248 ptrcall!(void)(GDNativeClassBinding.setStereo, _godot_object, stereo); 249 } 250 /** 251 Contains the audio data in bytes. 252 $(B Note:) This property expects signed PCM8 data. To convert unsigned PCM8 to signed PCM8, subtract 128 from each byte. 253 */ 254 @property PoolByteArray data() 255 { 256 return getData(); 257 } 258 /// ditto 259 @property void data(PoolByteArray v) 260 { 261 setData(v); 262 } 263 /** 264 Audio format. See $(D format) constants for values. 265 */ 266 @property AudioStreamSample.Format format() 267 { 268 return getFormat(); 269 } 270 /// ditto 271 @property void format(long v) 272 { 273 setFormat(v); 274 } 275 /** 276 The loop start point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present. 277 */ 278 @property long loopBegin() 279 { 280 return getLoopBegin(); 281 } 282 /// ditto 283 @property void loopBegin(long v) 284 { 285 setLoopBegin(v); 286 } 287 /** 288 The loop end point (in number of samples, relative to the beginning of the sample). This information will be imported automatically from the WAV file if present. 289 */ 290 @property long loopEnd() 291 { 292 return getLoopEnd(); 293 } 294 /// ditto 295 @property void loopEnd(long v) 296 { 297 setLoopEnd(v); 298 } 299 /** 300 The loop mode. This information will be imported automatically from the WAV file if present. See $(D loopmode) constants for values. 301 */ 302 @property AudioStreamSample.LoopMode loopMode() 303 { 304 return getLoopMode(); 305 } 306 /// ditto 307 @property void loopMode(long v) 308 { 309 setLoopMode(v); 310 } 311 /** 312 The sample rate for mixing this audio. 313 */ 314 @property long mixRate() 315 { 316 return getMixRate(); 317 } 318 /// ditto 319 @property void mixRate(long v) 320 { 321 setMixRate(v); 322 } 323 /** 324 If `true`, audio is stereo. 325 */ 326 @property bool stereo() 327 { 328 return isStereo(); 329 } 330 /// ditto 331 @property void stereo(bool v) 332 { 333 setStereo(v); 334 } 335 }