From: Hraban Luyat Date: Sun, 11 Mar 2018 18:37:16 +0000 (+0000) Subject: Directly access preprocessor directives X-Git-Tag: v2.0.0~24 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c490b1f0797298a29a3adf6f3e746c75be301da5;p=go-opus.git Directly access preprocessor directives Closes issue hraban/opus#9. To be honest I'm not 100% why I didn't do it this way in the first place. Three years have passed, something was probably fixed in CGo, or maybe I was just wrong about this not being possible, all along. Either way, it works on my machine, so that's all the testing you need to do, right? --- diff --git a/encoder.go b/encoder.go index cd67484..0ffaa66 100644 --- a/encoder.go +++ b/encoder.go @@ -68,22 +68,12 @@ bridge_encoder_get_max_bandwidth(OpusEncoder *st, opus_int32 *max_bw) return opus_encoder_ctl(st, OPUS_GET_MAX_BANDWIDTH(max_bw)); } -// Access the preprocessor from CGO -const int CONST_BANDWIDTH_NARROWBAND = OPUS_BANDWIDTH_NARROWBAND; -const int CONST_BANDWIDTH_MEDIUMBAND = OPUS_BANDWIDTH_MEDIUMBAND; -const int CONST_BANDWIDTH_WIDEBAND = OPUS_BANDWIDTH_WIDEBAND; -const int CONST_BANDWIDTH_SUPERWIDEBAND = OPUS_BANDWIDTH_SUPERWIDEBAND; -const int CONST_BANDWIDTH_FULLBAND = OPUS_BANDWIDTH_FULLBAND; - -const int CONST_BITRATE_AUTO = OPUS_AUTO; -const int CONST_BITRATE_MAX = OPUS_BITRATE_MAX; - */ import "C" type Bandwidth int -var ( +const ( // 4 kHz passband Narrowband = Bandwidth(C.OPUS_BANDWIDTH_NARROWBAND) // 6 kHz passband @@ -246,7 +236,7 @@ func (enc *Encoder) SetBitrate(bitrate int) error { // SetBitrateToAuto will allow the encoder to automatically set the bitrate func (enc *Encoder) SetBitrateToAuto() error { - res := C.bridge_encoder_set_bitrate(enc.p, C.opus_int32(C.CONST_BITRATE_AUTO)) + res := C.bridge_encoder_set_bitrate(enc.p, C.opus_int32(C.OPUS_AUTO)) if res != C.OPUS_OK { return Error(res) } @@ -256,7 +246,7 @@ func (enc *Encoder) SetBitrateToAuto() error { // SetBitrateToMax causes the encoder to use as much rate as it can. This can be // useful for controlling the rate by adjusting the output buffer size. func (enc *Encoder) SetBitrateToMax() error { - res := C.bridge_encoder_set_bitrate(enc.p, C.opus_int32(C.CONST_BITRATE_MAX)) + res := C.bridge_encoder_set_bitrate(enc.p, C.opus_int32(C.OPUS_BITRATE_MAX)) if res != C.OPUS_OK { return Error(res) } diff --git a/opus.go b/opus.go index a7436e2..e4e67e0 100644 --- a/opus.go +++ b/opus.go @@ -8,25 +8,18 @@ package opus // Link opus using pkg-config. #cgo pkg-config: opus #include - -// Access the preprocessor from CGO -const int CONST_APPLICATION_VOIP = OPUS_APPLICATION_VOIP; -const int CONST_APPLICATION_AUDIO = OPUS_APPLICATION_AUDIO; -const int CONST_APPLICATION_RESTRICTED_LOWDELAY = OPUS_APPLICATION_RESTRICTED_LOWDELAY; */ import "C" type Application int -// These variables should be constants, but for interoperability with CGO -// they're var. Don't change them, though! -var ( +const ( // Optimize encoding for VoIP - AppVoIP = Application(C.CONST_APPLICATION_VOIP) + AppVoIP = Application(C.OPUS_APPLICATION_VOIP) // Optimize encoding for non-voice signals like music - AppAudio = Application(C.CONST_APPLICATION_AUDIO) + AppAudio = Application(C.OPUS_APPLICATION_AUDIO) // Optimize encoding for low latency applications - AppRestrictedLowdelay = Application(C.CONST_APPLICATION_RESTRICTED_LOWDELAY) + AppRestrictedLowdelay = Application(C.OPUS_APPLICATION_RESTRICTED_LOWDELAY) ) const (