» »

[C++ DirectX] DirectSound vodič za začetnike

[C++ DirectX] DirectSound vodič za začetnike

Phil ::

A kdo mogoce ve za kaksen DirectSound tutorial za VC++.
Zanima me kako kreirati buffer, vanj naloziti wav in ga predvajati.
LP
  • spremenilo: CCfly ()

Senitel ::

Ker DirectX SDK imaš?

Phil ::

Pomoje,da je 5-ka k je zraven VC++ 6.0 . A če hočeš 8.0 dol potegnt a je treba cel paket (137Mb 8-O) a se da dobit knjizice sam za zvok?
LP

Zgodovina sprememb…

  • spremenil: Phil ()

Senitel ::

Zraven VC++ 6.0 je DirectX 3.0 :(...

Phil ::

Ups my mistake :8).
Zdej sm dobu neki v MSDNju bom probal s tam, sam ne vem a v MSDNju zanalasc komplicirajo kr 5 strani kode za en zvok predvajat se mi zdi pa res prevec.
LP

Senitel ::

Ne sej ni tolk hudo... Ti bom juter postal en mal simple kode, OK?

Senitel ::

#pragma comment(lib,"dsound.lib")
#include
#define SafeKill(a) if (a) { (a)->Release(); (a)=NULL; }

LPDIRECTSOUND lpSound;
LPDIRECTSOUNDBUFFER lpPrimary;
LPDIRECTSOUNDBUFFER lpSecondary;
HRESULT hr;

hr=DirectSoundCreate(NULL,&lpSound,NULL);
if (hr!=DS_OK) return 1; // DirectSound ne obstaja?
hr=lpSound->SetCooperativeLevel(Window,DSSCL_NORMAL);
if (hr!=DS_OK) { SafeKill(lpSound); return 2; } // Hmm?

DSBUFFERDESC BufferDesc;
ZeroMemory(&BufferDesc,sizeof(DSBUFFERDESC));
BufferDesc.dwSize=sizeof(DSBUFFERDESC);
BufferDesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
hr=lpSound->CreateSoundBuffer(&BufferDesc,&lpPrimary,NULL);
if (hr!=DS_OK) { SafeKill(lpSound); return 3; } // Ne moremo kreirat primary bufferja

ZeroMemory(&BufferDesc,sizeof(DSBUFFERDESC));
BufferDesc.dwSize=sizeof(DSBUFFERDESC);
BufferDesc.dwFlags=DSBCAPS_DEFAULT | DSBCAPS_STATIC;
BufferDesc.dwBufferBytes=1024;
hr=lpSound->CreateSoundBuffer(&BufferDesc,&lpSecondary,NULL);
if (hr!=DS_OK) { SafeKill(lpSound); SafeKill(lpPrimary); return 4; } // Ne moremo kreirat secondary bufferja

BYTE* pBuf=NULL;
DWORD Size=1024;
lpSecondary->Lock(0,Size,(LPVOID)pBuf,&Size,NULL,NULL,DSBLOCK_ENTIREBUFFER);
for (UINT n=0; n lpSecondary->UnLock(0,Size,NULL,NULL);

lpSecondary->Play(0,0,0);

Eko upam, da bo delal (ker je spisano v notepadu). Uživaj v random zvoku >:D...

NoUse4AName ::

gamedev idi pod sekcijo articles and resources

Zgodovina sprememb…

ElNuncio ::

Sem iskal kasen "normalen" tutorial za directsound pa ne najdem nic kaj dosti koristnega. Kaj mogoce kdo ve kje je kaksen enostaven primer, ki ga zalaufas in odigra en WAVE file, nic drugega :) Po poznosti koda v C/C++.

Hvala

Senitel ::

Eko tole upam da bo vredu.

Sayer ::

Od ver DirectX 8.1 imas na voljo DirectMusic ...

Senitel ::

DirectMusic se je pojavil v DirectX 6.1 potem pa dvomim, da se je sploh se kaj spreminjal. In ker je zadeva postavljena cez DirectSound to tudi pomeni, da uporabljas staro verzijo DirectSound.

Sayer ::

6.1 ? brrrr

DirectMusic se je precej spremenil v ver 8.1, iz prakticno neuporabnega librarya (vsaj za game production) se je razvil v precej spodobno zadevo:
Pa poglejmo kaj pravi SDK 8.1:

