0
0

I have one problem. I’d like to create sound from an array with samples. An pay it. I was trying something like this.

It is only part of my code concerning my problem.

The sin used in the code below is only an example and I know that to generate the sin I can use DSP tools from FMOD lib.

[code:3iltniby]
signed short data[1000];
float t1=0;
signed short *stereo16bitbuffer = (signed short *)data ;

  for (int count=0; count<1000; count++)
  {

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

      t1 += (2*M_PI)/10 ;
  }

result = FMOD_System_CreateSound(system, void *data,FMOD_OPENMEMORY,&exinfo,&sound);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, 0, &channel);
ERRCHECK( result);[/code:3iltniby]

the main thing are :

  • Am I using right flag in FMOD_MODE

  • how to load data form array

  • or maybe I’m doing it all wrong

Please help ?

  • You must to post comments
0
0

Ok, I set FMOD_SOUND_TYPE_RAW in this way

[code:1geqp7lz]exinfo.suggestedsoundtype = FMOD_SOUND_TYPE_RAW;[/code:1geqp7lz]

and Access violation message disappeared.

But Now I have new error, after line

[code:1geqp7lz]result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_SOFTWARE |FMOD_OPENMEMORY, &exinfo, &sound);[/code:1geqp7lz]

I get result – FMOD_ERR_FORMAT.

  • You must to post comments
0
0

Sorry my mistake, what I meant to say is you need FMOD_OPENRAW. It is a mode flag to OR into the createSound mode flags. You can just leave the suggested sound type empty.

[quote:2yrtjhti][b:2yrtjhti]FMOD_OPENRAW[/b:2yrtjhti]
Will ignore file format and treat as raw pcm. Use FMOD_CREATESOUNDEXINFO to specify format. Requires at least defaultfrequency, numchannels and format to be specified before it will open. Must be little endian data. [/quote:2yrtjhti]

  • You must to post comments
0
0

Hi orticelo,

Check out the usercreatedsound example in your FMOD install directory.

  • You must to post comments
0
0

Thanks Peter

Problem Solved, although there was another issue with my code which caused Access violation error.

In structure FMOD_CREATESOUNDEXINFO I declared too much samples in exinfo.length relativly to length of my array.

  • You must to post comments
0
0

I have checked out this example but I still have some problems

I wrote something like this
[code:evzfzv7t]
FMOD_SYSTEM *system;
FMOD_RESULT result;
FMOD_CHANNEL *channel = 0 ;
FMOD_SOUND *sound ;
FMOD_CREATESOUNDEXINFO exinfo;
FMOD_SOUND_PCMREADCALLBACK pcmreadcallback;
result = FMOD_System_Create(&system); // Create the main system object.

result=FMOD_System_Init(system, 100,FMOD_INIT_NORMAL, 0);
ERRCHECK( result);

result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_WINMM);
ERRCHECK( result);

F_CALLBACK pcmreadcallback(*,sound, void *data, unsigned int datalen)
{
unsigned int count;
static float t = 0 ; // time
static float v = 0; // velocity
signed short *stereo16bitbuffer = (signed short *)data;

for (count=0; count<datalen; count++)        // >>2 = 16bit stereo (4 bytes per sample)
{
    *stereo16bitbuffer++ = (signed short)(sin(t) * 32767.0f);    // left channel

    t += 0.01f   + v;

    v += (float)(sin(t) * 0.002f);

}

return FMOD_OK;

}

memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels      = 1;
exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 1000;
exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 1;
exinfo.pcmreadcallback   = pcmreadcallback;   /* User callback for reading. */
exinfo.decodebuffersize  = 1000;   /* Chunk size of stream update in samples.  This will be the amount of data passed to the user callback. */

FMOD_MODE mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_HARDWARE;

result = FMOD_System_CreateSound(system, 0, mode, &exinfo, &sound);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_REUSE, sound, 0, &channel);
ERRCHECK( result);[/code:evzfzv7t]

but it return an error in line,

[code:evzfzv7t]F_CALLBACK pcmreadcallback(*,sound, void *data, unsigned int datalen)

[/code:evzfzv7t]

it is syntax error. I ‘m using borland C++ builder.

I was trying other options like
[code:evzfzv7t]
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:evzfzv7t]

or
[code:evzfzv7t]
F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:evzfzv7t]

or

[code:evzfzv7t] F_CALLBACK pcmreadcallback(FMOD::Sound *sound, void *data, unsigned int datalen)[/code:evzfzv7t]

and few else solutions but always is something wrong. I’m not experienced in programing and probably is a stupid mistake but I don’t know how to deal with it, so please helm me.

  • You must to post comments
0
0

Glad to hear it’s all working. Yeah, you do have to be careful with those array length parameters, theres nothing preventing a buffer overrun if you accidently get it wrong.

  • You must to post comments
