Solved

Describe buffer format for waveOut()

Posted on 1997-10-14
1
227 Views
Last Modified: 2013-12-03
I successfully used the Win32 API waveOut() call to output some sound to my sound blaster.
waveOutWrite() requires the passing of a pointer to a structure that contains information about the sound to be played. One of the members of this structure is the "buffer":

WAVEHDR WaveHeader;
WaveHeader.lpData = buffer;

I tried specifying something like

WaveHeader.lpData = "balljljsdfljweriwoejrasdafafsff";

and as I expected I received random garbage sound.

I'd like someone to explain how the format of the buffer is interpreted exactly (in 8 bit mode). What does the content of the buffer do to the sound that is output? Please point me to a very specific site that explains the format or explain it yourself. Thanks.
0
Comment
Question by:jawed
1 Comment
 
LVL 5

Accepted Solution

by:
y96andha earned 100 total points
ID: 1407575
Every byte in the buffer is a sample that is output to the speaker. 0x00 is the lowest possible value, 0x80 is the midpoint value and 0xff is highest value.

A buffer containing {0x00, 0xff, 0x00, 0xff ...} will produce a square wave with maximum amplitude.

A buffer containing {0x80, 0x80, 0x80 ...} will produce no output at all.

A buffer containing {0x70, 0x70, 0x70 ...} would optimally produce a weak negative DC.

For a nicer sound than a square wave, try for example to fill the buffer with sine values, like
 buf[i] = 0x80 + 0x40 * sin(i / 16.0 * 2*3.14159)
Playing back this buffer at 8kHz would yield a 500 Hz sine wave with an amplitude of 50% maximum amplitude.

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now