func OpenAudio(desired, obtained_orNil *AudioSpec) int { if alreadyOpened { panic("more than 1 audio stream currently not supported") } // copy handle to user-defined callback function, if defined // it is perfectly supported to not specify the callback function // in that case you will use default SendAudio semantics // note that if you specify a callback and use SendAudio, a hangup will instead happen // when calling SendAudio if nil != desired.UserDefinedCallback { userDefinedCallback = desired.UserDefinedCallback } else { // default playback (16-bit signed) userDefinedCallback = DownstreamPlaybackS16 PlayLoop = make(chan AudioEvent) } var C_desired, C_obtained *C.SDL_AudioSpec C_desired = new(C.SDL_AudioSpec) C_desired.freq = C.int(desired.Freq) C_desired.format = C.Uint16(desired.Format) C_desired.channels = C.Uint8(desired.Channels) C_desired.samples = C.Uint16(desired.Samples) // there is an unique C callback acting as proxy to the different Go callbacks // see streamContext() C_desired.callback = C.callback_getCallback() if obtained_orNil != nil { if desired != obtained_orNil { C_obtained = new(C.SDL_AudioSpec) } else { C_obtained = C_desired } } status := C.SDL_OpenAudio(C_desired, C_obtained) if status == 0 { alreadyOpened = true } if obtained_orNil != nil { obtained := obtained_orNil obtained.Freq = int(C_obtained.freq) obtained.Format = uint16(C_obtained.format) obtained.Channels = uint8(C_obtained.channels) obtained.Samples = uint16(C_obtained.samples) obtained.Out_Silence = uint8(C_obtained.silence) obtained.Out_Size = uint32(C_obtained.size) } return int(status) }
func OpenAudio(desired, obtained_orNil *AudioSpec) int { var C_desired, C_obtained *C.SDL_AudioSpec C_desired = new(C.SDL_AudioSpec) C_desired.freq = C.int(desired.Freq) C_desired.format = C.Uint16(desired.Format) C_desired.channels = C.Uint8(desired.Channels) C_desired.samples = C.Uint16(desired.Samples) C_desired.callback = C.callback_getCallback() if obtained_orNil != nil { if desired != obtained_orNil { C_obtained = new(C.SDL_AudioSpec) } else { C_obtained = C_desired } } status := C.SDL_OpenAudio(C_desired, C_obtained) if status == 0 { mutex.Lock() opened++ mutex.Unlock() } if obtained_orNil != nil { obtained := obtained_orNil obtained.Freq = int(C_obtained.freq) obtained.Format = uint16(C_obtained.format) obtained.Channels = uint8(C_obtained.channels) obtained.Samples = uint16(C_obtained.samples) obtained.Out_Silence = uint8(C_obtained.silence) obtained.Out_Size = uint32(C_obtained.size) } return int(status) }