0
0

Hi,

I try to do a software that generate sound in real time.
I calculate frequencies and I want to "send" it to output device.

I try to use FMOD but it seems that he doesn’t accept several opening.
With one "thread", I can generate one sound with the frequency I want.
But, if I try to open several threads, it sais that he cannot open the output device.

How can I generate several sounds at the same time ?

Regards,

PS : Sorry for my english, it’s not my native language ๐Ÿ˜‰

  • You must to post comments
0
0

The Oscillator DSP generates a full-volume signal. It doesn’t take much to get it to clip, which is probably what you’re describing. My suggestion would be to lower the volume on all of your Channels, which should prevent clipping when you have multiples going at once.

  • You must to post comments
0
0

You don’t need multiple threads for multiple sounds.

Simply play all the sounds you want, the play sound function is not blocking.

  • You must to post comments
0
0

So I lower the volume to 0.1f and I change a few things and it’s good.
The sound produced is really good. It is rather perfect ๐Ÿ˜€

The speakers saturate a little bit but my working PC is not a monster and, then, the OS speaker volume is the highest.

I really thank you both of you for the help.

I keep going my project, and I hope I will not have to post here again ๐Ÿ˜†

  • You must to post comments
0
0

So I have to do that :

m_result = m_system->createSound(0, m_mode, &m_createsoundexinfo, &m_sound1) ;
m_result = m_system->createSound(0, m_mode, &m_createsoundexinfo, &m_sound2) ;

m_result = m_system->playSound(FMOD_CHANNEL_FREE, m_sound1, 0, &m_channel);
m_result = m_system->playSound(FMOD_CHANNEL_FREE, m_sound2, 0, &m_channel);

?
And then, in the pcmreadcallback, I look "sound" to know which one is it ?

  • You must to post comments
0
0

If you wish to generate audio manually for each of those sounds, then yes you could implement using that method.

If you are simply looking to generate tones, take a look at FMOD_DSP_OSCILLATOR.

  • You must to post comments
0
0

So I did as you told me.

I called several times "createSound" et "playSound" and, in "pcmreadcallback", I use a global variable that I increment to generate each sound one after another.

It seems to be good, but there is one problem.
It is not fluid. And I think that it comes less and less fluid the more the program is executed.

I have around 6-7 sounds running.
Maybe there is too many call to the callback and my computer can’t handle it so fast ?

[u:xoe0edhd][b:xoe0edhd]CODE : [/b:xoe0edhd][/u:xoe0edhd]

[code:xoe0edhd]
void MyClass::run()
    {
        nb_corde = g_pointeur->get_nb_frequencies() ;

        for (int i = 0; i < nb_corde; i++)
        {
            frequencies.push_back(get_frequency(i)) ;
            FMOD::Sound * pointeur ;
            m_result = m_system->createSound(0, m_mode, &m_createsoundexinfo, &pointeur) ;
            ERRCHECK(m_result) ;
            m_sounds.push_back(pointeur) ;
        }

        for (vector<FMOD::Sound *>::iterator it = m_sounds.begin(); it != m_sounds.end(); it++)
        {
            m_result = m_system->playSound(FMOD_CHANNEL_FREE, (*it), 0, &m_channel);
            ERRCHECK(m_result);
        }

        m_system->update() ;
    }

FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)
    {
        float frequency = 0 ;

        frequency = frequencies[num_corde] ;
        num_corde = (num_corde + 1) % nb_corde ;

        unsigned int count ;
        static float t1 = 0 ;
        signed short *stereo16bitbuffer = (signed short *)data ;

        for (count=0; count<datalen>>2; count++)
        {

            *stereo16bitbuffer++ = (float)(sin(t1) * 32767.0f) ;
            *stereo16bitbuffer++ = (float)(sin(t1) * 32767.0f) ;

            t1 += (2*M_PI*frequency)/44100 ;
        }

        return FMOD_OK ;
    }
[/code:xoe0edhd]

Run() is called only once.

