• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - AudioToolbox AUAudioFilePlayer 属性说明

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:57:29 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我对 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap