Exemplo n.º 1
0
        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());
                }
            }
        }
Exemplo n.º 2
0
        public void AllocateRenderResources(uint inMaxFrames)
        {
            MaxFrames = inMaxFrames;
            pcmBuffer = new AVAudioPcmBuffer(Bus.Format, MaxFrames);

            OriginalAudioBufferList = pcmBuffer.AudioBufferList;
            MutableAudioBufferList  = pcmBuffer.MutableAudioBufferList;
        }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
0
        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
            };
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        ///<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));
        }
Exemplo n.º 7
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();
            });
        }
    }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 public void DeallocateRenderResources()
 {
     pcmBuffer = null;
     OriginalAudioBufferList = null;
     MutableAudioBufferList  = null;
 }