PCMPlayer
public class PCMPlayer : NSObject
PCMのプレイヤークラス。
本プレイヤーは、新しい音声データが追加されると再生待ちバッファの最後尾に追加します。 再生中は、再生待ちバッファの先頭から音声データを再生します。 伝送遅延等の影響で音声データの追加タイミングがばらつくと、 バッファ長が延び、音声データの追加から再生されるまでの時間(バッファリング時間)が大きくなる場合があります。
ライブモードで再生する場合は、バッファリング時間が蓄積して再生までに時間がかかるのを防ぐため、
再生待ちバッファが liveModeMaxBufferingTime の長さを超えた場合に、
バッファ長が liveModeMaxBufferingTime になるまでバッファの先頭をスキップして再生を継続します。
これにより、ライブモードではバッファリング時間が liveModeMaxBufferingTime を超えることはありません。
通信が不安定な場合に liveModeMaxBufferingTime を小さく設定しすぎると、
スキップが頻繁に起こり、再生がとぎれとぎれになる場合があります。
このような場合には、 liveModeMaxBufferingTime の値を大きめに設定してください。
-
音声フォーマットのデフォルト値(
.pcmInt16)。Declaration
Swift
public static let DEFAULT_PLAY_FORMAT: IntdashAudioFormat -
サンプリングレートのデフォルト値( 48000 )。
Declaration
Swift
public static let DEFAULT_SAMPLE_RATE: Double -
再生に必要な音声サンプル数のデフォルト値( 1024 )。
Declaration
Swift
public static let DEFAULT_AUDIO_OUTPUT_FRAME_SIZE: Int -
チャンネル数のデフォルト値( 1チャンネル )。
Declaration
Swift
public static let DEFAULT_CHANNELS: Int -
ライブモードかどうかを表すフラグのデフォルト値(
true)。Declaration
Swift
public static let DEFAULT_LIVE_MODE_FLAG: Bool -
ライブモード時のバッファリング時間の最大値のデフォルト値( 300ms )
Declaration
Swift
public static let DEFAULT_LIVE_MODE_MAX_BUFFERING_TIME: TimeInterval -
音声処理方法のデフォルト値(
kAudioUnitSubType_HALOutput)。 -
音声処理方法のデフォルト値(
kAudioUnitSubType_RemoteIO)。Declaration
Swift
public static let DEFAULT_AUDIO_UNIT_SUBTYPE: UInt32 -
音声フォーマット。
Declaration
Swift
public let playerFormat: IntdashAudioFormat -
サンプリングレート。
Declaration
Swift
public let sampleRate: Double -
チャンネル数。
Declaration
Swift
public var channels: Int -
AVAudioFormat の streamDescription。
Declaration
Swift
public private(set) var streamDescription: AudioStreamBasicDescription { get } -
出力するフレームに含まれるサンプル数。
Declaration
Swift
public var outputFrameSize: Int -
デバイスID。
-
音声の処理方法。
-
音声の処理方法。音声計測を行う場合は
kAudioUnitSubType_RemoteIO、音声通話を行う場合はkAudioUnitSubType_VoiceProcessingIOを指定してください。Declaration
Swift
public private(set) var audioUnitSubType: UInt32 { get } -
ライブモードかどうかを表すフラグ。
Declaration
Swift
public var isLiveMode: Bool -
ライブモード時のバッファリング時間の最大値。
Declaration
Swift
public var liveModeMaxBufferingTime: TimeInterval -
ミュートフラグ。
Declaration
Swift
public var isMuted: Bool -
オブジェクトを識別するためのタグ。
Declaration
Swift
public var tag: Int -
このクラスが使用する Delegate。
Declaration
Swift
public weak var delegate: PCMPlayerDelegate? -
再生中かどうか。
Declaration
Swift
public private(set) var isPlaying: Bool { get } -
PCMPlayer を生成します。
-
PCMPlayer を生成します。
-
PCMPlayer を生成します。
-
各種設定をセットします。
-
PCMPlayer を生成します。
Declaration
Swift
public override init() -
PCMPlayer を生成します。
Declaration
Swift
public init(commonFormat: AVAudioCommonFormat, sampleRate: Double = PCMPlayer.DEFAULT_SAMPLE_RATE, channels: Int = PCMPlayer.DEFAULT_CHANNELS, outputFrameSize: Int = PCMPlayer.DEFAULT_AUDIO_OUTPUT_FRAME_SIZE, audioUnitSubType: UInt32 = PCMPlayer.DEFAULT_AUDIO_UNIT_SUBTYPE) throwsParameters
commonFormat音声フォーマット。
sampleRateサンプリングレート。
channelsチャンネル数。
outputFrameSize出力するフレームのサイズ。
audioUnitSubType音声の処理方法。音声計測を行う場合は
kAudioUnitSubType_RemoteIO、音声通話を行う場合はkAudioUnitSubType_VoiceProcessingIOを指定してください。 -
PCMPlayer を生成します。
Declaration
Swift
public init(pcmFormat: PCMFormat, outputFrameSize: Int = PCMPlayer.DEFAULT_AUDIO_OUTPUT_FRAME_SIZE, audioUnitSubType: UInt32 = PCMPlayer.DEFAULT_AUDIO_UNIT_SUBTYPE) throwsParameters
pcmFormat音声フォーマット。
outputFrameSize出力するフレームのサイズ。
audioUnitSubType音声の処理方法。音声計測を行う場合は
kAudioUnitSubType_RemoteIO、音声通話を行う場合はkAudioUnitSubType_VoiceProcessingIOを指定してください。 -
音声を再生します。
Declaration
Swift
public func play(completion: ((_ result: Bool) -> ())? = nil)Parameters
completion処理完了時のコールバック
result処理成功、失敗フラグ
-
再生対象のデータを追加します。
Declaration
Swift
public func append(sampleData: Data, time: TimeInterval = MediaSystemClock.shared.rtcDate.timeIntervalSince1970)Parameters
sampleDataサンプルデータ
timeタイムスタンプ
-
再生対象のデータを追加します。
Declaration
Swift
public func append(sampleBufferPtr: UnsafeMutableRawPointer, bufferLength: Int, time: TimeInterval = MediaSystemClock.shared.rtcDate.timeIntervalSince1970)Parameters
sampleBufferPtrサンプルバッファーへのポインタ
bufferLengthバッファーの長さ
timeタイムスタンプ
-
再生を一時停止します。
Declaration
Swift
public func pause() -
バッファーをクリアします。
Declaration
Swift
public func clearBuffer() -
再生を停止します。
Declaration
Swift
public func stop(_ completion: (() -> ())? = nil)Parameters
completion処理完了時のコールバック
-
割り当てを解除します。
Declaration
Swift
public func dispose()
PCMPlayer Class Reference