0
0

I have a large mp3(or other) file with length of 20 seconds.
How can I play sound from this file betwen 12.5 and till 13.2 seconds?

[code:3cj2ixxw]
system->createStream(fileName.toLocal8Bit(), FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
system->playSound(FMOD_CHANNEL_FREE,sound, false, &channel);
channel->setPosition(12500, FMOD_TIMEUNIT_MS);
[/code:3cj2ixxw]

How to stop at position exactly 13200ms?
I don’t want to crop sound stream to another one.
I want function something like:
[code:3cj2ixxw]
system->playSound(FMOD_CHANNEL_FREE,sound, false, &channel);
channel->setPosition(12500, FMOD_TIMEUNIT_MS);
channel->setStopPosition(13200, FMOD_TIMEUNIT_MS);
[/code:3cj2ixxw]
Thank you.

  • You must to post comments
0
0

I think, not sure, that loop points may achieve this, though you may have to set the start position manually and loop it once.

I would ask why you want to play a tiny bit of the sound… A compressed streamed sound at that. Streamed sounds are slower to process, especially compressed sounds. So if you plan on using that for sound effect dont create it streamed… And a .wav would be best. Spliting them would be optimal.

Your set_stop_position suggestion is a good one though

  • You must to post comments
0
0

Hi cemehehko,

[quote:1wa02j5i]I don’t want to crop sound stream to another one[/quote:1wa02j5i]
Is that because the file is reused other places and different parts of it are used? If you tell us what you’re trying to achieve we might be able to give you better advice on how to go about doing it.

[quote:1wa02j5i]I think, not sure, that loop points may achieve this[/quote:1wa02j5i]
The loop points wont make the channel stop at the end loop point – it will play the rest of the file which in this case is undesirable.

[quote:1wa02j5i]channel->setStopPosition(13200, FMOD_TIMEUNIT_MS); [/quote:1wa02j5i]
Well if there was a setStopPosition function it would probably just poll Channel::getPosition so you could quite easily set that up yourself.
[code:1wa02j5i]ERRCHECK(channel->getPosition(&pos, FMOD_TIMEUNIT_MS));
if (pos > stop_time)
{
ERRCHECK(channel->stop());
}[/code:1wa02j5i]

Another possible solution is to use syncpoint callbacks. You can encode syncpoints into the sound then manipulate the channel in the callback.
[code:1wa02j5i]system->createStream(filename, FMOD_OPENONLY | FMOD_ACCURATETIME, 0, &sound);
system->playSound(FMOD_CHANNEL_FREE, sound, true, &channel);
sound->addSyncPoint(end_time, FMOD_TIMEUNIT_MS, 0, 0);
channel->setCallback(syncpoint_stop);
channel->setPosition(start_time, FMOD_TIMEUNIT_MS);
channel->setPaused(false);[/code:1wa02j5i]

Unfortunately you cannot call Channel::stop inside the callback because the FMOD code is still using that channel. Although you can effectively stop it by setting the position to the end of the channel and muting it which will cause it to get cleaned up.

[code:1wa02j5i]FMOD_RESULT F_CALLBACK syncpoint_stop(FMOD_CHANNEL *c_channel, FMOD_CHANNEL_CALLBACKTYPE type, void *commanddata1, void *commanddata2)
{
FMOD::Channel *channel = (FMOD::Channel *)c_channel;

if (type == FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT)
{
    unsigned int length;
    FMOD::Sound *snd;
    channel->getCurrentSound(&snd);
    snd->getLength(&length, FMOD_TIMEUNIT_PCM);
    channel->setPosition(length - 1, FMOD_TIMEUNIT_PCM);
    channel->setMute(true);
}

return FMOD_OK;

}[/code:1wa02j5i]

Hope this helps,

-Pete

  • You must to post comments
0
0

I have found relevant way (I think) with external timer. I use QT framework:

  1. Start play sound.
  2. Setup system timer event on stop after N seconds
    [code:2nrnijgf]
    QTimer::singleShot(1200,SLOT(stop()));
    [/code:2nrnijgf]

Thank you.
[/code]

  • You must to post comments
0
0

I think a QTimer will work fine for this. It is important no two calls to FMOD occur at the same time, but it looks like the QTimer will call the slot function from the same thread as it was started from. So as long as you start the timer from the same thread you’re making the rest of your FMOD calls from, it should be fine.

-Pete

  • You must to post comments
0
0

Hello, this is my first post here, and by luck I found this thread instead of posting one with the exact same question.

I have been playing with fmod for a week and I think its great!

I had hoped for something similar, like a function where you could just specify a start and end time slice, call play and it would play the specified slice and stop.

Setting the specified start then using the timer with an interval as long as the desired slice sounds OK. The only thing that I wonder is this- if you do this, would you call the timer start first, then call "play", or would you call "play" then tell the timer to kick off? I suppose it wouldn’t matter. It does seem like doing it this way could be inaccurate give or take a tick if the wind was blowing right. A mSec here or there won’t be noticeable to the avg. human, so that should be fine. I just feel a little guilty when I use a timer to duct-tape a situation though

I am using fmod to sync music together with laser light effects. The timing is everything, so you might find yourself playing the same 2 to 3 second slice of a song over and over just to get the visual synced just right.

I’m glad to have found this forum- it looks like an excellent resource.

Thanks, Mike 😉

  • You must to post comments
0
0

The most accuracy way is to create virtual Sound based on real Sound(stream or file) with yours callbacks on read. virtual ReadCallback will read from original Sound. The code:
[code:3fj4btha]
FMOD::Sound *sound; // real full sound(mp3 or other)

/* Start play a piece of real sound
*/
void SoundChannel::play(){
FMOD::Sound *virtualSound; // virtual sound
FMOD_RESULT result;
FMOD_CREATESOUNDEXINFO createsoundexinfo;
memset(&createsoundexinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
createsoundexinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
createsoundexinfo.decodebuffersize = 4096;
createsoundexinfo.length = LENGHT_OF_PIECE;
createsoundexinfo.numchannels = 2;
createsoundexinfo.defaultfrequency = 44100;
createsoundexinfo.format = FMOD_SOUND_FORMAT_PCMFLOAT;
createsoundexinfo.pcmreadcallback = pcmreadcallback;
createsoundexinfo.pcmsetposcallback = pcmsetposcallback;
createsoundexinfo.initialseekposition=0;
createsoundexinfo.initialseekpostype=FMOD_TIMEUNIT_PCM;

//realSound->getFormat(0,&createsoundexinfo.format, &createsoundexinfo.numchannels,0);

result = system->createSound(0, FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_SOFTWARE|FMOD_CREATESTREAM, &createsoundexinfo, &virtualSound);
atEnd=false;
ERRCHECK(result);

result = system->playSound(FMOD_CHANNEL_REUSE , virtualSound, paused, &channel);

}

FMOD_RESULT F_CALLBACK pcmsetposcallback(FMOD_SOUND *fsound, int subsound, unsigned int position, FMOD_TIMEUNIT postype)
{
// TODO: postype
sound->seekData(channel->position+START_POSITION );
return FMOD_OK;
}

FMOD_RESULT F_CALLBACK pcmreadcallback(FMOD_SOUND *fsound, void *data, unsigned int datalen)
{
sound->readData(data,datalen);
}

[/code:3fj4btha]

This is fake code – do not comile this without appropriate changes).

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.