Example #1
0
// toError returns an error string from the mpg123 integer numeral.
func toError(e C.int) error {
	if e == C.MPG123_OK {
		return nil
	}

	s := C.mpg123_plain_strerror(e)
	err := errors.New(C.GoString(s))

	return err
}
Example #2
0
// Create a new mpg123 decoder instance
func NewDecoder(decoder string) (*Decoder, error) {
	var err C.int
	var mh *C.mpg123_handle
	if decoder != "" {
		mh = C.mpg123_new(nil, &err)
	} else {
		cdecoder := C.CString(decoder)
		defer C.free(unsafe.Pointer(cdecoder))
		mh = C.mpg123_new(cdecoder, &err)
	}
	if mh == nil {
		errstring := C.mpg123_plain_strerror(err)
		defer C.free(unsafe.Pointer(errstring))
		return nil, fmt.Errorf("Error initializing mpg123 decoder: %s", errstring)
	}
	dec := new(Decoder)
	dec.handle = mh
	return dec, nil
}
Example #3
0
func mpg123PlainStrError(errcode C.int) string {
	return C.GoString(C.mpg123_plain_strerror(errcode))
}