Jump to content
  • Advertisement
Sign in to follow this  
ctaclas

beginner question

This topic is 5408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i recently bought a book called fundamentals of audio and video programming for games published by microsoft press, i found it in the bargain bin at compusa :) i've read the first chapter, which is a simple program that demonstrates how to play sounds. i've been able to follow it, it seems relatively straightforward, but obviously i want to start playing with it. the example in the book uses a utility file called dsutil.cpp. the way the book describes it, it is a generic utility file that comes with the sdk. when i try to compile the book's example, it doesn't work because it can't find the utility file. the utility file isn't in my direct x sdk directories either. thinking maybe my bargain bin book was outdated and that theres no longer a file called dsutil.cpp, i checked out the directx documentation. out of curiosity i did a search for the dsutil.cpp file in the documentation, and it said that it should be in (SDK root)\samples\C++\Common\Src\Dsutil.cpp. however, when i go to the common directories, there is no Src subdirectory. in fact theres no subdirectories in Common. theres a couple of .cpp files but i don't think they're what i'm looking for. i'm wondering if somethings wrong with my installation of the sdk, or maybe i got the wrong one. i got my directx stuff from microsoft's page, and the file was called dxsdk_sum2004.exe. thanks

Share this post


Link to post
Share on other sites
Advertisement
How old is the book? The SDK you downloaded is the latest and greatest. Many many things have changed since the book's release (probably). Some files will be different. Did the book not have a version of the SDK included with it? That is the one you would want to install (if you want to use that book to learn it). On the other hand, if you really had your curiousity peeked, stay away from out-of-date books for the most part. There are the general concepts you need to learn of course, but if it's a book that goes into detail about how to use Direct Sound, then you will want to read the latest on that, because significant changes between old SDK's and the latest one could cause you to explode. This applies really more to the graphics part than the sound part.

So, like I said, if you're really interested in the up-to-date stuff, then check out the tutorials listed numerous times on this website by doing a search for them. You'll see the good ones are listed repetitive times. Also check out the Articles and For Beginners links above. That should get you going in the right direction.

Good luck,
Chris

Share this post


Link to post
Share on other sites
i opened up the cover and it has a copyright 2004, so it can't be that old, although i suspect it was probably written last year. i'd just assume that the book sucks if it weren't for the documentation mentioning the same file. the documentation about the sample programs mentions two directories with the sample framework:
SDK root)\samples\C++\Common\Include
(SDK root)\samples\C++\Common\Src

i have the (sdk root)\samples\c++\common, but i don't have the include or src folders. maybe i messed up the installation? if somebody with that version of directx could see if they have those folders that would be good. if i don't have it and other people do, i'll try run the installation thing again.

oh yeah, and is the only thing i have to do is run the self extracting file dxsdk_sum2004.exe? is there anything else i gotta do to install? i'll try check that real fast too

Share this post


Link to post
Share on other sites
Your book was probably (almost certainly) written before the summer update 2004. If you want to use that book, figure which SDK version it uses and get the same version.

Share this post


Link to post
Share on other sites
Mine has all of the files in it, but I have Summer 2003 Update. Try reinstalling though. Maybe you didn't select the examples as part of the install.

Share this post


Link to post
Share on other sites
Summer 2003 has the files you wanted,if u wanna use Summer 2004,make sure you extract three files from 2003 SDK:dsutil.h, dxutil.h, dsutil.cpp as I do :-)
This is my simple sound class build on DSound before,it's simple but works well:

XSound.h

#pragma once
#include "dsutil.h"

//This class need XSound.h, XSound.cpp, dsutil.h, dxutil.h, dsutil.cpp in one directory
//and need link with dsound.lib, dxerr9.lib

class XSound
{
CWaveFile m_WaveFile;
CSound* m_pSound;
CSoundManager m_Manager;
LPDIRECTSOUND8 m_pDS;
WAVEFORMATEX* m_pwfx;
DWORD m_dwDataLen;
DSBUFFERDESC m_dsbd;
LPDIRECTSOUNDBUFFER m_pDSB;
public:
XSound();
~XSound(void);
void Initialize(void);
BOOL LoadWaveFile(LPTSTR strWaveFileName);
void Play(long lPan=0,BOOL bLoop=FALSE,long lVolume=0);
void Replay(long lPan=0,BOOL bLoop=FALSE,long lVolume=0);
void Stop(void);
BOOL IsPlaying(void);
void Reset(void);
};


XSound.cpp

#include "StdAfx.h"
#include ".\xsound.h"
#include "dsutil.cpp"

XSound::XSound()
{
m_pDS=NULL;
m_pDSB=NULL;
m_pwfx=NULL;
m_dwDataLen=0;
}

XSound::~XSound(void)
{
SAFE_RELEASE(m_pDSB);
SAFE_RELEASE(m_pDS);
}

