1 module armos.audio.recorder; 2 3 import derelict.openal.al; 4 /++ 5 +/ 6 class Recorder { 7 public{ 8 /// 9 this(uint rate = 44100, uint size = 1024){ 10 DerelictAL.load(); 11 _rate = rate; 12 _size = size; 13 _device = alcCaptureOpenDevice(null, _rate, AL_FORMAT_STEREO16, _size); 14 } 15 16 ~this(){ 17 stop; 18 alcCaptureCloseDevice(_device); 19 } 20 21 /// 22 const(byte[]) buffer()const{ 23 return _buffer; 24 } 25 26 /// 27 int samples()const{ 28 return _samples; 29 } 30 31 /// 32 Recorder update(){ 33 alcGetIntegerv(_device, ALC_CAPTURE_SAMPLES, cast(ALCsizei)(ALint.sizeof), &_samples); 34 if(_samples > 0){ 35 _buffer = new byte[_samples]; 36 alcCaptureSamples(_device, _buffer.ptr, _samples/2); 37 }else{ 38 _buffer = []; 39 } 40 return this; 41 } 42 43 /// 44 Recorder start(){ 45 alcCaptureStart(_device); 46 return this; 47 } 48 49 /// 50 Recorder stop(){ 51 alcCaptureStop(_device); 52 return this; 53 } 54 }//public 55 56 private{ 57 ALCdevice* _device; 58 int _samples; 59 byte[] _buffer; 60 uint _rate; 61 uint _size; 62 }//private 63 }//class Recorder