Solved

Describe buffer format for waveOut()

Posted on 1997-10-14
1
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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