コード例 #1
0
        unsafe void TapPrepare(MTAudioProcessingTap tap, nint maxFrames, ref AudioStreamBasicDescription processingFormat)
        {
            // Store sample rate for CenterFrequency property
            context.SampleRate = processingFormat.SampleRate;

            /* Verify processing format (this is not needed for Audio Unit, but for RMS calculation). */
            VerifyProcessingFormat(processingFormat);

            if (processingFormat.FormatFlags.HasFlag(AudioFormatFlags.IsNonInterleaved))
            {
                context.IsNonInterleaved = true;
            }

            /* Create bandpass filter Audio Unit */

            var audioComponentDescription = AudioComponentDescription.CreateEffect(AudioTypeEffect.BandPassFilter);
            // TODO: https://trello.com/c/GZUGUyH0
            var audioComponent = AudioComponent.FindNextComponent(null, ref audioComponentDescription);

            if (audioComponent == null)
            {
                return;
            }

            AudioUnitStatus error = AudioUnitStatus.NoError;

            AudioUnit.AudioUnit audioUnit = audioComponent.CreateAudioUnit();
            try {
                audioUnit.SetAudioFormat(processingFormat, AudioUnitScopeType.Input);
                audioUnit.SetAudioFormat(processingFormat, AudioUnitScopeType.Output);
            } catch (AudioUnitException) {
                error = AudioUnitStatus.FormatNotSupported;
            }

            if (error == AudioUnitStatus.NoError)
            {
                error = audioUnit.SetRenderCallback(Render, AudioUnitScopeType.Input);
            }

            if (error == AudioUnitStatus.NoError)
            {
                error = audioUnit.SetMaximumFramesPerSlice((uint)maxFrames, AudioUnitScopeType.Global);
            }

            if (error == AudioUnitStatus.NoError)
            {
                error = (AudioUnitStatus)audioUnit.Initialize();
            }

            if (error != AudioUnitStatus.NoError)
            {
                audioUnit.Dispose();
                audioUnit = null;
            }

            context.AudioUnit = audioUnit;
        }
コード例 #2
0
        public static AudioComponent FindComponent(AudioTypeEffect effect)
        {
            var cd = AudioComponentDescription.CreateEffect(effect);

            return(FindComponent(ref cd));
        }
コード例 #3
0
ファイル: AVPlayerEqualizer.cs プロジェクト: mdavid/gMusic
            unsafe void TapPrepare(MTAudioProcessingTap tap, nint maxFrames, ref AudioStreamBasicDescription processingFormat)
            {
                // Store sample rate for CenterFrequency property
                context.SampleRate = processingFormat.SampleRate;

                /* Verify processing format (this is not needed for Audio Unit, but for RMS calculation). */
                VerifyProcessingFormat(processingFormat);

                if (processingFormat.FormatFlags.HasFlag(AudioFormatFlags.IsNonInterleaved))
                {
                    context.IsNonInterleaved = true;
                }

                /* Create bandpass filter Audio Unit */

                var audioComponentDescription = AudioComponentDescription.CreateEffect(AudioTypeEffect.NBandEq);
                // TODO: https://trello.com/c/GZUGUyH0
                var audioComponent = AudioComponent.FindNextComponent(null, ref audioComponentDescription);

                if (audioComponent == null)
                {
                    return;
                }

                var error     = AudioUnitStatus.NoError;
                var audioUnit = audioComponent.CreateAudioUnit();

                try
                {
                    audioUnit.SetFormat(processingFormat, AudioUnitScopeType.Input);
                    audioUnit.SetFormat(processingFormat, AudioUnitScopeType.Output);
                }
                catch (AudioUnitException)
                {
                    error = AudioUnitStatus.FormatNotSupported;
                }

                if (error == AudioUnitStatus.NoError)
                {
                    error = audioUnit.SetRenderCallback(Render, AudioUnitScopeType.Input);
                }

                if (error == AudioUnitStatus.NoError)
                {
                    error = audioUnit.SetMaximumFramesPerSlice((uint)maxFrames, AudioUnitScopeType.Global);
                }

                if (error == AudioUnitStatus.NoError)
                {
                    error = (AudioUnitStatus)audioUnit.Initialize();
                }

                if (error != AudioUnitStatus.NoError)
                {
                    audioUnit.Dispose();
                    audioUnit = null;
                }

                context.AudioUnit = audioUnit;
                uint value = 10;
                uint size  = sizeof(uint);
                var  stat  = AudioUnitSetProperty(audioUnit.Handle, AUNGraphicParams.NumberOfBands, AudioUnitScopeType.Global, 0,
                                                  ref value, size);

                for (var i = 0; i < Parent.Bands.Length; i++)
                {
                    var band = Parent.Bands[i];
                    var freq = context.AudioUnit.SetParameter(AudioUnitParameterType.AUNBandEQFrequency + i, band.Center,
                                                              AudioUnitScopeType.Global);
                    var bypass = context.AudioUnit.SetParameter(AudioUnitParameterType.AUNBandEQBypassBand + i, 0,
                                                                AudioUnitScopeType.Global);
                    SetBand(i, band.Gain);
                    Console.WriteLine(freq);
                }
            }