For FMOD_DSP_OSCILLATOR, is it compatible with C++ ?
Because I found it about Java.
Is there a documentation ?
It seems that the doc on "http://52.88.2.202/docs/HTML/" is empty…

  • You must to post comments
0
0

If you suspect performance issues check System::getCPUUsage.

FMOD_DSP_OSCILLATOR is a DSP unit available with FMOD, this has nothing to do with the programming language. You can see an example of its usage in the generatetone example that ships with the FMOD SDK.

If you are looking for documentation have a look at fmodex.chm located in the documentation folder of the FMOD SDK.

  • You must to post comments
0
0

I looked at generatetone, and it seems that this method is closer to my objective.
But, as it used the output channel, is it possible to generate several tones ?
Can I create many FMOD::Channel * ?

  • You must to post comments
0
0

If you wish to have multiple different tones you will need to create multiple oscillator DSPs.

  • You must to post comments
0
0

So, I do that :

[code:yf7hz1ux]
for (int i = 0; i < get_nb_frequencies(); i++)
{
FMOD::DSP * pointeur ;

        m_result = m_system-&gt;createDSPByType(FMOD_DSP_TYPE_OSCILLATOR, &amp;pointeur) ;
        ERRCHECK(m_result) ;
        m_result = pointeur-&gt;setParameter(FMOD_DSP_OSCILLATOR_RATE, get_frequency(i)) ;
        ERRCHECK(m_result) ;
        m_result = pointeur-&gt;setParameter(FMOD_DSP_OSCILLATOR_TYPE, 0) ;
        ERRCHECK(m_result) ;

        m_dsp.push_back(pointeur) ;
    }

    for (int i = 0; i &lt; get_nb_frequencies(); i++)
    {
        m_result = m_system-&gt;playDSP(FMOD_CHANNEL_REUSE, m_dsp[i], true, &amp;m_channel) ;
    }

    m_channel-&gt;setVolume(0.5f) ;
    m_channel-&gt;setPaused(false) ;

[/code:yf7hz1ux]

But there is only the last DSP that is played.
I have a vector of FMOD::DSP * so I do have multiple oscillator DSPs, do not ?
Is there something else that I have misunderstood ?

Thank you very much for your help,
I began to lose hope in my project.
Maybe what I want is too hard or not doable ?

  • You must to post comments
0
0

You’re starting all of your DSPs paused, but then you’re only ever unpausing the last one.

Remember that each time you play a DSP, it’ll get its own channel. You can either do the unpause/setvolume inside of your second for() loop, or you can store a parallel array of FMOD::Channels.

If you want one point at which you manipulate all of these Channels together, have a look at FMOD::ChannelGroup.

Hope that helps.

  • You must to post comments
0
0

I use a vector of FMOD::Channel * and one of FMOD::DSP *.

I do as you said and it seems to be ok.

But, can you explain what are
> setParameter(FMOD_DSP_OSCILLATOR_RATE, myFreq) ;
> m_channel->setFrequency(myFreq) ;
for ?

What are the differencies ?
Because, I initialize doing setParameter with the frequency I want and I saw, in "generatetone" example, that the frequency was changed with setFrequency.

Maybe setParameter is for the frequency of the sound played ?
And setFrequency the frequency of reading, the sample rate ?

Thank you a lot for the replies, it really helped me.

EDIT :
I finally got several sounds at the same time.
At the beginning, it’s good.

But then, when I modify the frequencies of some DSP, their sounds become noisy (we hear some sizzles).

[code:5ryens2g]
void Audio::updateFrequencies()
{
for (int i = 0; i < get_nb_frequencies(); i++)
{
m_result = m_dsp[i]->setParameter(FMOD_DSP_OSCILLATOR_RATE, get_frequency(i)) ;
ERRCHECK(m_result) ;
}
}
[/code:5ryens2g]

I call "updateFrequencies" when the user modify a frequency.
They are all updated but only the ones which are "really" changed become noisy.
I don’t know if you understand what I mean, it is not easy to explain ^^

Do you know what may cause sounds become noisy ?

  • You must to post comments
Showing 12 results
Your Answer

Please first to submit.