Solved

Playing real-time sound

Posted on 1997-11-26
5
225 Views
Last Modified: 2012-06-21
I'm working on a project, where I have to create sound in
real-time. The waveform is 8 bit PCM. I have tried to use
low level audio functions as described in DirectSound.

I'm using VC5.0++

When I'm playing a sound-sample I can hear some weak
noise as long as spesified.

I have used this functions:

DirectSoundCreate
SetCooperativeLevel
CreateSoundBuffer
Lock
memcpy
Unlock
SetCurrentPosition
Play

all of are returning "DS_OK", but the sound are not playing.

Please help.
0
Comment
Question by:hakon
5 Comments
 
LVL 2

Expert Comment

by:anichini
ID: 1174184
You might want to check to make sure the waveform data you are copying into the direct sound buffer is in the correct format and at the correct sampling rate. For example, 8 bit PCM is unsigned, so 128 is "zero". (So for example if you had a 22 khz, 8 bit buffer, a 11 khz square wave would be [255, 0, 255, 0, 255, ...])

0
 
LVL 2

Expert Comment

by:AlFa
ID: 1174185
Have you checked the DSCAPS (with GetCaps) of your device?

0
 

Author Comment

by:hakon
ID: 1174186
Yes, I have checked the DSCAPS. Everything seems OK.

Now I'm using waveOut-functions. They are working, but I
hear a short silence between blocks of waveform data. I can
probably use this solution.
0
 
LVL 23

Accepted Solution

by:
chensu earned 180 total points
ID: 1174187
Look into two samples that come with DirectX SDK: DSSHOW and DSSTREAM. And, you can use the functions in samples\misc\dsutil.c directly. Since you create the sound samples in real-time, you may use BOOL DSFillSoundBuffer(IDirectSoundBuffer *pDSB, BYTE *pbWaveData, DWORD cbWaveSize) function in dsutil.c.
0
 

Author Comment

by:hakon
ID: 1174188
Thanks !
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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