]> Sergey Matveev's repositories - go-opus.git/commitdiff
Directly access preprocessor directives
authorHraban Luyat <hraban@0brg.net>
Sun, 11 Mar 2018 18:37:16 +0000 (18:37 +0000)
committerHraban Luyat <hraban@0brg.net>
Sun, 11 Mar 2018 18:37:16 +0000 (18:37 +0000)
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?

encoder.go
opus.go

index cd67484a0fe820bc4ec90d168ffd415f78dde97a..0ffaa66bb29d2ba6ac3d1400d6dfb757a290bbd7 100644 (file)
@@ -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 a7436e21befccaf5e536f8d6f7bbc5a041ca8875..e4e67e01901fd3babbd1805b7e674b5680844205 100644 (file)
--- a/opus.go
+++ b/opus.go
@@ -8,25 +8,18 @@ package opus
 // Link opus using pkg-config.
 #cgo pkg-config: opus
 #include <opus.h>
-
-// 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 (