Beispiel #1
0
// Close closes the AudioFile and releases the reference to it.
//
// When used with ExtAudioFile this function must not be called while the ExtAudioFile is still in use.
func (af *AudioFile) Close() error {
	if af.id == nil {
		return nil
	}
	stat := C.AudioFileClose(af.id)
	af.id = nil
	runtime.SetFinalizer(af, nil)
	return osStatus(stat)
}
Beispiel #2
0
func newOutputFile(target ReadWriterAt, asbd *C.AudioStreamBasicDescription, fileType C.AudioFileTypeID) (*AudioFile, error) {
	af := AudioFile{
		target: target,
	}

	stat := C.AudioFileInitializeWithCallbacks(unsafe.Pointer(&af), (*[0]byte)(C.go_audiofile_readproc), (*[0]byte)(C.go_audiofile_writeproc),
		(*[0]byte)(C.go_audiofile_getsizeproc), nil, fileType, asbd, 0, &af.id)
	if stat != 0 {
		return nil, osStatus(stat)
	}
	runtime.SetFinalizer(&af, func(af *AudioFile) {
		if af.id != nil {
			C.AudioFileClose(af.id)
		}
	})
	return &af, nil
}