DirectSound Learning guide Using WAV Data

Source: Internet
Author: User
Tags resource

Using WAV data

In Windows drive Model (WDM), the DirectSound hardware buffer can play any uncompressed or compressed sound format that can be described by a waveformatex or waveformatextensible structure and supported by hardware. Software buffers and non-WDM hardware buffers support only 8-bit and 16-bit uncompressed formats.

Waveform (WAV) data is typically stored in a file or resource in a resource Interchange File format (RIFF). The data includes a WAV format description containing parameters such as sample rate and output channel number.

Multi-band WAV format

In WDM drives, the DirectSound buffer supports WAV format with more than two output channels. For speaker configurations such as 5.1, it has speakers at the front left, middle, right, background left, right, and low-frequency intensifier.

The waveformatextensible structure describes a multi-channel waveform format. This structure is an extension of the WAVEFORMATEX, configured with additional bytes that have been supported by cbsize members in WaveFormatEx. Where WaveFormatEx is needed, the waveformatextensible structure can be transformed into WaveFormatEx.

If the system is configured with fewer physical speakers than the number of channels specified in a multi-band WAV file, the audio data is properly blended and exported to the existing speakers. DirectSound does not support 3D processing and effects of multi-band-format buffers. Attempts to create a buffer with a dsbcaps_ctrl3d or dsbcaps_ctrlfx identity and a multi-band WAV format will fail.

Read WAV data

A WAV file is a resource Interchange File format (RIFF) that consists of a number of named blocks that contain header information, such as sound sampling format, or data (the sample itself). The WIN32 API provides functions such as opening and closing riff files, exploring blocks, and so on. These function names begin with "Mmio".

To store WAV sounds in an executable way, import WAV files as resources and name them. Note the Cwavefile class expects that these resources are wave or WAV types and are executable modules rather than a DLL.

The DirectSound API does not contain methods for loading sound data. However, the Dsutil.cpp file is used by many SDK example programs to implement several classes that can be used to create sound buffers from files, resources, or a memory address.

The steps to initialize DirectSound using an example class and to create a load buffer include:

1. Create an object for the Csoundmanager example class.

2. Call Csoundmanager::initialize to create a device object.

3. Pass a file or resource name to Csoundmanager::create or pass a memory address to csoundmanager::createfrommemory. These methods return an object of the Csound example class that represents one or more static buffers of the size that fit the data. (You can create multiple buffers to play multiple sound instances at the same time) or pass a file or resource name to the Cstreamingsound example class. This method returns an object of the Cstreamingsound example class, which represents a separate stream buffer.

4. Invokes the Fillbufferwithsound method in the object obtained in the previous step. It reads data from a file, resource, or memory address into a buffer. For a stream buffer, it fills the buffer with the maximum data that can be accommodated and uses cstreamingsound::handlewavestreamnotification to update the data while playing the buffer.

Note that the actual data reads are done by a Cwavefile object, which is a protected member of the Csound or Cstreamingsound object. You usually do not have to use the Cwavefile class directly, however, you can refer to the implementation of this class to obtain information to analyze WAV data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.