dsp.getParameterData return ERR_INVALID_PARAM

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using AudioSpectrumStudy.Fmod;
using System.Runtime.InteropServices;

namespace AudioSpectrumStudy
{
    public partial class Form1 : Form
    {
        Fmod.System system;
        Fmod.Channel channel;
        Fmod.Sound sound;
        Fmod.ChannelGroup channelGroup;
        Fmod.DSP dsp;
        Fmod.DSP_DESCRIPTION description;
        Timer timer;

        public Form1()
        {
            InitializeComponent();
            textBox1.MouseDoubleClick += textBox1_MouseDoubleClick;

            system = new Fmod.System(IntPtr.Zero);
            system.init(32, INITFLAGS.NORMAL, IntPtr.Zero);
            channel = new Channel(IntPtr.Zero);
            sound = new Sound(IntPtr.Zero);

            sound.setMusicSpeed(1.0f);
            sound.setMode(MODE._2D);

            description = new DSP_DESCRIPTION();
            system.createDSP(ref description, out dsp);

            channel.getChannelGroup(out channelGroup);
            timer = new Timer();
            timer.Tick += timer_Tick;
        }

        void textBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "File|*.*";
            ofd.ShowDialog();

            textBox1.Text = ofd.FileName;
        }

        void timer_Tick(object sender, EventArgs e)
        {
            system.update();

            UpdateSpectrum();

            progressBar1.Value = (int)_spectrum[0] > 100 ? 100 : (int)_spectrum[0];
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private const int SPECTRUM_SIZE = 512;
        private float[][] _spectrumInfo;
        public float[] _spectrum;

        private void UpdateSpectrum()
        {
            if (_spectrum == null || _spectrumInfo == null)
            {
                if(_spectrum == null)
                    _spectrum = new float[SPECTRUM_SIZE];

                if (_spectrumInfo == null)
                {
                    _spectrumInfo = new float[2][];
                    _spectrumInfo[0] = new float[SPECTRUM_SIZE];
                    _spectrumInfo[1] = new float[SPECTRUM_SIZE];
                }
            }

            System.IntPtr data = IntPtr.Zero;
            uint length = 0;

            dsp.getParameterData(3, out data, out length);
            //Fmod.DSP_PARAMETER_FFT spectrumBuffer = new DSP_PARAMETER_FFT();
            
            var spectrumBuffer = (Fmod.DSP_PARAMETER_FFT)Marshal.PtrToStructure(data, typeof(Fmod.DSP_PARAMETER_FFT));

            _spectrumInfo = spectrumBuffer.spectrum;

            for (int i = 0; i < SPECTRUM_SIZE; i++)
            {
                _spectrum[i] = (_spectrumInfo[0][i] + _spectrumInfo[1][i]) / 2f;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            system.createSound(textBox1.Text, MODE._2D, out sound);
            system.playSound(sound, channelGroup, false, out channel);
            system.playDSP(dsp, channelGroup, false, out channel);

            system.release();
            system.close();

            timer.Start();
        }
    }
}

this is my code
var spectrumBuffer = (Fmod.DSP_PARAMETER_FFT)Marshal.PtrToStructure(data, typeof(Fmod.DSP_PARAMETER_FFT));
this code raise exception ‘ArgumentNullException’ so, I traced with debug why the exception raise.
I found dsp.getParameterData() method was returned ‘ERR_INVALID_PARAM’
why working like that?

It looks like you aren’t adding your dsp to anything.
You will need to use Channel/ChannelGroup::addDSP().

Also a good idea to make sure the sound is playing before using getParameterData, otherwise you will just get back meaningless data.

truly music was not played…
playSound Method also returned ERR_INVALID_PARAM too.
I’m so confused about use this api now :expressionless:

The channelgroup may not be valid, you are calling getChannelGroup on the channel before it has been assigned (in the playSound method). You don’t have to use a channelgroup when creating a sound, you can pass in null or even the master group using System::getMasterChannelGroup.

Also when creating the dsp, you need to specify the description going in to create it. Otherwise you can use createDSPByType(FMOD.DSP_TYPE.FFT, out dsp).

thx at all, I turned the other solution.

now have new issue
private void FmodERRCheck(Fmod.RESULT result){
if (result != RESULT.OK)
{
MessageBox.Show(Fmod.Error.String(result));
}
}

    private void InitFmodSystems()
    {
        Fmod.Factory.System_Create(out system);
        system = new Fmod.System(IntPtr.Zero);
        system.init(3, INITFLAGS.NORMAL, IntPtr.Zero);

        channelGroup = new ChannelGroup(IntPtr.Zero);

        FmodERRCheck(system.createChannelGroup("", out channelGroup));
    }

I fixed my code right that
FmodERRCheck(system.createChannelGroup("", out channelGroup));
this line message to me ERR_INVALID_PARAM again.
welp. I think that could be working :confused: