OGeek|极客世界-中国程序员成长平台

标题: ios - AudioToolbox AUAudioFilePlayer 属性说明 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:57
标题: ios - AudioToolbox AUAudioFilePlayer 属性说明

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

  1. kAudioUnitProperty_ScheduleStartTimeStamp

  2. kAudioUnitProperty_ScheduledFilePrime

  3. kAudioUnitProperty_ScheduledFileRegion

有人可以对每种用法提供一些说明吗?似乎它们的用法重叠?谢谢。



Best Answer-推荐答案


是的,这令人困惑。

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4