0
0

Hello Guys,

That’s my 1st post in this forum and so I want to introduce myself at first.
My name is Marcus, I’m 23 years old and i live in Germany. I am a Hobby-Programmer and my favourite programming-language is Microsoft C# .net. Currently i’m trying to prog a c# MP3-Player using the FMODex soundsystem – and there’s the problem – I’m TRYING.

I’ve downloaded the FMODex Win32 API from this site on Friday and tried the whole weekend to get this thing work.

OK – the examples, esp. the C# examples are working fine – but i really don’t know much about FMOD and FMODex so I can’t get started.

So I decided to use the “playsound” example and work around it, till it’s doing my choices. So far so good – i just got the thing to work fine by playing my MP3s but the major problem – and the reason why I tried FMODex after all – is: I need a Spectrum Anayzer, and just this thing won’t work at my tries.

The Floatarray I created returns only some fix values (no dynamic while playing my sound).. I read about that in FMOD Forum – they said you have to use Managed Code or something, but this was the “old” FMOD and not the “new” FMODex.

Please have a closer look at the folowing Code, I guess i did right – but i don’t know.

[code:287mcdh0]

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace playsound
{
public class PlaySound : System.Windows.Forms.Form
{

    static int NumSpectrumBars = 64;
    float [] SpectrumArray = new float[NumSpectrumBars];


    private FMOD.System     system  = null;
    private FMOD.Sound      sound1  = null, sound2 = null, sound3 = null;
    private FMOD.Channel    channel = null;
    private uint            ms      = 0;
    private uint            lenms   = 0;
    private bool            playing = false;
    private bool            paused  = false;
    private int             channelsplaying = 0;

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.Button exit_button;
    private System.Windows.Forms.Timer timer;
    private System.Windows.Forms.StatusBar statusBar;
    private System.Windows.Forms.Label label;
    private System.ComponentModel.IContainer components;

    public PlaySound()
    {
        InitializeComponent();
    }

    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
            FMOD.RESULT     result;

            /*
                Shut down
            */
            if (sound1 != null)
            {
                result = sound1.release();
                ERRCHECK(result);
            }

            if (system != null)
            {
                result = system.close();
                ERRCHECK(result);
                result = system.release();
                ERRCHECK(result);
            }

            if (components != null) 
            {
                components.Dispose();
            }
        }
        base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        --SNIP ComponentProperties removed for better overview --SNAP--
    }
    #endregion

    [STAThread]
    static void Main() 
    {
        Application.Run(new PlaySound());
    }

    private void PlaySound_Load(object sender, System.EventArgs e)
    {
        uint version = 0;

        FMOD.Factory.System_Create(ref system);
        system.getVersion(ref version);

        if (version < FMOD.VERSION.number)
        {
            MessageBox.Show("Error!  You are using an old version of FMOD " + version.ToString("X") + ".  This program requires " + FMOD.VERSION.number.ToString("X") + ".");
            Application.Exit();
        }

        system.init(32, FMOD.INITFLAG.NORMAL, (IntPtr)null);
        system.createSound("d:/backups/mp3/rnb/track10.mp3", FMOD.MODE.SOFTWARE, ref sound1);



        sound1.setMode(FMOD.MODE.LOOP_OFF);

        FMOD.RESULT FSOUNDSpectrum = system.getSpectrum(SpectrumArray,NumSpectrumBars,0,FMOD.DSP_FFT_WINDOW.RECT);
        label.Text = FSOUNDSpectrum.ToString();    
        statusBar.Text = SpectrumArray[32].ToString();
    }

    private void button1_Click(object sender, System.EventArgs e)
    {
        system.playSound(FMOD.CHANNELINDEX.FREE, sound1, false, ref channel);
    }

    private void timer_Tick(object sender, System.EventArgs e)
    {   
        if (system != null)
        {
            system.getChannelsPlaying(ref channelsplaying);
            system.update();
        }

        label.Text = SpectrumArray[32].ToString();
        statusBar.Text = SpectrumArray[40].ToString()+ " : Channels Playing " + channelsplaying;
    }

    private void ERRCHECK(FMOD.RESULT result)
    {
        if (result != FMOD.RESULT.OK)
        {
            timer.Stop();
            MessageBox.Show("FMOD error! " + result + " - " + FMOD.Error.String(result));
            Environment.Exit(-1);
        }

    }


    private void exit_button_Click(object sender, System.EventArgs e)
    {
        Application.Exit();
    }

}

}
[/code:287mcdh0]

Please help me – I’m going crazy to get this thing to work.

Hopefully
Marcus aka. Jimmy

P.S.: Please excuse my bad english, I’m just a Kraut :) Hope you did understand everything.

  • You must to post comments
0
0

OK – Shame on me! Problem soved!

Just forgot that these Spectrum values will be initialized only one tine – and then never ever. putted the getSpectrum into the “Timer_Tick”-Event and it works fine!

Damn error – i could kick myself!

Jimmy

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.