// NewOutputAACFile opens a CoreAudio MP4 encapsulated AAC file suitable for output to target.
//
// rate is the sample rate, numchan is the number of channels in the output, and numbits is the number of bits per channel.
// NOTE: In order to prevent unnecessary copying, the calls to target use buffers that are owned by CoreAudio. This means that
// slices should not be made of buffers that will outlive the call to the WriteAt method.
func NewOutputAACFile(target ReadWriterAt, rate float64, numchan int, numbits int) (*AudioFile, error) {
	asbd := C.AudioStreamBasicDescription{
		mSampleRate:       C.Float64(rate),
		mFormatID:         C.kAudioFormatMPEG4AAC,
		mFormatFlags:      C.kMPEG4Object_AAC_Main,
		mChannelsPerFrame: C.UInt32(numchan),
		mFramesPerPacket:  1024,
	}
	return newOutputFile(target, &asbd, C.kAudioFileM4AType)
}
// NewOutputWAVEFile opens a CoreAudio WAVE file suitable for output to target.
//
// rate is the sample rate, numchan is the number of channels in the output, and numbits is the number of bits per channel.
// NOTE: In order to prevent unnecessary copying, the calls to target use buffers that are owned by CoreAudio. This means that
// slices should not be made of buffers that will outlive the call to the WriteAt method.
func NewOutputWAVEFile(target ReadWriterAt, rate float64, numchan int, numbits int) (*AudioFile, error) {
	bpf := C.UInt32(numbits * numchan / 8)
	asbd := C.AudioStreamBasicDescription{
		mSampleRate:       C.Float64(rate),
		mFormatID:         C.kAudioFormatLinearPCM,
		mFormatFlags:      C.kAudioFormatFlagIsSignedInteger | C.kAudioFormatFlagIsPacked,
		mBytesPerPacket:   bpf,
		mFramesPerPacket:  1,
		mBytesPerFrame:    bpf,
		mChannelsPerFrame: C.UInt32(numchan),
		mBitsPerChannel:   C.UInt32(numbits),
	}
	return newOutputFile(target, &asbd, C.kAudioFileWAVEType)
}