//initialize this class after app started
void XSound::Initialize(void)
{
DirectSoundCreate8(NULL,&m_pDS,NULL);
m_pDS->SetCooperativeLevel(g_hWnd,DSSCL_NORMAL);
}

//only WAVE file
BOOL XSound::LoadWaveFile(LPTSTR strWaveFileName)
{
//open wave file
if(FAILED(m_WaveFile.Open(strWaveFileName,m_pwfx,WAVEFILE_READ)))
return FALSE;
//get wave format and length
m_pwfx=m_WaveFile.GetFormat();
m_dwDataLen=m_WaveFile.GetSize();
//fill struct m_dsbd
ZeroMemory(&m_dsbd,sizeof(m_dsbd));
m_dsbd.dwSize=sizeof(m_dsbd);
m_dsbd.dwFlags=DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_STATIC;
m_dsbd.dwBufferBytes=m_dwDataLen;
m_dsbd.lpwfxFormat=m_pwfx;
m_dsbd.guid3DAlgorithm=GUID_NULL;
//create sound buffer
m_pDS->CreateSoundBuffer(&m_dsbd,&m_pDSB,NULL);
//close wave file
m_WaveFile.Close();
//translate date to buffer
m_Manager.Initialize(g_hWnd,DSSCL_NORMAL);
m_Manager.Create((CSound**)&m_pSound,strWaveFileName);
m_pSound->FillBufferWithSound(m_pDSB,FALSE);

return TRUE;
}

//start playing sound which loaded in this class until stop it or it was end without "bLoop"
//lPan is in the range of DSBPAN_LEFT(-10,000) to DSBPAN_RIGHT(+10,000),refer to IDirectSoundBuffer8::SetPan()
//lVolume is in the range of DSBVOLUME_MIN(-10,000) to DSBVOLUME_MAX(0),refer to IDirectSoundBuffer8::SetVolume()
void XSound::Play(long lPan,BOOL bLoop,long lVolume)
{
if(bLoop)
{
m_pDSB->SetVolume(lVolume);
m_pDSB->SetPan(lPan);
m_pDSB->Play(0,0,DSBPLAY_LOOPING);
}
else
{
m_pDSB->SetVolume(lVolume);
m_pDSB->SetPan(lPan);
m_pDSB->Play(0,0,0);
}
}

//call this method to restart playing the sound,
//the only difference from Play() is play the sound from start
void XSound::Replay(long lPan,BOOL bLoop,long lVolume)
{
if(bLoop)
{
m_pDSB->SetCurrentPosition(0);
m_pDSB->SetVolume(lVolume);
m_pDSB->SetPan(lPan);
m_pDSB->Play(0,0,DSBPLAY_LOOPING);
}
else
{
m_pDSB->SetCurrentPosition(0);
m_pDSB->SetVolume(lVolume);
m_pDSB->SetPan(lPan);
m_pDSB->Play(0,0,0);
}
}

//call this method whenever u wanna stop playing
void XSound::Stop(void)
{
m_pDSB->Stop();
}

//check whether the sound is playing
BOOL XSound::IsPlaying(void)
{
DWORD dwStatus;
m_pDSB->GetStatus(&dwStatus);
if(dwStatus==DSBSTATUS_PLAYING || dwStatus==DSBSTATUS_LOOPING)
return TRUE;

return FALSE;
}

//move play line to the start
void XSound::Reset(void)
{
m_pDSB->SetCurrentPosition(0);
}

Share this post


Link to post
Share on other sites
My version of the SDK came as a ZIP file which when unzipped made a tempary directory on the C: in which was a setup.exe. If you've got a similar setup then you'll need to run that too.

Hope that helps

Matt

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i just reinstalled the sdk and went through that setup thing after the zip file, and i'm pretty sure i selected all the features, but it gave me the same setup as before...

i went to MSDN and it seems like i should have the folders...
right about now the particular files i'm interested probably aren't required, but maybe theres other files supposed to be in those folders that i might need later on

Microsoft DirectX 9.0 SDK Update (Summer 2004)

DirectSound Sample Framework
The core functionality for the DirectSound samples is in a common set of classes, declared in Dsutil.h and implemented in Dsutil.cpp.

These files are found in the following folders:

(SDK root)\samples\C++\Common\Include
(SDK root)\samples\C++\Common\Src
To use the sample framework, your project must link to Dxerr9.lib and Winmm.lib.

The framework classes provide basic functionality for the samples, and you can use them as a starting-point for your own applications. However, they are not intended to be a full-featured wrapper for the DirectSound API.

The following classes are used in the samples:

Class Description
CSound Sample Class Represents a static buffer.
CSoundManager Sample Class Contains functionality for creating and initializing DirectSound, accessing the primary buffer, and creating secondary buffers.
CStreamingSound Sample Class Represents a sound in one or more streaming buffers.
CWaveFile Sample Class Used for reading from and writing to WAV files and reading from WAV resources or waveforms stored in memory.


See Also

DirectSound C++ Samples

--------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!