0
0

Hi everybody,

I got some trouble for copying a sound by raw data :

[code:xzb57oeb]
FMOD::System *system = 0;
FMOD::Sound *sound, *sound2;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
void *ptr1, *ptr2;
unsigned int len1,len2
FMOD_CREATESOUNDEXINFO soundexinfo;

result = FMOD::System_Create(&system);

result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);

result = system->init(32,FMOD_INIT_NORMAL, 0);

result = system->createSound("ocean.wav",FMOD_SOFTWARE, 0,&sound);
result = sound->setMode(FMOD_LOOP_OFF);

sound->getLength(&len1,FMOD_TIMEUNIT_MS);

sound->lock(0,len1,&ptr1,&ptr2,&len1,&len2);

memset(&soundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
soundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);

soundexinfo.length = len1;

system->createStream((const char *)ptr1, FMOD_HARDWARE | FMOD_OPENMEMORY, &soundexinfo, &sound2);
sound->unlock(ptr1,ptr2,len1,len2);
result = system->playSound(FMOD_CHANNEL_FREE, sound2,0,&channel);

while (1) ;

result = sound->release();
result = sound->release();
result = system->close();
result = system->release();

return 0;
[/code:xzb57oeb]

But this doesn’t work.
I think I havn’t understood everything
I hope anyone can help me

Thanks.

  • You must to post comments
0
0

Ok , i’ve just found the solution :

[code:1vuym3a0]

include <iostream>

include <fmod/fmod.hpp>

include <string.h>

include <stdio.h>

using namespace std;

int main (void)
{
FMOD::System *system = 0;
FMOD::Sound *sound, *sound2;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
void *ptr11, *ptr12, *ptr21, *ptr22;
unsigned int len11,len21,len12,len22;
FMOD_CREATESOUNDEXINFO soundexinfo;

result = FMOD::System_Create(&system);

result = system->setOutput(FMOD_OUTPUTTYPE_ALSA);

result = system->init(32,FMOD_INIT_NORMAL, 0);

result = system->createSound("ocean.wav",FMOD_SOFTWARE, 0,&sound);
result = sound->setMode(FMOD_LOOP_OFF);

sound->getLength(&len11,FMOD_TIMEUNIT_PCMBYTES);
sound->lock(0,len11,&ptr11,&ptr21,&len11,&len21);

memset(&soundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
soundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
soundexinfo.numchannels = 1;
soundexinfo.format = FMOD_SOUND_FORMAT_PCM8;
soundexinfo.defaultfrequency = 11025;
soundexinfo.length = soundexinfo.defaultfrequency4sizeof(short int);

system->createSound(0, FMOD_2D | FMOD_OPENUSER | FMOD_SOFTWARE, &soundexinfo, &sound2);

sound2->lock(0,soundexinfo.defaultfrequency,&ptr12,&ptr22,&len12,&len22);

len12=len11;
memcpy(ptr12,ptr11,len11);

sound->unlock(ptr11,ptr21,len11,len21);
sound2->unlock(ptr12,ptr22,len12,len22);

result = system->playSound(FMOD_CHANNEL_FREE, sound2,0,&channel);

while (1) ;

result = sound->release();
result = sound->release();
result = system->close();
result = system->release();

return 0;
}
[/code:1vuym3a0]

But I’m afraid I’m alloing too much memory with this :

[code:1vuym3a0]
soundexinfo.length = soundexinfo.defaultfrequency4sizeof(short int);
[/code:1vuym3a0]

What do you guys think ?

Thanks !

  • You must to post comments
0
0

I dont understand the point of that code. Why dont you just play ocean.wav as a stream? You’re just wasting resources by creating an extra sound.

  • You must to post comments
0
0

[quote:39wf5xuj] I dont understand the point of that code. Why dont you just play ocean.wav as a stream? You’re just wasting resources by creating an extra sound.
[/quote:39wf5xuj]

Here is The Question.

This code has just a pedagogic aim. I would like to know how manipulate raw data before doing something efficient like a Voip program or something.[/quote]

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.