• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How does one update a view position during a core audio render callback?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does one update a view position during a core audio render callback?


  • Subject: Re: How does one update a view position during a core audio render callback?
  • From: Patrick Collins <email@hidden>
  • Date: Sat, 07 Mar 2015 13:52:24 -0800

What do you mean by "tracking"?

Sent from my iPhone

On Mar 7, 2015, at 1:42 PM, "Dave O'Neill" <email@hidden> wrote:

It looks like your timer might not be firing consistently.  I would test that first. I'm not sure what else is going on in your Application but if there is any tracking then a timer will be blocked. If your timer isn't firing as expected try adding it like this:

    NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 / 60.0 target:self selector:@selector(moveBox) userInfo:nil repeats:1];
    [[NSRunLoop mainRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];




On Sat, Mar 7, 2015 at 10:20 AM, Patrick J. Collins <email@hidden> wrote:
Hmmm... So yeah, I tried using a timer-- and strangely, it's similar to
when I did the performSelectorOnMainThread...  The update only happens a
handful of times and I don't get why...

    self.timer = [NSTimer scheduledTimerWithTimeInterval:(1.0f / 60) target:self selector:@selector(updatePlayhead) userInfo:nil repeats:YES];

For a 1.6 second audio clip, the callback is fired only 5 times..

??  Why is this happening?

here is the actual code for my sample player:
https://gist.github.com/patrick99e99/72712182158ecbfcbfea

Patrick J. Collins
http://collinatorstudios.com


On Sat, 7 Mar 2015, Dave O'Neill wrote:

>
> ---------- Forwarded message ----------
> From: Dave O'Neill <email@hidden>
> Date: Sat, Mar 7, 2015 at 9:44 AM
> Subject: Re: How does one update a view position during a core audio render callback?
> To: "Patrick J. Collins" <email@hidden>
>
>
> The simplest way to do is to just set a variable to your current time in your render callback. 
> And then employ a repeating timer to check that value and update your view on the main thread.
> @implementation MyObject{
>     float currentTime;
> }
>
> OSStatus myRenderCallback{
>     MyObject *object = (MyObject *)inRefCon;
>     object->currentTime = CalculateTimeOnRenderThread(); //with no Obj-C messaging!
> }
>
> -(void)myTimerCallback{
>    self.playhead.position = currentTime;
> }
>
> If you want it to refresh the currentTime faster than the render callback you should get the
> mach_absolute_time() at the start of playing and again in your timer and calculate the difference.
>
> @implementation MyObject{
>     UInt64 startMachTime;
> }
> // if you need accuracy get the mHostTime from your render callback
> // otherwise do this
>
> -(void)startAudio{
>    startMachTime = mach_absolute_time();
> }
>
> -(void)myTimerCallback{
>    UInt64 ticksSinceStart = mach_absolute_time() - startMachTime;
>    self.playhead.position = convertTicksToSeconds(ticksSinceStart);
> }
>
> A CADisplyLink is an excellent timer for this
>
> On Sat, Mar 7, 2015 at 9:17 AM, Patrick J. Collins <email@hidden> wrote:
>       Hi,
>
>       So I have plotted out a waveform, and simply want to have a vertical
>       line represent a playhead which will move across the waveform's X-axis
>       as it plays.
>
>       I am using an NSBox as my playhead, and in my callback proc, I tried doing inside the
>       loop:
>
>         player->sampler.playheadView.position = player->sampler.playheadView.containerWidth
>       / player->buffer.size * currentSampleIndex
>
>       my playheadView's position setter just does this:
>
>       -(void)setPosition:(NSUInteger)position {
>           if (position == self.position) return;
>           [self setFrameOrigin:NSMakePoint(position, 0)];
>       }
>
>       However, this causes everything to slow down to the point that the audio plays
>       with clicks and gaps inbetween the frames..
>
>       I changed this to do a performSelectorOnMainThread, where this operation
>       occurs, but it seems like the playhead only gets updated a handful of times
>       during playback, so it does not look good..
>
>       What is the ideal way to get visual feedback like this during playback?
>
>       Thanks!
>
>       Patrick J. Collins
>       http://collinatorstudios.com
>
>        _______________________________________________
>       Do not post admin requests to the list. They will be ignored.
>       Coreaudio-api mailing list      (email@hidden)
>       Help/Unsubscribe/Update your Subscription:
>
>       This email sent to email@hidden
>
>
>
>
>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How does one update a view position during a core audio render callback? (From: "Patrick J. Collins" <email@hidden>)
 >Fwd: How does one update a view position during a core audio render callback? (From: "Dave O'Neill" <email@hidden>)
 >Re: Fwd: How does one update a view position during a core audio render callback? (From: "Patrick J. Collins" <email@hidden>)
 >Re: Fwd: How does one update a view position during a core audio render callback? (From: "Dave O'Neill" <email@hidden>)

  • Prev by Date: Re: Fwd: How does one update a view position during a core audio render callback?
  • Next by Date: Fwd: How does one update a view position during a core audio render callback?
  • Previous by thread: Re: Fwd: How does one update a view position during a core audio render callback?
  • Next by thread: Fwd: How does one update a view position during a core audio render callback?
  • Index(es):
    • Date
    • Thread