void prepareExtAudioFile() { // Opening Audio File _extAudioFile = ExtAudioFile.OpenUrl(_url); // Getting file data format _srcFormat = _extAudioFile.FileDataFormat; // Setting the channel number of the output format same to the input format _dstFormat = AudioUnitUtils.AUCanonicalASBD(_sampleRate, _srcFormat.ChannelsPerFrame); // setting reading format as audio unit cannonical format _extAudioFile.ClientDataFormat = _dstFormat; // getting total frame _totalFrames = _extAudioFile.FileLengthFrames; // Aloocating AudoBufferList _buffer = new MutableAudioBufferList(_srcFormat.ChannelsPerFrame, (int) (sizeof(uint) * _totalFrames)); _numberOfChannels = _srcFormat.ChannelsPerFrame; // Reading all frame into the buffer _extAudioFile.Read((int) _totalFrames, _buffer); }
void prepareExtAudioFile () { // Opening Audio File _extAudioFile = ExtAudioFile.OpenUrl (_url); // Getting file data format _srcFormat = _extAudioFile.FileDataFormat; // Setting the channel number of the output format same to the input format _dstFormat = AudioStreamBasicDescription.CreateLinearPCM (channelsPerFrame: (uint)_srcFormat.ChannelsPerFrame, bitsPerChannel: 32); _dstFormat.FormatFlags |= AudioFormatFlags.IsNonInterleaved; // setting reading format as audio unit cannonical format _extAudioFile.ClientDataFormat = _dstFormat; // getting total frame _totalFrames = _extAudioFile.FileLengthFrames; // Allocating AudioBufferList _buffer = new AudioBuffers (_srcFormat.ChannelsPerFrame); for (int i = 0; i < _buffer.Count; ++i) { int size = (int)(sizeof(uint) * _totalFrames); _buffer.SetData (i, Marshal.AllocHGlobal (size), size); } _numberOfChannels = _srcFormat.ChannelsPerFrame; // Reading all frame into the buffer ExtAudioFileError status; _extAudioFile.Read ((uint)_totalFrames, _buffer, out status); if (status != ExtAudioFileError.OK) throw new ApplicationException (); }