Integration of waves and message-based sounds in a single playback mechanism

Wave files and resources can now be loaded by the DirectMusic loader and played by the DirectMusic performance. The application no longer needs to parse the wave and copy or stream it to a DirectSound buffer. The timing of wave playback is based on the DirectMusic master clock, and waves can be synchronized to musical events and processed by tools just like any other segment.

The DirectSound API continues to be supported, and you can still play waves directly through DirectSound buffers. DirectSound continues to be the API for wave capture and full duplex.

More flexible and powerful audiopath model

In previous versions of DirectMusic, performance channels were mapped to ports, and each port sent its output to a single DirectSound buffer. Under the new model, channels in a segment are mapped to audiopaths that control the data flow from the performance to the final output. Output from the synthesizer can be sent to multiple playback buffers, each with its own 3-D positioning and effects. Audiopaths can be created dynamically by the application or authored into segments.

Individual control over segment states

Each playing instance of a segment can have its own audiopath, so parameters such as volume, pan, and pitch bend can be modified for each segment state individually.

DLS2 Synthesis

The DirectMusic synthesizer is now based on the Downloadable Sounds (DLS) Level 2 standard, providing higher-quality sound synthesis. New features of the DLS2 synthesizer include six-stage envelopes, layering of voices, release waveforms, and additional low-frequency oscillators (LFOs). Each voice has an optional low-pass resonant filter.

Special effects

DirectX Media Objects can be attached to sound buffers to add effects. Standard effects such as musical reverb, I3DL2 (Interactive 3-D Audio Level 2) environmental reverb, distortion, and echo are provided by DirectX Audio, and third-party effects can be added.

Greater control over cueing

A composer can set points in a segment that specify where the segment can begin playback, so that the segment can maintain its relationship to the time signature. Primary segments can contain arbitrary points where other segments can be cued, allowing greater control than cueing to the nearest measure, beat, or grid. A new segment cue flag, DMUS_SEGF_SEGMENTEND, causes the segment to play when the current primary segment finishes playing.

Notification of impending silence

The performance notification event has a new notification type, DMUS_NOTIFICATION_MUSICALMOSTEND, which indicates that the last primary segment in the queue is about to end. This notification gives the application a chance to schedule a new segment.

Enhanced MIDI controller support

Curve messages now support RPN (registered parameter number) and NRPN (nonregistered parameter number) controller changes.

Infinite repetition of segments

The new DMUS_SEG_REPEAT_INFINITE flag allows a segment to play for an indefinite time.

Simplified downloading and unloading of bands

Bands can be downloaded and unloaded with a simple method call on the segment object.

Dynamic track data generation

New track configuration and play flags allow tracks to be recomposed each time the segment is played or looped. For example, a chordmap track can be configured to establish a new chord progression each time the segment plays.

Audio scripting

Music composers and sound designers can gain greater control over the performance by using scripts. The application does not handle the details of playback but instead calls into the script. For example, a game event might trigger a script function. The script author can easily modify the soundtrack's response to the game event by modifying the function.

Improved run-time control over tracks

Applications can set individual track configurations to disable playback and parameter control. Tracks can be configured to operate in clock time rather than music time. Tracks in self-controlling segments can be configured to override parameter tracks in controlling or primary segments.

Container object

All components of a Microsoft DirectMusic Producer project can be kept in a single file, making it easier to find and load all objects. Containers can also be embedded in segments, so that everything necessary to play a segment is kept within the segment.

Lyrics track

Time-stamped text is sent to the performance by a segment containing a lyrics track.

Improved cache management

Applications can more easily release unused objects that were loaded by other objects.



LP

W3by ::

@LionZion

Mislim da bo tole zate kar tapravo:
PlaySound() - Predvaja wav file.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo

cod 2 direct x problem

Oddelek: Igre
162608 (1588) sandi17
»

Lag pri filmčkih v špilih

Oddelek: Igre
102006 (1868) Matev
»

Program, ki zkorišča zvočo kartico.

Oddelek: Programiranje
341750 (1115) Microsoft
»

3D Mark 2000 in 2001 = VELIK PROBLEM :)

Oddelek: Pomoč in nasveti
101644 (1504) BustA

Več podobnih tem