AudioToolbox框架詳細(xì)解析 (一) —— 基本概覽

版本記錄

版本號 時(shí)間
V1.0 2017.12.25

前言

AudioToolbox是專門處理聲音的一個(gè)框架,AudioToolbox這個(gè)庫是C的接口,偏向于底層,用于在線流媒體音樂的播放,可以調(diào)用該庫的相關(guān)接口自己封裝一個(gè)在線播放器類,接下來幾篇我們就詳細(xì)的解析一個(gè)這個(gè)框架。

Overview

首先看一下該框架的基本信息。

錄制或播放音頻,轉(zhuǎn)換格式,解析音頻流以及配置音頻會話。

AudioToolbox框架提供錄制,回放和流解析的接口。 在iOS中,框架為管理音頻會話提供了額外的接口。


框架基本

下面我們就看一下框架的基本情況。

接著看一下API

/*!
    @file       AudioToolbox.h
    @framework  AudioToolbox.framework
    @copyright  (c) 2002-2015 by Apple, Inc., all rights reserved.
    @abstract   Umbrella header for AudioToolbox framework.
*/


#ifndef AudioToolbox_AudioToolbox_h
#define AudioToolbox_AudioToolbox_h

#define AUDIO_TOOLBOX_VERSION 1060

#include <Availability.h>
#include <TargetConditionals.h>
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
    #include <AudioToolbox/AUComponent.h>
    #include <AudioToolbox/AUGraph.h>
    #include <AudioToolbox/AudioComponent.h>
    #include <AudioToolbox/AudioConverter.h>
    #include <AudioToolbox/AudioFile.h>
    #include <AudioToolbox/AudioFileStream.h>
    #include <AudioToolbox/AudioFormat.h>
    #include <AudioToolbox/AudioOutputUnit.h>
    #include <AudioToolbox/AudioQueue.h>
    #include <AudioToolbox/AudioServices.h>
    #include <AudioToolbox/AudioUnitParameters.h>
    #include <AudioToolbox/AudioUnitProperties.h>
    #include <AudioToolbox/CAFFile.h>
    #include <AudioToolbox/ExtendedAudioFile.h>
    #include <AudioToolbox/MusicDevice.h>
    #include <AudioToolbox/MusicPlayer.h>

    #if !TARGET_OS_IPHONE
        // OS X only
        #include <AudioToolbox/AudioCodec.h>
        #include <AudioToolbox/AudioFileComponent.h>
        #include <AudioToolbox/AudioUnitUtilities.h>
        #include <AudioToolbox/AUMIDIController.h>
        #include <AudioToolbox/CoreAudioClock.h>
    #endif

    #ifdef __OBJC2__
        // iOS (all architectures), OS X 64-bit only
        #import <AudioToolbox/AUAudioUnit.h>
        #import <AudioToolbox/AUAudioUnitImplementation.h>
        #import <AudioToolbox/AUParameters.h>
    #endif

#else
    #include <AUComponent.h>
    #include <AUGraph.h>
    #include <AudioComponent.h>
    #include <AudioConverter.h>
    #include <AudioFile.h>
    #include <AudioFileComponent.h>
    #include <AudioFileStream.h>
    #include <AudioFormat.h>
    #include <AudioOutputUnit.h>
    #include <AudioQueue.h>
    #include <AudioServices.h>
    #include <AudioUnitParameters.h>
    #include <AudioUnitProperties.h>
    #include <CAFFile.h>
    #include <ExtendedAudioFile.h>
    #include <MusicDevice.h>
    #include <MusicPlayer.h>

    #include <AudioCodec.h>
    #include <AudioUnitUtilities.h>
    #include <AUMIDIController.h>
    #include <CoreAudioClock.h>
#endif

/*! @mainpage

    @section section_intro          Introduction

    The AudioUnit framework contains a set of related API's dealing with:
    
    - Audio components, providing various types of plug-in functionality.
    - Audio Units, audio processing plug-ins.
    - Audio codecs, plug-ins which decode and encode compressed audio.
    
    @section section_component      Audio Components
    
    See AudioComponent.h for API's to find and use audio components, as well as information
    on how audio components are packaged and built.
    
    In addition, `<AVFoundation/AVAudioUnitComponent.h>` provides a higher-level interface for
    finding audio unit components.
    
    See @ref AUExtensionPackaging and AUAudioUnitImplementation.h for information on creating
    version 3 audio units.
    
    @section section_audiounit      Audio Units
*/

#include <stdio.h>

CF_ASSUME_NONNULL_BEGIN

#if defined(__cplusplus)
extern "C"
{
#endif

// prints out the internal state of an object to stdio
extern void CAShow (void* inObject) 
                                            __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_2_0);

// prints out the internal state of an object to the supplied FILE
extern void CAShowFile (void* inObject, FILE* inFile) 
                                            __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_2_0);
    
