Audio 'Codec Tag 49' may be requested when GSM 6.10 Audio Codec is missing. Learn how to reinstall it from this guide. Audio 'Codec Tag 17' may be requested when ADPCM Audio Codec / IMA ADPCM Audio Codec are missing.
![]() ![]()
(Redirected from ADPCM)
Adaptive differential pulse-code modulation (ADPCM) is a variant of differential pulse-code modulation (DPCM) that varies the size of the quantization step, to allow further reduction of the required data bandwidth for a given signal-to-noise ratio.
Typically, the adaptation to signal statistics in ADPCM consists simply of an adaptive scale factor before quantizing the difference in the DPCM encoder.[1]
ADPCM was developed for speech coding by P. Cummiskey, Nikil S. Jayant and James L. Flanagan at Bell Labs in 1973.[2]
In telephony[edit]
In telephony, a standard audio signal for a single phone call is encoded as 8000 analog samples per second, of 8 bits each, giving a 64 kbit/s digital signal known as DS0. The default signal compression encoding on a DS0 is either μ-law (mu-law) PCM (North America and Japan) or A-law PCM (Europe and most of the rest of the world). These are logarithmic compression systems where a 13 or 14 bit linear PCM sample number is mapped into an 8 bit value. This system is described by international standard G.711. Where circuit costs are high and loss of voice quality is acceptable, it sometimes makes sense to compress the voice signal even further. An ADPCM algorithm is used to map a series of 8 bit μ-law (or a-law) PCM samples into a series of 4 bit ADPCM samples. In this way, the capacity of the line is doubled. The technique is detailed in the G.726 standard.
Some ADPCM techniques are used in voice over IP communications. ADPCM was also used by Interactive Multimedia Association for development of legacy audio codec known as ADPCM DVI, IMA ADPCM or DVI4, in the early 1990s.[3]
Split-band or subband ADPCM[edit]
G.722[4] is an ITU-T standard wideband speech codec operating at 48, 56 and 64 kbit/s, based on subband coding with two channels and ADPCM coding of each.[5] Before the digitization process, it catches the analog signal and divides it in frequency bands with QMF filters (quadrature mirror filters) to get two subbands of the signal. When the ADPCM bitstream of each subband is obtained, the results are multiplexed and the next step is storage or transmission of the data. The decoder has to perform the reverse process, that is, demultiplex and decode each subband of the bitstream and recombine them.
Referring to the coding process, in some applications as voice coding, the subband that includes the voice is coded with more bits than the others. It is a way to reduce the file size.
Software[edit]
The Windows Sound System supported ADPCM in WAV files.[6] The corresponding FFmpeg audio codecs are adpcm_ima_qt, adpcm_ima_wav, adpcm_ms, adpcm_swf and adpcm_yamaha.[7][8]
References[edit]
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Adaptive_differential_pulse-code_modulation&oldid=940102713'
Core Audio EssentialsApple has designed the software interfaces to Core Audio using a layered, cooperative, task-focused approach. Read the first two sections in this chapter for a brief introduction to these interfaces and how they work together. Continue reading to understand the design principles, use patterns, and programming idioms that pervade Core Audio. The later sections in this chapter introduce you to how Core Audio works with files, streams, recording and playback, and plug-ins. API Architectural LayersThe programming interfaces for Core Audio are arranged into three layers, as illustrated in Figure 2-1.
Figure 2-1 The three API layers of Core AudioThe lowest layer includes:.The I/O Kit, which interacts with drivers.The audio hardware abstraction layer (audio HAL), which provides a device-independent, driver-independent interface to hardware.Core MIDI, which provides software abstractions for working with MIDI streams and devices.Host Time Services, which provides access to the computerâs clockMac apps can be written to use these technologies directly when they require the highest possible, real-time performance. Many audio applications, however, donât access this layer. Indeed, Core Audio in iOS provides ways to achieve real-time audio using higher level interfaces. OpenAL, for example, employs direct I/O for real-time audio in games. Typedef struct OpaqueAudioFileID.AudioFileID;You instantiate an audio file objectâand create an actual audio file tied to that objectâby calling the AudioFileCreateWithURL function.
The function gives you a reference to the new audio file object. From that point on, you work with the real audio file by communicating with the proxy object.This sort of pattern is consistent throughout Core Audio, whether you are working with audio files, iPhone audio sessions (described in ), or even hardware devices. Properties, Scopes, and ElementsMost Core Audio interfaces use a property mechanism for managing object state or refining object behavior.
A property is a key-value pair.A property key is typically an enumerator constant with a mnemonic name, such as kAudioFilePropertyFileFormat or kAudioQueueDevicePropertyNumberChannels.A property value is of a particular data type appropriate for the purpose of the propertyâa void., a Float64, an AudioChannelLayout structure, and so on.There are many Apple-defined properties. Youâll find their definitions in the various Core Audio framework header files. Some Core Audio interfaces, such as Audio Unit Services, let you define your own properties as well.Core Audio interfaces use accessor functions for retrieving a property value from an object and, in the case of a writable property, changing its value. Youâll also find a third accessor function for getting information about properties. For example, the Audio Unit Services function AudioUnitGetPropertyInfo tells you a given property value data typeâs size and whether you can change it. The Audio Queue Services function AudioQueueGetPropertySize gets a specified property valueâs size.Core Audio interfaces provide a mechanism for informing your application that a property has changed. You can read about this in the next section,.In some cases, a property applies to an audio object as a whole.
For example, to enable audio level metering in a playback audio queue object, you set the value of its kAudioQueuePropertyEnableLevelMetering property to true.Other Core Audio objects have an internal structure, each part of which may have its own set of properties. For example, an audio unit has an input scope, an output scope, and a global scope.
An audio unitâs input or output scope consists of one or more elementsâeach of which is analogous to a channel bus in audio hardware. When you call the AudioUnitGetProperty function with the kAudioUnitPropertyAudioChannelLayout property, you specify not only the audio unit you want information about but also the scope (input or output) and element (0, 1, 2, etc.). Callback Functions: Interacting with Core AudioMany Core Audio interfaces can communicate with your application using callback functions. Core Audio uses callbacks for such things as:.Delivering a new set of audio data to your application (such as for recording; your callback then writes the new data to disk).Requesting a new set of audio data from your application (such as for playback; your callback reads from disk and provides the data).Telling your application that a software object has changed state (your callback takes appropriate action).One way to understand callbacks is to reverse your perspective on who calls whom. In a normal function call, such as AudioQueueNewOutput, your application invokes behavior that is defined by Apple in the implementation of the operating system. You donât knowâand donât need to knowâwhat goes on under the hood.
Your application requests a playback audio queue object and gets one back. It works because, in making the call, you adhere to the function interface specified in the functionâs header file.In the case of a callback, the operating systemâwhen it chooses toâinvokes behavior that you implement in your application.
By defining a callback in your application according to a template, the operating system can successfully invoke it. For example, Audio Queue Services specifies a template for a callbackâthat you can implementâthat lets you get and react to messages when an audio queue object property changes.
This callback template, declared in the AudioQueue.h header file, is shown in Listing 2-1.Listing 2-1 A template for a callback function. Typedef void (.AudioQueuePropertyListenerProc) (void. inUserData,AudioQueueRef inAQ,AudioQueuePropertyID inID);To implement and use a callback in your application, you do two things:.Implement the callback function.
For example, you might implement the audio queue property listener callback to update the titles and the enabled/disabled state of buttons in your user interface, depending on whether an audio queue object is running or stopped.Register your callback function with the object you want to interact with. One way to register a callbackâtypically used for callbacks that send or receive audio dataâis during object creation: In the function call that creates the object, you pass a reference to your callback as a function parameter.
The other wayâtypically used for property listenersâis by using a dedicated function call, as you will see later in this section.Listing 2-2 shows one way you might implement a property listener callback function to respond to property changes in a playback audio queue object.Listing 2-2 A property listener callback implementation. AudioQueueAddPropertyListener (self.queueObject, // the object that will invoke your callbackkAudioQueuePropertyIsRunning, // the ID of the property you want to listen forpropertyListenerCallback, // a reference to your callback functionself);Audio Data FormatsCore Audio insulates you from needing detailed knowledge of audio data formats. Not only does this make it easier to deal with a specific format in your codeâit means that one set of code can work with any format supported by the operating system. Note: An audio data format describes audio data per se, including such things as sample rate, bit depth, and packetization. An audio file format describes how audio data, audio metadata, and filesystem metadata for a sound file are arranged on disk. Some audio file formats can contain just one sort of audio data format (for instance, an MP3 file can contain only MP3 audio data).
Other file formatsâsuch as Appleâs CAF formatâcan contain a variety of audio data formats.Universal Data Types in Core AudioIn Core Audio, you use two universal data types to represent any audio data format. These types are the data structures AudioStreamBasicDescription ( Listing 2-4) and AudioStreamPacketDescription ( Listing 2-5), both declared in the CoreAudioTypes.h header file and described in.Listing 2-4 The AudioStreamBasicDescription data type. About the name: Although this data type has âstreamâ in its name, you use it in every instance where you need to represent an audio data format in Core Audioâincluding in non-streamed, standard files. You could think of it as the âaudio format basic descriptionâ data type.
The âstreamâ in the name refers to the fact that audio formats come into play whenever you need to move (that is, stream) audio data around in hardware or software.In discussions involving Core Audio, youâll often hear âaudio stream basic descriptionâ abbreviated to âASBD,â which this document does as well.The audio stream packet description type comes into play for certain compressed audio data formats, as described in.Listing 2-5 The AudioStreamPacketDescription data type. AudioFileCreateWithURL (audioFileURL,kAudioFileCAFType,&audioFormat,kAudioFileFlagsEraseFile,&audioFileID // the function provides the new file object here);Opening a Sound FileTo open a sound file for playback, you use the AudioFileOpenURL function. You supply this function with the fileâs URL, a file type hint constant, and the file access permissions you want to use. AudioFileOpenURL gives you back a unique ID for the file.You then use property identifiers, along with the AudioFileGetPropertyInfo and AudioFileGetProperty functions, to retrieve what you need to know about the file.
Some often-used property identifiersâwhich are fairly self-explanatoryâare:.kAudioFilePropertyFileFormat.kAudioFilePropertyDataFormat.kAudioFilePropertyMagicCookieData.kAudioFilePropertyChannelLayoutThere are many such identifiers available in Audio File Services that let you obtain metadata that may be in a file, such as region markers, copyright information, and playback tempo.When a VBR file is longâsay, a podcastâobtaining the entire packet table can take a significant amount of time. In such a case, two property identifiers are especially useful: kAudioFilePropertyPacketSizeUpperBound and kAudioFilePropertyEstimatedDuration. You can use these to quickly approximate a VBR sound fileâs duration or number of packets, in lieu of parsing the entire file to get exact numbers.
Reading From and Writing To a Sound FileIn iOS you typically use Audio File Services to read audio data from, and write it to, sound files. Reading and writing are essentially mirror images of each other when you use Audio File Services. Both operations block until completion, and both can work using bytes or packets. However, unless you have special requirements, always use packets.Reading and writing by packet is the only option for VBR data.Using packet-based operations makes it much easier to compute durations.Another option in iOS for reading audio data from disk is Audio File Stream Services. For an introduction to this technology, see later in this chapter.Audio Queue Services, declared in the AudioQueue.h header file in the Audio Toolbox framework, is the Core Audio interface for recording and playback.
For an overview of Audio Queue Services, see later in this chapter. Extended Audio File ServicesCore Audio provides a convenience API called Extended Audio File Services. This interface encompasses the essential functions in Audio File Services and Audio Converter Services, providing automatic data conversion to and from linear PCM. See for more on this.
IPhone Audio File FormatsiOS supports the audio file formats listed in. For information on audio data formats available in iOS, see. Table 2-1 iOS audio file formatsFormat nameFormat filename extensionsAIFF.aif,.aiffCAF.cafMPEG-1, layer 3.mp3MPEG-2 or MPEG-4 ADTS.aacMPEG-4.m4a,.mp4WAV.wavAC-3 (Dolby Digital).ac3Enhanced AC-3 (Dolby Digital Plus).ec3CAF FilesiOS and OS X have a native audio file format, the Core Audio Format (or CAF) file format.
The CAF format was introduced in OS X v10.4 âTigerâ and is available in iOS 2.0 and newer. It is unique in that it can contain any audio data format supported on a platform.CAF files have no size restrictionsâunlike AIFF and WAVE filesâand can support a wide range of metadata, such as channel information and text annotations. For detailed information about the CAF file format, see. Sound StreamsUnlike a disk-based sound file, an audio file stream is audio data whose beginning and end you may not have access to. You encounter streams, for example, when you build an Internet radio player application.
![]()
A provider typically sends their stream continuously. When a user presses Play to listen in, your application needs to jump aboard no matter what data is going by at the momentâthe start, middle, or end of an audio packet, or perhaps a magic cookie.Also unlike a sound file, a streamâs data may not be reliably available.
There may be dropouts, discontinuities, or pausesâdepending on the vagaries of the network you get the stream from.Audio File Stream Services lets your application work with streams and all their complexities. It takes care of the parsing.To use Audio File Stream Services, you create an audio file stream object, of type AudioFileStreamID. This object serves as a proxy for the stream itself.
This object also lets your application know whatâs going on with the stream by way of properties (see ). For example, when Audio File Stream Services has determined the bit rate for a stream, it sets the kAudioFileStreamPropertyBitRate property on your audio file stream object.Because Audio File Stream Services performs the parsing, it becomes your applicationâs role to respond to being given sets of audio data and other information. You make your application responsive in this way by defining two callback functions.First, you need a callback for property changes in your audio file stream object. At a minimum, you write this callback to respond to changes in the kAudioFileStreamPropertyReadyToProducePackets property.
Table 2-2 Features provided by the audio session interfaceAudio session featureDescriptionCategoriesA category is a key that identifies a set of audio behaviors for your application. By setting a category, you indicate your audio intentions to iOS, such as whether your audio should continue when the screen locks.Interruptions and route changesYour audio session posts notifications when your audio is interrupted, when an interruption ends, and when the hardware audio route changes. These notifications let you respond to changes in the larger audio environmentâsuch as an interruption due to in an incoming phone callâgracefully.Hardware characteristicsYou can query the audio session to discover characteristics of the device your application is running on, such as hardware sample rate, number of hardware channels, and whether audio input is available.Audio Session Default BehaviorAn audio session comes with some default behavior. Specifically:.When the user moves the Ring/Silent switch to silent, your audio is silenced.When the user presses the Sleep/Wake button to lock the screen, or when the Auto-Lock period expires, your audio is silenced.When your audio starts, other audio on the deviceâsuch as iPod audio that was already playingâis silenced.This set of behaviors is specified by the default audio session category, namely kAudioSessionCategorySoloAmbientSound. IOS provides categories for a wide range of audio needs, ranging from user-interface sound effects to simultaneous audio input and output, as you would use for a VOIP (voice over Internet protocol) application. You can specify the category you want at launch and while your application runs.Audio session default behavior is enough to get you started in iPhone audio development.
Except for certain special cases, however, the default behavior is unsuitable for a shipping application, as described next. Interruptions: Deactivation and ActivationOne feature conspicuously absent from a default audio session is the ability to reactivate itself following an interruption. An audio session has two primary states: active and inactive. Audio can work in your application only when the audio session is active.Upon launch, your default audio session is active. However, if a phone call comes in, your session is immediately deactivated and your audio stops. This is called an interruption. If the user chooses to ignore the phone call, your application continues running.
But with your audio session inactive, audio does not work.If you use OpenAL, the I/O audio unit, or Audio Queue Services for audio in your application, you must write an interruption listener callback function and explicitly reactivate your audio session when an interruption ends. Provides details and code examples.If you use the AVAudioPlayer class, the class takes care of audio session reactivation for you. Determining if Audio Input is AvailableA recording application on an iOS-based device can record only if hardware audio input is available. To test this, you use the audio session kAudioSessionPropertyAudioInputAvailable property. This is important when your application is running on devices like the iPod touch (2nd generation), which gain audio input only when appropriate accessory hardware is attached. Listing 2-10 shows how to perform the test.Listing 2-10 Determining if a mobile device supports audio recording. UInt32 audioInputIsAvailable;UInt32 propertySize = sizeof (audioInputIsAvailable);AudioSessionGetProperty (kAudioSessionPropertyAudioInputAvailable,&propertySize,&audioInputIsAvailable // A nonzero value on output means that// audio input is available);Using Your Audio SessionYour application has just one audio session category at a timeâso, at a given time, all of your audio obeys the characteristics of the active category.
(The one exception to this rule is audio that you play using System Sound Servicesâthe API for alerts and user-interface sound effects. Such audio always uses the lowest priority audio session category.) in describes all the categories.When you add audio session support to your application, you can still run your app in the Simulator for development and testing. However, the Simulator does not simulate session behavior. To test the behavior of your audio session code, you need to run on a device. Note: Ignoring Audio Session Services will not prevent your application from running, but your app may not behave the way you want it to. In most cases, you should not ship an iPhone or iPod touch application that uses audio without using this interface, as described earlier in this section.Playback using the AVAudioPlayer ClassThe AVAudioPlayer class provides a simple Objective-C interface for audio playback. NSString.soundFilePath =NSBundle mainBundle pathForResource: @'sound'ofType: @'wav';NSURL.fileURL = NSURL alloc initFileURLWithPath: soundFilePath;AVAudioPlayer.newPlayer =AVAudioPlayer alloc initWithContentsOfURL: fileURLerror: nil;fileURL release;self.player = newPlayer;newPlayer release;self.player prepareToPlay;self.player setDelegate: self;You use a delegate object (which can be your controller object) to handle interruptions and to update the user interface when a sound has finished playing.
The delegate methods for the AVAudioPlayer class are described in. Listing 2-12 shows a simple implementation of one delegate method. This code updates the title of a Play/Pause toggle button when a sound has finished playing.Listing 2-12 Implementing an AVAudioPlayer delegate method. self.player setVolume: 1.0; // available range is 0.0 through 1.0For more information on the AVAudioPlayer class, see. Recording and Playback using Audio Queue ServicesAudio Queue Services provides a straightforward, low overhead way to record and play audio.
It lets your application use hardware recording and playback devices (such as microphones and loudspeakers) without knowledge of the hardware interface. It also lets you use sophisticated codecs without knowledge of how the codecs work.Although it is a high-level interface, Audio Queue Services supports some advanced features. It provides fine-grained timing control to support scheduled playback and synchronization. You can use it to synchronize playback of multiple audio queues, to play sounds simultaneously, to independently control playback level of multiple sounds, and to perform looping.
Audio Queue Services and the AVAudioPlayer class (see ) are the only ways to play compressed audio on an iPhone or iPod touch.You typically use Audio Queue Services in conjunction with Audio File Services (as described in ) or with Audio File Stream Services (as described in ). Audio Queue Callback Functions for Recording and PlaybackAs is the case with Audio File Stream Services, you interact with audio queue objects using callbacks and properties.
For recording, you implement a callback function that accepts audio data buffersâprovided by your recording audio queue objectâand writes them to disk. Your audio queue object invokes your callback when there is a new buffer of incoming data to record. Figure 2-2 illustrates a simplified view of this process. Figure 2-2 Recording with an audio queue objectFor playback, your audio callback has a converse role. It gets called when your playback audio queue object needs another bufferâs worth of audio to play. Your callback then reads a given number of audio packets from disk and hands them off to one of the audio queue objectâs buffers.
The audio queue object plays that buffer in turn. Figure 2-3 illustrates this.
Float32 volume = 1;AudioQueueSetParameter (myAQstruct.audioQueueObject,kAudioQueueParamVolume,volume);You can also set playback level for an audio queue buffer, using the AudioQueueEnqueueBufferWithParameters function. This lets you assign audio queue settings that are, in effect, carried by an audio queue buffer as you enqueue it. Such changes take effect when the audio queue buffer begins playing.In both cases, level changes for an audio queue remain in effect until you change them again.
Indicating Audio Queue Playback LevelYou can obtain the current playback level from an audio queue object by querying its kAudioQueuePropertyCurrentLevelMeterDB property. The value of this property is an array of AudioQueueLevelMeterState structures, one per channel. Listing 2-16 shows this structure:Listing 2-16 The AudioQueueLevelMeterState structure. Table 2-5 iOS: recording audio formatsApple LosslessiLBC (internet Low Bitrate Codec, a speech codec)IMA/ADPCM (also known as IMA-4)Linear PCMµLaw and aLawIn OS X, you find a wide array of codecs and supported formats, described in.OS X also provides interfaces for using and creating audio data codecs.
These interfaces are declared in the AudioConverter.h header file (in the Audio Toolbox framework) and AudioCodec.h (in the Audio Unit framework). Describes how you might use these services.
Audio Processing GraphsAn audio processing graph (sometimes called an AUGraph) defines a collection of audio units strung together to perform a complex task. For example, a graph could distort a signal, compress it, and then pan it to a particular location in the soundstage. When you define a graph, you have a reusable processing module that you can add to and remove from a signal chain in your application.A processing graph typically ends in an I/O unit (sometimes called an output unit).
An I/O unit often interfaces (indirectlyâvia low-level services) with hardware, but this is not a requirement. An I/O unit can send its output, instead, back to your application.You may also see an I/O unit referred to as the head node in a processing graph. I/O units are the only ones that can start and stop data flow in a graph. This is an essential aspect of the so-called pull mechanism that audio units use to obtain data. Each audio unit in a graph registers a rendering callback with its successor, allowing that successor to request audio data. When an I/O unit starts the data flow (triggered, in turn, by your application), its render method calls back to the preceding audio unit in the chain to ask for data, which in turn calls its predecessor, and so on.iOS has a single I/O unit, as described in.
The story on OS X is a bit more complex.The AUHAL unit is for dedicated input and output to a specific hardware device. See Technical Note TN2091,.The Generic I/O unit lets you connect the output of an audio processing graph to your application. You can also use a generic I/O unit as the head node of a subgraph, as you can see in.The System I/O unit is for alerts and user interface sound effects.The Default I/O unit is for all other audio input and output.The Audio MIDI Setup application (Mac only; in the Utilities folder) lets a user direct the connections of the System I/O and Default I/O units separately.Figure 2-4 shows a simple audio processing graph, in which signal flows from the top to the bottom.
Figure 2-4 A simple audio processing graphEach audio unit in an audio processing graph can be called a node. You make a processing graph connection by attaching an output from one node to the input of another.
You cannot connect a single output to more than one input unless you use an intervening splitter unit, as shown in Figure 2-5. Figure 2-5 How to fan out an audio unit connectionHowever, an audio unit may be designed to provide multiple outputs or inputs, depending on its type. A splitter unit does this, for example.You can use Audio Processing Graph Services to combine subgraphs into a larger graph, where a subgraph appears as a single node in the larger graph.
Figure 2-6 illustrates this. Figure 2-6 A subgraph connectionEach graph or subgraph must end in an I/O unit. A subgraph, or a graph whose output feeds your application, should end with the generic I/O unit, which does not connect to hardware.While you can link audio units programmatically without using an audio processing graph, itâs rarely a good idea.
Graphs offer important advantages. You can modify a graph dynamically, allowing you to change the signal path while processing data. In addition, because a graph encapsulates an interconnection of audio units, you instantiate a graph in one step instead of explicitly instantiating each of the audio units it references. MIDI Services in OS XCore Audio uses Core MIDI Services for MIDI support. These services consist of the functions, data types, and constants declared in the following header files in CoreMIDI.framework:.MIDIServices.h.MIDISetup.h.MIDIThruConnection.h.MIDIDriver.hCore MIDI Services defines an interface that applications and audio units can use to communicate with MIDI devices. It uses a number of abstractions that allow an application to interact with a MIDI network.A MIDI endpoint (defined by an opaque type MIDIEndpointRef) represents a source or destination for a standard 16-channel MIDI data stream.
You can associate endpoints with tracks used by Music Player Services, allowing you to record or play back MIDI data. A MIDI endpoint is a proxy object for a standard MIDI cable connection. MIDI endpoints do not necessarily have to correspond to a physical device, however; an application can set itself up as a virtual source or destination to send or receive MIDI data.MIDI drivers often combine multiple endpoints into logical groups, called MIDI entities ( MIDIEntityRef). For example, it would be reasonable to group a MIDI-in endpoint and a MIDI-out endpoint as a MIDI entity, which can then be easily referenced for bidirectional communication with a device or application.Each physical MIDI device (not a single MIDI connection) is represented by a Core MIDI device object ( MIDIDeviceRef). Each device object may contain one or more MIDI entities.Core MIDI communicates with the MIDI Server, which does the actual job of passing MIDI data between applications and devices.
The MIDI Server runs in its own process, independent of any application. Figure 2-7 shows the relationship between Core MIDI and MIDI Server. Figure 2-7 Core MIDI and Core MIDI ServerIn addition to providing an application-agnostic base for MIDI communications, MIDI Server also handles any MIDI thru connections, which allows device-to device chaining without involving the host application.If you are a MIDI device manufacturer, you may need to supply a CFPlugin plug-in for the MIDI Server packaged in a CFBundle to interact with the kernel-level I/O Kit drivers. Figure 2-8 shows how Core MIDI and Core MIDI Server interact with the underlying hardware. Note: If you create a USB MIDI class-compliant device, you do not have to write your own driver, because Appleâs supplied USB driver will support your hardware.Figure 2-8 MIDI Server interface with I/O KitThe drivers for each MIDI device generally exist outside the kernel, running in the MIDI Server process.
These drivers interact with the default I/O Kit drivers for the underlying protocols (such as USB and FireWire). The MIDI drivers are responsible for presenting the raw device data to Core MIDI in a usable format. Core MIDI then passes the MIDI information to your application through the designated MIDI endpoints, which are the abstract representations of the MIDI ports on the external devices.MIDI devices on PCI cards, however, cannot be controlled entirely through a user-space driver. For PCI cards, you must create a kernel extension to provide a custom user client. This client must either control the PCI device itself (providing a simple message queue for the user-space driver) or map the address range of the PCI device into the address of the MIDI server when requested to do so by the user-space driver. Doing so allows the user-space driver to control the PCI device directly.For an example of implementing a user-space MIDI driver, see MIDI/SampleUSBDriver in the Core Audio SDK.
Music Player Services in OS XMusic Player Services allows you to arrange and play a collection of MIDI music tracks.A track is a stream of MIDI or event data (represented by the MusicTrack data type). Tracks contain a series of time-based events, which can be MIDI data, Core Audio event data, or custom event messages. You can think of a track as sheet music for one instrument.A sequence is a collection of tracks (represented by the MusicSequence data type). A sequence always contains an separate tempo track, used for synchronizing all its tracks. You can think of a sequence as a musical score, which collects the sheet music for multiple instruments. Your Mac app can add, delete, or edit tracks in a sequence dynamically.To play a sequence you assign it to a music player object (of type MusicPlayer), which acts as the conductor, controlling the playback of the sequence. To produce sound, you send each track to an instrument unit or to an external MIDI device.Track data does not have to represent musical information.
You could instead use a track to implement audio unit automation. For example, a track assigned to a panner unit could control the apparent position of a sound source in the soundstage. Tracks can also contain proprietary user events that trigger an application-defined callback.For more information about using Music Player Services to play MIDI data, see. Timing Services in OS XCore Audio Clock Services provides a reference clock that you can use to synchronize applications and devices. This clock may be a standalone timing source or it can be synchronized with an external trigger, such as a MIDI beat clock or MIDI time code.
You can start and stop the clock yourself, or you can set the clock to activate or deactivate in response to certain events.You can obtain the generated clock time in a number of formats, including seconds, beats, SMPTE time, audio sample time, and bar-beat time. The latter describes the time in a manner that is easy to display onscreen in terms of musical bars, beats, and subbeats.
Core Audio Clock Services also contains utility functions that convert one time format to another and that display bar-beat or SMPTE times. Figure 2-9 shows the interrelationship between various Core Audio Clock formats.
Figure 2-9 Some Core Audio Clock formatsThe hardware times represent absolute time values from either the host time (the system clock) or an audio time obtained from an external audio device (represented by an AudioDevice object in the HAL). You determine the current host time by calling machabsolutetime or UpTime.
The audio time is the audio deviceâs current time represented by a sample number. The sample numberâs rate of change depends on the audio deviceâs sampling rate.The media times represent common timing methods for audio data. The canonical representation is in seconds, expressed as a double-precision floating point value. However, you can use a tempo map to translate seconds into musical bar-beat time, or apply a SMPTE offset to convert seconds to SMPTE seconds.Media times do not have to correspond to real time. For example, an audio file that is 10 seconds long will take only 5 seconds to play if you double the playback rate.
The knob in indicates that you can adjust the correlation between the absolute (ârealâ) times and the media-based times. For example, bar-beat notation indicates the rhythm of a musical line and what notes to play when, but does not indicate how long it takes to play. To determine that, you need to know the playback rate (say, in beats per second). Similarly, the correspondence of SMPTE time to actual time depends on such factors as the frame rate and whether frames are dropped or not.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |