0
0

i want to set loop points (include startpoint and endpoint) for midi, but i found two similar api for this:FMOD_Sound_SetLoopPoints and FMOD_Channel_SetLoopPoints, they have same parameters, i don’t konw the differences between them? i try to use them in my code, but it doesn’t work, i guess i don’t use them rightly, so pls tell me how to accomplish the function? thanks! my code is bellow
[code:16jkv3pf]#import "PlayMidiDemoViewController.h"

@implementation PlayMidiDemoViewController

@synthesize status;
@synthesize time;

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}

  • (void)viewDidLoad {
    [super viewDidLoad];
    system = NULL;
    sound1 = NULL;
    sound2 = NULL;
    channel = NULL;
    }

  • (void)didReceiveMemoryWarning {
    // Releases the view if it doesn’t have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren’t in use.
    }

  • (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }

  • (void)dealloc {
    [status release], status = nil;
    [time release], time = nil;
    [super dealloc];
    }

  • (void)viewWillAppear:(BOOL)animated
    {
    FMOD_RESULT result = FMOD_OK;
    char buffer[200] = {0};
    unsigned int version = 0;

    /*
    Create a System object and initialize
    */
    result = FMOD::System_Create(&system);
    ERRCHECK(result);

    result = system->getVersion(&version);
    ERRCHECK(result);

    if (version < FMOD_VERSION)
    {
    fprintf(stderr, "You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
    exit(-1);
    }

    result = system->init(32, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, NULL);
    ERRCHECK(result);

    // set up DLS file
    FMOD_CREATESOUNDEXINFO soundExInfo;
    memset(&soundExInfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
    soundExInfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    char dlsName[200] = {0};
    [[NSString stringWithFormat:@"%@/gs_instruments.dls", [[NSBundle mainBundle] resourcePath]] getCString:dlsName maxLength:200 encoding:NSASCIIStringEncoding];
    soundExInfo.dlsname = dlsName;

    // midi one
    

    [[NSString stringWithFormat:@"%@/bbb.mid", [[NSBundle mainBundle] resourcePath]] getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding];

    result = system->createSound(buffer, FMOD_SOFTWARE | FMOD_CREATESTREAM, &soundExInfo, &sound1);

// ERRCHECK(result);

result = sound1-&gt;setMode(FMOD_LOOP_NORMAL);//FMOD_LOOP_OFF
result = sound1-&gt;setLoopCount(1);
result = sound1-&gt;setLoopPoints(3000, FMOD_TIMEUNIT_MS, 20000, FMOD_TIMEUNIT_MS);

// ERRCHECK(result);

// midi two
[[NSString stringWithFormat:@&quot;%@/Drum_sample.mid&quot;, [[NSBundle mainBundle] resourcePath]] getCString:buffer maxLength:200 encoding:NSASCIIStringEncoding]; 

result = system-&gt;createSound(buffer, FMOD_SOFTWARE | FMOD_CREATESTREAM, &amp;soundExInfo, &amp;sound2);
result = sound2-&gt;setMode(FMOD_LOOP_OFF);    

// timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES];
}

  • (IBAction)playSound1:(id)sender
    {
    FMOD_RESULT result = FMOD_OK;

    result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
    result = channel->setPosition(30000, FMOD_TIMEUNIT_PCM);//FMOD_TIMEUNIT_MS
    //result = channel->setLoopPoints(3000, FMOD_TIMEUNIT_PCM, 20000, FMOD_TIMEUNIT_PCM);
    ERRCHECK(result);
    }

  • (IBAction)playSound2:(id)sender
    {
    FMOD_RESULT result = FMOD_OK;

    result = system->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
    ERRCHECK(result);
    }[/code:16jkv3pf]

  • You must to post comments
0
0

Sound::setLoopPoints is like a template, so all channels created from that sound will have the same loop points.
Channel::setLoopPoints will only affect one particular channel.

I notice you are trying to seek outside the loop region, I think that gives an error. Have you tried playing the sound without seeking to check looping works?

  • You must to post comments
0
0

Thanks for your reply.
If I do nothing, just play a sound, it goes well. But I need accomplish a funtion that I can play any part of a midi for any times.
I have tried three cases:
1.just set sound loop points, not set channel, but it doesn’t work, it still play from the beginning;
[code:1x9n8hyk]result = sound1->setMode(FMOD_LOOP_NORMAL);//FMOD_LOOP_OFF
result = sound1->setLoopCount(1);
result = sound1->setLoopPoints(3000, FMOD_TIMEUNIT_MS, 20000, FMOD_TIMEUNIT_MS);
[/code:1x9n8hyk]

2.just set channel loop points, not set sound, the result is as above, it also play from beginning;
[code:1x9n8hyk]- (IBAction)playSound1:(id)sender
{
FMOD_RESULT result = FMOD_OK;

result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound1, false, &amp;channel);
result = channel-&gt;setLoopPoints(3000, FMOD_TIMEUNIT_MS, 20000, FMOD_TIMEUNIT_MS);
ERRCHECK(result);

}
[/code:1x9n8hyk]

3.set sound loop, also set channel loop, the result is as the same.

But Ifind if I just use Channel::setPosition, not use other seeking loop functions, it takes effect, it can play from the point which one I wish it is.
So I want to know why the function setlooppoints doesn’t work.
I also have another question: which case should I choose FMOD_TIMEUNIT_MS? which case to use FMOD_TIMEUNIT_PCM? I see that
[code:1x9n8hyk]#define FMOD_TIMEUNIT_PCM 0x00000002 /* PCM samples, related to milliseconds * samplerate / 1000. */[/code:1x9n8hyk]
how to get the ‘samplerate’? I don’t know whether it can modified. dose it have a default value?

  • You must to post comments
0
0

By the way, the other two questions:
1.I want to konw whether Fmod can extract tracks within the midi file. For example, there are three tracks(piano, guitar, bass) in a midi file, could fmod extacts the three instruments, and play them separately? If it can, could you show me some sample code? Thanks! :)
2.I see that fmod can support FSB/DLS/SF2 formats as sound banks, but I try to use a sf2 file as sound bank, as result it can’t paly midi, what’s the reason?

  • You must to post comments
