public override void SetData(short[] data, int offset) { if (null == Buffer) { Format = new AVAudioFormat(AVAudioCommonFormat.PCMFloat32, (double)Frequency, (uint)(ChannelFormat == AudioChannelFormat.Mono ? 1 : 2), true); Buffer = new AVAudioPcmBuffer(Format, (uint)SampleCount); Buffer.FrameLength = (uint)(SampleCount / sizeof(float)); } unsafe { try { float *f = (float *)Marshal.ReadIntPtr(Buffer.FloatChannelData, 0 * IntPtr.Size); for (int i = 0; i < SampleCount; i++) { f[i] = data[i] / 32767.0f; } } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
public void AllocateRenderResources(uint inMaxFrames) { MaxFrames = inMaxFrames; pcmBuffer = new AVAudioPcmBuffer(Bus.Format, MaxFrames); OriginalAudioBufferList = pcmBuffer.AudioBufferList; MutableAudioBufferList = pcmBuffer.MutableAudioBufferList; }
private void onDataAvailable(AVAudioPcmBuffer buffer, AVAudioTime when) { AudioBuffer audioBuffer = buffer.AudioBufferList[0]; byte[] data = new byte[audioBuffer.DataByteSize]; Marshal.Copy(audioBuffer.Data, data, 0, audioBuffer.DataByteSize); encode(data, 0, data.Length); }
public void Init(AVAudioFormat defaultFormat, uint maxChannels) { MaxFrames = 0; pcmBuffer = null; OriginalAudioBufferList = null; MutableAudioBufferList = null; NSError error; Bus = new AUAudioUnitBus(defaultFormat, out error) { MaximumChannelCount = maxChannels }; }
void Init() { FrequenciesByOctave = new FrequencyDictionary(); for (int i = 0; i < InFlightAudioBuffers; i++) { var buffer = new AVAudioPcmBuffer(AudioFormat, SamplesPerBuffer); AudioBuffers.Add(buffer); } PlayerNode = new AVAudioPlayerNode { Volume = .8f }; AudioEngine.AttachNode(PlayerNode); AudioEngine.Connect(PlayerNode, AudioEngine.MainMixerNode, AudioFormat); AudioEngine.StartAndReturnError(out var error); }
///<Summary> /// Begin playback or resume if paused ///</Summary> public void Play() { if (player == null) { return; } if (!_hasPlayedFirst) { NSError er; var audioFileBuffer = new AVAudioPcmBuffer(audioFile.ProcessingFormat, (uint)audioFile.Length); audioFile.ReadIntoBuffer(audioFileBuffer, out er); player.ScheduleBuffer(audioFileBuffer, null, AVAudioPlayerNodeBufferOptions.Loops, null); _hasPlayedFirst = true; } player.PlayAtTime(new AVAudioTime(0)); }
public void onDecodedData(float[] data) { if (!running) { return; } if (audioPlayer != null) { AVAudioPcmBuffer buffer = new AVAudioPcmBuffer(inputAudioFormat, (uint)data.Length); IntPtr int_data = Marshal.AllocHGlobal(data.Length * sizeof(float)); Marshal.Copy(data, 0, int_data, data.Length); buffer.AudioBufferList.SetData(0, int_data, data.Length); buffer.FrameLength = (uint)data.Length; audioPlayer.ScheduleBuffer(buffer, () => { Marshal.FreeHGlobal(int_data); buffer.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); }); } }
public IOSAudioClip(int samples, AudioChannelFormat channelFormat, int frequency) : base(samples, channelFormat, frequency) { Format = new AVAudioFormat((double)frequency, (uint)(channelFormat == AudioChannelFormat.Mono ? 1 : 2)); Buffer = new AVAudioPcmBuffer(Format, (uint)samples); }
public void DeallocateRenderResources() { pcmBuffer = null; OriginalAudioBufferList = null; MutableAudioBufferList = null; }