#if !TARGET_OS_IPHONE
// this will return the name of a sound bank from a sound bank file
// the name should be released by the caller
struct FSRef;
extern OSStatus GetNameFromSoundBank (const struct FSRef *inSoundBankRef, CFStringRef __nullable * __nonnull outName)
                                            __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2,__MAC_10_5, __IPHONE_NA, __IPHONE_NA);
#endif

/*!
    @function       CopyNameFromSoundBank
     
    @discussion     This will return the name of a sound bank from a DLS or SF2 bank.
                    The name should be released by the caller.

    @param          inURL
                        The URL for the sound bank.
    @param          outName
                        A pointer to a CFStringRef to be created and returned by the function.
    @result         returns noErr if successful.
*/

extern OSStatus
CopyNameFromSoundBank (CFURLRef inURL, CFStringRef __nullable * __nonnull outName)
                                            __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_7_0);

/*!
    @function       CopyInstrumentInfoFromSoundBank
     
    @discussion     This will return a CFArray of CFDictionaries, one per instrument found in the DLS or SF2 bank.
                    Each dictionary will contain four items accessed via CFStringRef versions of the keys kInstrumentInfoKey_MSB,
                    kInstrumentInfoKey_LSB, kInstrumentInfoKey_Program, and kInstrumentInfoKey_Name.
                        MSB: An NSNumberRef for the most-significant byte of the bank number.  GM melodic banks will return 120 (0x78).
                             GM percussion banks will return 121 (0x79).  Custom banks will return their literal value.
                        LSB: An NSNumberRef for the least-significant byte of the bank number.  All GM banks will return
                             the bank variation number (0-127).
                        Program Number: An NSNumberRef for the program number (0-127) of an instrument within a particular bank.
                        Name: A CFStringRef containing the name of the instrument.
 
                    Using these MSB, LSB, and Program values will guarantee that the correct instrument is loaded by the DLS synth
                    or Sampler Audio Unit.
                    The CFArray should be released by the caller.

    @param          inURL
                        The URL for the sound bank.
    @param          outInstrumentInfo
                        A pointer to a CFArrayRef to be created and returned by the function.
    @result         returns noErr if successful.
*/

extern OSStatus CopyInstrumentInfoFromSoundBank (CFURLRef inURL, CFArrayRef __nullable * __nonnull outInstrumentInfo)
                                                        __OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_7_0);
    
#define kInstrumentInfoKey_Name     "name"
#define kInstrumentInfoKey_MSB      "MSB"
#define kInstrumentInfoKey_LSB      "LSB"
#define kInstrumentInfoKey_Program  "program"

#if defined(__cplusplus)
}
#endif

CF_ASSUME_NONNULL_END

#endif // AudioToolbox_AudioToolbox_h

框架詳細(xì)

下面我們就看一下框架的詳細(xì)情況。

1. Classes

  • AUAudioUnit

    • AUAudioUnit類定義了一個(gè)音頻單元的主機(jī)接口。
  • AUAudioUnitBus

    • AUAudioUnitBus類定義音頻單元上的輸入或輸出連接點(diǎn)。
  • AUAudioUnitBusArray

    • AUAudioUnitBusArray類定義音頻單元輸入或輸出總線的容器。
  • AUAudioUnitPreset

    • AUAudioUnitPreset類描述audio unit開發(fā)人員提供的自定義參數(shù)設(shè)置的接口。 這些預(yù)設(shè)通常會產(chǎn)生有用的聲音或起點(diǎn)。
  • AUAudioUnitV2Bridge

    • AUAudioUnitV2Bridge類將version 2 audio unit包裝在AUAudioUnit子類中。
  • AUParameter

    • AUParameter對象表示單個(gè)音頻單元audio unit參數(shù)。
  • AUParameterGroup

    • AUParameterGroup對象表示一組相關(guān)的音頻單元參數(shù)。 一個(gè)參數(shù)組對于其子類是符合KVC的。
  • AUParameterNode

    • AUParameterNode對象表示音頻單元參數(shù)樹中的節(jié)點(diǎn)。 節(jié)點(diǎn)是AUParameterAUParameterGroup類的實(shí)例。
  • AUParameterTree

    • AUParameterTree對象是頂級group節(jié)點(diǎn),代表所有音頻單元的參數(shù)。 音頻單元的參數(shù)被組織成一個(gè)包含組和參數(shù)的樹(組可以嵌套)。

2. Protocols

  • AUAudioUnitFactory

    • 實(shí)現(xiàn)這個(gè)協(xié)議來創(chuàng)建一個(gè)version 3 audio unit
  • AUCocoaUIBase

3. Reference

  • Audio Converter Services
  • Audio File Services
  • Audio File Stream Services
  • Audio Format Services
  • Audio Queue Services
  • Audio Session Services
  • Audio Toolbox Debugging
  • Audio Unit Processing Graph Services
  • Extended Audio File Services
  • System Sound Services
  • AudioToolbox Structures
  • AudioToolbox Enumerations
  • AudioToolbox Constants
  • AudioToolbox Functions
  • AudioToolbox Data Types

后記

未完,待續(xù)~~~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容