0
0

The second one your posted looks right:

[code:2ra92mc1]FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:2ra92mc1]

  • You must to post comments
0
0

[quote:11q20875]The second one your posted looks right:

Code:
FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code][/quote:11q20875]

but I still have syntax error, I was trying to solve it for, a long time using documentation and example mentioned by you, but still no results, I run out of new Ideas how to deal with it

when I am using code
[code:11q20875]
F_CALLBACK pcmreadcallback(sound, void *data, unsigned int datalen)
{
unsigned int count;
static float t = 0 ; // time
static float v = 0; // velocity
signed short *stereo16bitbuffer = (signed short *)data;

for (count=0; count<datalen; count++)        // >>2 = 16bit stereo (4 bytes per sample)
{
    *stereo16bitbuffer++ = (signed short)(sin(t) * 32767.0f);    // left channel

    t += 0.01f   + v;

    v += (float)(sin(t) * 0.002f);

}

return FMOD_OK;

}
[/code:11q20875]

There is only an syntax error

the same is with line
[code:11q20875]
F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:11q20875]

but when i try this

[code:11q20875]FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:11q20875]

then I get other errors:
– Inproper use of typdef ‘FMOD_RESULT’
– Statment missng ;

  • You must to post comments
0
0

Like I said stick with this one:
[code:15xeb7bc]FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:15xeb7bc]
The others are totally wrong.

[quote:15xeb7bc]Inproper use of typdef ‘FMOD_RESULT’ [/quote:15xeb7bc]
It sounds like it doesn’t understand the ‘FMOD_RESULT’ part. Make sure you #include fmod.h so that the definition of FMOD_RESULT is in the code unit. If it still doesn’t work you could try adding the keyword ‘enum’ before it, so:
[code:15xeb7bc]enum FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)[/code:15xeb7bc]

  • You must to post comments
0
0

Thanks for help

The problem was in bad placemnet of declaration

FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *sound, void *data, unsigned int datalen)

After I had moved it up as a global it worked.

But Now I wonder how to create sound from array which is already filed with samples.

I read topic

http://52.88.2.202/forum/viewtopic.php?t=13378

but I still have problems.

I wonder if something like this would be ok

[code:3sm7in00]result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_HARDWARE | FMOD_OPENMEMORY, &exinfo, &sound1);[/code:3sm7in00]

assuming that my array is buff and it has already been filed with samples.

Or maybe I should use DSP, if so how can I pass my array to DSP ?

  • You must to post comments
0
0

That CreateSound code looks good. Just casting the buffer to (const char*) like that is correct. I would probably steer clear of FMOD_HARDWARE though, FMOD_SOFTWARE is more reliable and more consistent across platforms.

Using DSP would be a bit more complicated but is another valid possiblity.

  • You must to post comments
0
0

Thanks for help but I stuck in one thing

I have array with short data and in this situation I don’t know how to use it.

I looked over loadfrommemory example but in my situation is a bit different because I am not loading any file to memory I have only already existing array with samples.

My code:

[code:rqld4n8e]
FMOD_CHANNEL *channel=0 ;
short tab[8000];
FMOD_SYSTEM *system;
FMOD_RESULT result;
FMOD_SOUND *sound ;
FMOD_CREATESOUNDEXINFO exinfo;
void *buff = 0;

result = FMOD_System_Create(&system); // Create the main system object.
ERRCHECK( result);

result = FMOD_System_SetOutput(system, FMOD_OUTPUTTYPE_WINMM);
ERRCHECK( result);

result=FMOD_System_Init(system, 100,FMOD_INIT_NORMAL, 0);
ERRCHECK( result);
unsigned int a;

// in this situation I am creating the array for testing purpose, but normally I will get array filed with random samples.

for (a=0; a<8000; a++)
{

     tab[a]=(short)(32767.0*sin((short)a*6.283185/800));


       }

buff = tab ;

memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels      = 1;
exinfo.format           = FMOD_SOUND_FORMAT_PCM16;
exinfo.defaultfrequency = 48000;
exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 1;

result = FMOD_System_CreateSound(system, (const char *)buff, FMOD_SOFTWARE | FMOD_OPENMEMORY, &exinfo, &sound);
ERRCHECK(result);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE , sound, 0, &channel);
ERRCHECK( result);[/code:rqld4n8e]

When I try to compile this code I get such a massage

EAccessVlioation with message ‘ Access violation at address 77C370F0 in module ‘msvcrt.dll’. Read of address 0041DA64′ Proces Stoped.

What sould I change to get i worked ?

  • You must to post comments
0
0

If you array is just data with no wav file header, you should use FMOD_SOUND_TYPE_RAW.

  • You must to post comments
Showing 13 results
Your Answer

Please first to submit.