共用方式為


Loading Audio Data

Many DirectMusic objects have to be loaded from a file or resource before they can be incorporated into a performance. The IDirectMusicLoader8 interface is used to manage the enumeration and loading of such objects, as well as to cache them so that they are not loaded more than once.

Note Do not load data from untrusted sources. Loading DirectMusic data files causes objects to be constructed, with the possibility that excessive demand on resources will lead to degradation of performance or system failure.

An application should have only one instance of the loader in existence at a time. You should create a single global loader object and not free it until there is no more loading to be done. This strategy ensures that objects are found and cached efficiently.

When objects are loaded from a memory location or a stream, the application should not touch the data until the loader is released. Because of caching and other internal mechanisms, the loader might try to access the data at a later time. To load new data, always allocate a new buffer or create a new stream.

The DirectMusic implementation of IStream streams the data from the source. The parsing of the data is handled by the various objects themselves through their implementations of IPersistStream. As long as you are dealing only with standard DirectMusic data, you don't have to use these interfaces directly.

Loading of objects referenced by other objects is handled transparently. For example, suppose a segment being loaded from a DirectMusic Producer file contains a reference to a WAV sound in another file. When the segment's implementation of IPersistStream::Load finds the reference, it obtains the IDirectMusicGetLoader8 interface from the stream object. Using this interface, it obtains a pointer to the loader object. Then it calls IDirectMusicLoader8::GetObject to load the WAV sound.

More information on using the loader is contained in the following topics:

See Also

© 2004 Microsoft Corporation. All rights reserved.