示例#1
0
文件: ao.go 项目: bobertlo/go-ao
func NewPlayer(driver int, f Format, options map[string]string) (*Player, error) {
	var cf C.ao_sample_format
	cf.bits = C.int(f.Bits)
	cf.rate = C.int(f.Rate)
	cf.channels = C.int(f.Channels)
	cf.byte_format = C.int(f.Byte_format)
	if f.Matrix == "" {
		cf.matrix = nil
	} else {
		// this string is
		cf.matrix = C.CString(f.Matrix)
	}
	// FIXME: handle options (currently ignored)
	devp := C.ao_open_live(C.int(driver), &cf, nil)
	if cf.matrix != nil {
		C.free(unsafe.Pointer(cf.matrix))
	}
	if devp == nil {
		return nil, fmt.Errorf("could not initialize ao device")
	}
	p := new(Player)
	p.handle = devp
	p.format = f
	return p, nil
}