gpt4 book ai didi

ios - AudioToolbox AUAudioFilePlayer 属性说明

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:03:40 25 4
gpt4 key购买 nike

我对 AUAudioFilePlayer 的以下属性感到困惑。 Apple 的文档充其量是令人困惑的:

  1. kAudioUnitProperty_ScheduleStartTimeStamp

  2. kAudioUnitProperty_ScheduledFilePrime

  3. kAudioUnitProperty_ScheduledFileRegion

有人可以对每种用法提供一些说明吗?好像他们的用法重叠了?谢谢。

最佳答案

是的,这很困惑。

StartTime 正是您所想的那样:它定义了您为该音频单元安排的所有切片/区域的播放时间线的开始。

由于在播放之前需要将音频数据拉入 RAM,“启动”基本上告诉系统开始将音频文件(指定的帧数)读入内存。

您可以选择只播放文件的一部分(从文件中的一些帧开始和/或在文件末尾之前结束一些帧)。这些称为“区域”,如果您只想播放音频文件的一部分(或区域),这就是您使用的属性。

查看 AudioUnitProperties.h:

Start Time

The audio unit will not play any slices following initialization or reset, until its start time has been set. The start time establishes the beginning of a timeline: the timestamps of all slices in the schedule are relative to the start time.

Set a start time by setting the kAudioUnitProperty_ScheduleStartTimeStamp property with an AudioTimeStamp structure. If the timestamp contains a valid sample time (timestamp.mFlags & kAudioTimeStampSampleTimeValid), then playback begins when the timestamp passed to the AudioUnitRender function reaches the specified sample time. If the specified sample time is -1, playback begins on the next render cycle.

If the start timestamp does not contain a valid sample time, but does contain a valid host time (timestamp.mFlags & kAudioTimeStampHostTimeValid), then the specified host time is translated to the sample time at which playback will begin. A host time of 0 means "start on the next render cycle."

The kAudioUnitProperty_ScheduleStartTimeStamp property may be queried to obtain the time at which playback began. If the start time has not yet been reached, the timestamp returned will be whatever the host application last set.

Priming

You should set kAudioUnitProperty_ScheduledFilePrime after scheduling initial file regions to be played and before starting playback. This SetProperty call will begin reading the audio files and not return until the number of frames specified by the property value have been read.

Scheduling Regions

To schedule the playback of a region of an audio file, set the kAudioUnitProperty_ScheduledFileRegion property. This is a ScheduledAudioFileRegion structure. mTimeStamp.mSampleTime must be valid and is interpreted relative to the unit's start time -- the start time semantics (using kAudioUnitProperty_ScheduleStartTimeStamp) are identical to those of AUScheduledSoundPlayer. Unlike the ScheduledAudioSlice structures, the unit makes copies of ScheduledAudioFileRegions, so you may create them on the stack or otherwise reuse/dispose of them immediately after scheduling them.

关于ios - AudioToolbox AUAudioFilePlayer 属性说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com