allg5/audio.go

38 lines
766 B
Go
Raw Permalink Normal View History

2019-12-19 06:08:52 +00:00
package allg5
/*
#define ALLEGRO_KCM_AUDIO_SRC
#include <allegro5/allegro_audio.h>
*/
import "C"
type Recorder struct {
recorder *C.ALLEGRO_AUDIO_RECORDER
Frequency int
Depth int
}
func NewRecorder(fragments, samples, frequency, depth int) *Recorder {
var depthC C.ALLEGRO_AUDIO_DEPTH
switch depth {
case 16:
depthC = C.ALLEGRO_AUDIO_DEPTH_INT16
default:
depthC = C.ALLEGRO_AUDIO_DEPTH_UINT8
}
var rec = C.al_create_audio_recorder(C.size_t(fragments), C.uint(samples), C.uint(frequency), depthC, C.ALLEGRO_CHANNEL_CONF_1)
if rec == nil {
return nil
}
return &Recorder{rec, frequency, depth}
}
func (r *Recorder) Start() {
C.al_start_audio_recorder(r.recorder)
}
func (r *Recorder) Destroy() {
C.al_destroy_audio_recorder(r.recorder)
}