Re: Sequencer project
Re: Sequencer project
- Subject: Re: Sequencer project
- From: Gregory Wieber <email@hidden>
- Date: Mon, 4 Oct 2010 10:03:16 -0700
I was re-reading this thread from a while back, and have some questions regarding how one can align note ons to a 'sample edge'.
One, what is the 'sample edge'? Two, without something like MusicPlayer on iOS, how can someone implement something similar?
My notes do seem to be jittering -- it's extremely subtle, but there seems to be some phasing to my tempo.
Here's a pseudo look at my code (inside a render callback):
for each frame in inNumberOfFrames
{
is the time elapsed since last tick greater than tickLength (all based on the inTimeStamp sample time)?
YES: sequencer->nextStep, set time elapsed to 0, set last tick to now
}
Bill, you were saying to align note ons to the sample edge. I was trying to figure out what that meant. Should I be somehow scheduling my sequencer to move to the next step at some point in the future?
On Tue, Aug 17, 2010 at 12:07 PM, William Stewart
<email@hidden> wrote:
Yes, but all that the time stamp tells you is the time of the first sample in the buffer. If you want to schedule something to be sample accurate, then you just have to calculate how many samples in the current buffer (say 512 in your example below) that you need to go, to get the sound to be played on that exact sample. You know the duration of the buffer (512 / sampleRate), so that is an easy calculation.
This is basically how the MusicPlayer works - it looks at the events in the sequence, looks at the time stamp coming in, the size of the render buffer, then offsets events (see MusicDeviceMIDIEvent, AudioUnitSetParameter) where an offset in samples is provided. That allows the audio unit to apply a given event to an exact sample edge in its rendering. Most events (for example volume changes) do not need to be "sample accurate" as the change in the parameter is de-zippered (the new value is approached over a particular length of time to avoid glitching). Some events (note ons are the classic example) must be placed on the sample edge, or you will have a perceptible sense of jitter in the timing of the notes. A metronome click should also be aligned to the sample.
Bill
On Aug 16, 2010, at 6:10 PM, Andrew Coad wrote:
> I've been using time stamps in an audio unit render callback to count samples. Problem with that is that the callback processes 512 frames of audio at once; so it's not really accurate either.
Disagree. The number of frames being processed per callback has no impact on accuracy for an application like a metronome or sequencer where you know ahead of time what needs to be played and at what time. The accuracy of a single metronome click (i.e. the difference between desired time of the sound and actual time) will never be more than one half of one sample time (depends on the BPM rate) which is 1/2*44100s = 11.3us. At 140 BPM, this yields a worst case error of 0.16%. You can never get more accurate than this. Even if you calculated timing at the nanosecond level you can only start the sound on sample time intervals so you will still be in error by the same amount. Fortunately, an error of 0.16% has no meaning in music applications.
The number of samples being processed per callback does have an impact in applications where you don't know ahead of time what needs to be played - e.g. all cases of user initiated real-time sound. For these cases, the worst-case delay in getting the user initiated sound to actually play is (buffer size in samples per second)/44100s = 11.6ms for a 512 sample buffer. I don't know how much delay is perceivable by a human being (it will surely vary person-to-person) but 11.6ms is not perceivable. In cases where even this delay is undesirable you can reduce the number of samples per callback (512 is the default) but this increases the frequency at which the callback occurs so there is a trade-off here.
Andrew Coad
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (
email@hidden)
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
_______________________________________________
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