sbooth / SFBAudioEngine

A powerhouse of audio functionality for macOS and iOS
https://sbooth.github.io/SFBAudioEngine/
MIT License
552 stars 87 forks source link

Fix loopable region #254

Closed mixage closed 1 year ago

mixage commented 1 year ago
Running this code did not ... repeat the region:
NSError *error= nil;
NSURL *url = [NSURL fileURLWithPath:FILE_PATH];
_player = [[SFBAudioPlayer alloc]init];
SFBLoopableRegionDecoder *decoder = [[SFBLoopableRegionDecoder alloc]initWithURL:url framePosition:START_FRAME frameLength:NUM_FRAMES repeatCount:REPEATCOUNT error:&error];
[_player enqueueDecoder:decoder forImmediatePlayback:YES error:&error];
[_player playReturningError:&error];
sbooth commented 1 year ago

There is definitely a missing repeatCount in https://github.com/sbooth/SFBAudioEngine/blob/c94313a66d13b24cd3c254628d51294af6ae5b83/Decoders/SFBLoopableRegionDecoder.m#L57

It makes me wonder whether GCC_WARN_UNUSED_PARAMETER should be enabled.

I'm not sure if the other changes in this PR are required, though.

sbooth commented 1 year ago

I think PR #255 contains all the necessary changes.

sbooth commented 1 year ago

If you'd like to revert the other changes I'm happy to merge this PR.

mixage commented 1 year ago

I'm not sure to know the right way to do this... Should I push a new commit?

sbooth commented 1 year ago

I'm not sure to know the right way to do this... Should I push a new commit?

Yes, you can just push additional commits and they'll be squashed into one when merged.

sbooth commented 1 year ago

Once the changes in MainMenu.xib are reverted this should be ready to go.

mixage commented 1 year ago

Done. (Xcode made these changes just by viewing the .xib)

NB: loop does'nt work after reverting SFBLoopableRegionDecoder.m row 183 to:

if ( _repeatCount && _frameLength == (_framesDecoded / _frameLength))

Any idea? Thanks :)

sbooth commented 1 year ago

What is repeat count set to? The intent of that parameter is the number of times to repeat following the initial play through, so playing a region twice implies a repeat count of one. Is that the behavior you're seeing?

mixage commented 1 year ago

The region plays once, regardless of the value of REPEAT_COUNT

NSError *error= nil;
NSURL *url = [NSURL fileURLWithPath:FILE_PATH];
_player = [[SFBAudioPlayer alloc]init];
SFBLoopableRegionDecoder *decoder = [[SFBLoopableRegionDecoder alloc]initWithURL:url framePosition:START_FRAME frameLength:NUM_FRAMES repeatCount:REPEAT_COUNT error:&error];
[_player enqueueDecoder:decoder forImmediatePlayback:YES error:&error];
[_player playReturningError:&error];
sbooth commented 1 year ago

I will take a closer look at this later today when I have a bit more time.

sbooth commented 1 year ago

Could you verify whether the proposed fix in #255 corrects the problem for you?

mixage commented 1 year ago

Works like a charm :) Thank you!