77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'ext/webrtcvad/webrtcvad.c', line 77
static VALUE rb_vad_process(VALUE self, VALUE rb_sample_rate, VALUE rb_audio_frame, VALUE rb_offset, VALUE rb_frame_len) {
int sr = NUM2INT(rb_sample_rate);
int offset = NUM2INT(rb_offset);
int frame_length = NUM2INT(rb_frame_len);
int result;
int16_t *buf = (int16_t*)(StringValuePtr(rb_audio_frame) + offset);
struct vad_instance* ptr;
Data_Get_Struct(self, struct vad_instance, ptr);
result = WebRtcVad_Process(ptr->inst, sr, buf, frame_length);
switch (result) {
case 1:
return INT2NUM(1);
case 0:
return INT2NUM(0);
case -1:
break;
default:
rb_raise(rb_eRuntimeError, "Error while processing frame");
}
return Qnil;
}
|