0
0

[quote:75dyzarw]it still play from the beginning[/quote:75dyzarw]
No matter what the loop points are the sound will always start at the start, travel towards to the loop end point, then jump back to the loop start. If you want it to start at the loop start point you need to setPosition there.

[quote:75dyzarw]which case should I choose FMOD_TIMEUNIT_MS? which case to use FMOD_TIMEUNIT_PCM?[/quote:75dyzarw]
This is totally up to you, there is no real rules about which is best. If you are dealing with time, use MS (milliseconds) if you are dealing with samples use PCM.

[quote:75dyzarw]how to get the ‘samplerate’?[/quote:75dyzarw]
The sample rate here is the default rate, you can get this with Sound::getDefaults

[quote:75dyzarw]I don’t know whether it can modified[/quote:75dyzarw]
If you are looking to adjust the pitch of a channel you can use Channel::setFrequency, this won’t affect the sample rate of the Sound though, just the rate that the sound data is played at.

[quote:75dyzarw]dose it have a default value?[/quote:75dyzarw]
No, it depends on the source file.

[quote:75dyzarw]I want to konw whether Fmod can extract tracks within the midi file. [/quote:75dyzarw]
No, the tracks are all mixed together. However you can control the volume of each track before they are mixed via Sound::setMusicChannelVolume.

[quote:75dyzarw]I see that fmod can support FSB/DLS/SF2[/quote:75dyzarw]
FSB and DLS yes, SF2 no. Originally we planned to support SF2 but it never eventuated, is some documentation out of date somewhere?

[quote:75dyzarw]but I try to use a sf2 file as sound bank, as result it can’t paly midi[/quote:75dyzarw]
See above, SF2 isn’t supported, but more importantly for MIDI playback you must provide a DLS, no other bank format can be used.

  • You must to post comments
0
0

It’s very kind of you! Thank you! 😀
Well, if I want to set a loop end point, how to do? Does Fmod have APIs for this?

  • You must to post comments
0
0

You already have it’s the same function for setting start and end of the looping region.

[code:2pmj2e69]FMOD_RESULT Sound::setLoopPoints(
unsigned int loopstart,
FMOD_TIMEUNIT loopstarttype,
unsigned int loopend,
FMOD_TIMEUNIT loopendtype
);[/code:2pmj2e69]

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.