亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? t3dlib3.cpp

?? 一本外國人寫的關于3D游戲編程的書的源碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// T3DLIB3.CPP - Game Engine Part III, sound & music
 
// INCLUDES ///////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <objbase.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <wchar.h>

#include <ddraw.h>  // directX includes
#include <dsound.h>
#include <dmksctrl.h>
#include <dmusici.h>
#include <dmusicc.h>
#include <dmusicf.h>


#include "T3DLIB3.H"

// DEFINES ////////////////////////////////////////////////


// TYPES //////////////////////////////////////////////////

// PROTOTYPES /////////////////////////////////////////////

// EXTERNALS /////////////////////////////////////////////

extern HWND main_window_handle;     // access to main window handle in main module

// GLOBALS ////////////////////////////////////////////////

// directsound stuff
LPDIRECTSOUND		lpds = NULL;    // directsound interface pointer
DSBUFFERDESC		dsbd;           // directsound description
DSCAPS				dscaps;         // directsound caps
HRESULT				dsresult;       // general directsound result
DSBCAPS				dsbcaps;        // directsound buffer caps
LPDIRECTSOUNDBUFFER	lpdsbprimary = NULL;   // the primary mixing buffer
pcm_sound			sound_fx[MAX_SOUNDS];    // the array of secondary sound buffers

WAVEFORMATEX		pcmwf;          // generic waveformat structure

// direct music globals
IDirectMusicPerformance    *dm_perf = NULL;    // the directmusic performance manager 
IDirectMusicLoader         *dm_loader = NULL;  // the directmusic loader

// this hold all the directmusic midi objects
DMUSIC_MIDI                dm_midi[DM_NUM_SEGMENTS];
int dm_active_id = -1;     // currently active midi segment

// FUNCTIONS //////////////////////////////////////////////

int DSound_Load_WAV(char *filename, int control_flags)
{
// this function loads a .wav file, sets up the directsound 
// buffer and loads the data into memory, the function returns 
// the id number of the sound


HMMIO 			hwav;    // handle to wave file
MMCKINFO		parent,  // parent chunk
                child;   // child chunk
WAVEFORMATEX    wfmtx;   // wave format structure

int	sound_id = -1,       // id of sound to be loaded
	index;               // looping variable

UCHAR *snd_buffer,       // temporary sound buffer to hold voc data
      *audio_ptr_1=NULL, // data ptr to first write buffer 
	  *audio_ptr_2=NULL; // data ptr to second write buffer

DWORD audio_length_1=0,  // length of first write buffer
	  audio_length_2=0;  // length of second write buffer
			
// step one: are there any open id's ?
for (index=0; index < MAX_SOUNDS; index++)
	{	
    // make sure this sound is unused
	if (sound_fx[index].state==SOUND_NULL)
	   {
	   sound_id = index;
	   break;
	   } // end if

	} // end for index

// did we get a free id?
if (sound_id==-1)
	return(-1);

// set up chunk info structure
parent.ckid 	    = (FOURCC)0;
parent.cksize 	    = 0;
parent.fccType	    = (FOURCC)0;
parent.dwDataOffset = 0;
parent.dwFlags		= 0;

// copy data
child = parent;

// open the WAV file
if ((hwav = mmioOpen(filename, NULL, MMIO_READ | MMIO_ALLOCBUF))==NULL)
    return(-1);

// descend into the RIFF 
parent.fccType = mmioFOURCC('W', 'A', 'V', 'E');

if (mmioDescend(hwav, &parent, NULL, MMIO_FINDRIFF))
    {
    // close the file
    mmioClose(hwav, 0);

    // return error, no wave section
    return(-1); 	
    } // end if

// descend to the WAVEfmt 
child.ckid = mmioFOURCC('f', 'm', 't', ' ');

if (mmioDescend(hwav, &child, &parent, 0))
    {
    // close the file
    mmioClose(hwav, 0);

    // return error, no format section
    return(-1); 	
    } // end if

// now read the wave format information from file
if (mmioRead(hwav, (char *)&wfmtx, sizeof(wfmtx)) != sizeof(wfmtx))
    {
    // close file
    mmioClose(hwav, 0);

    // return error, no wave format data
    return(-1);
    } // end if

// make sure that the data format is PCM
if (wfmtx.wFormatTag != WAVE_FORMAT_PCM)
    {
    // close the file
    mmioClose(hwav, 0);

    // return error, not the right data format
    return(-1); 
    } // end if

// now ascend up one level, so we can access data chunk
if (mmioAscend(hwav, &child, 0))
   {
   // close file
   mmioClose(hwav, 0);

   // return error, couldn't ascend
   return(-1); 	
   } // end if

// descend to the data chunk 
child.ckid = mmioFOURCC('d', 'a', 't', 'a');

if (mmioDescend(hwav, &child, &parent, MMIO_FINDCHUNK))
    {
    // close file
    mmioClose(hwav, 0);

    // return error, no data
    return(-1); 	
    } // end if

// finally!!!! now all we have to do is read the data in and
// set up the directsound buffer

// allocate the memory to load sound data
snd_buffer = (UCHAR *)malloc(child.cksize);

// read the wave data 
mmioRead(hwav, (char *)snd_buffer, child.cksize);

// close the file
mmioClose(hwav, 0);

// set rate and size in data structure
sound_fx[sound_id].rate  = wfmtx.nSamplesPerSec;
sound_fx[sound_id].size  = child.cksize;
sound_fx[sound_id].state = SOUND_LOADED;

// set up the format data structure
memset(&pcmwf, 0, sizeof(WAVEFORMATEX));

pcmwf.wFormatTag	  = WAVE_FORMAT_PCM;  // pulse code modulation
pcmwf.nChannels		  = 1;                // mono 
pcmwf.nSamplesPerSec  = 11025;            // always this rate
pcmwf.nBlockAlign	  = 1;                
pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
pcmwf.wBitsPerSample  = 8;
pcmwf.cbSize		  = 0;

// prepare to create sounds buffer
dsbd.dwSize			= sizeof(DSBUFFERDESC);
dsbd.dwFlags		= control_flags | DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE;
dsbd.dwBufferBytes	= child.cksize;
dsbd.lpwfxFormat	= &pcmwf;

// create the sound buffer
if (FAILED(lpds->CreateSoundBuffer(&dsbd,&sound_fx[sound_id].dsbuffer,NULL)))
   {
   // release memory
   free(snd_buffer);

   // return error
   return(-1);
   } // end if

// copy data into sound buffer
if (FAILED(sound_fx[sound_id].dsbuffer->Lock(0,					 
								      child.cksize,			
								      (void **) &audio_ptr_1, 
								      &audio_length_1,
								      (void **)&audio_ptr_2, 
								      &audio_length_2,
								      DSBLOCK_FROMWRITECURSOR)))
								 return(0);

// copy first section of circular buffer
memcpy(audio_ptr_1, snd_buffer, audio_length_1);

// copy last section of circular buffer
memcpy(audio_ptr_2, (snd_buffer+audio_length_1),audio_length_2);

// unlock the buffer
if (FAILED(sound_fx[sound_id].dsbuffer->Unlock(audio_ptr_1, 
									    audio_length_1, 
									    audio_ptr_2, 
									    audio_length_2)))
 							     return(0);

// release the temp buffer
free(snd_buffer);

// return id
return(sound_id);

} // end DSound_Load_WAV

///////////////////////////////////////////////////////////

int DSound_Replicate_Sound(int source_id)
{
// this function replicates the sent sound and sends back the
// id of the replicated sound, you would use this function
// to make multiple copies of a gunshot or something that
// you want to play multiple times simulataneously, but you
// only want to load once

if (source_id!=-1)
    {
    // duplicate the sound buffer
    // first hunt for an open id

    for (int id=0; id < MAX_SOUNDS; id++)
        {
        // is this sound open?
        if (sound_fx[id].state==SOUND_NULL)
            {
            // first make an identical copy
            sound_fx[id] = sound_fx[source_id];

            // now actually replicate the directsound buffer
            if (FAILED(lpds->DuplicateSoundBuffer(sound_fx[source_id].dsbuffer,
                                           &sound_fx[id].dsbuffer)))
                {
                // reset sound to NULL
                sound_fx[id].dsbuffer = NULL;
                sound_fx[id].state    = SOUND_NULL;

                // return error
                return(-1);
                } // end if

            // now fix up id
            sound_fx[id].id = id;
            
            // return replicated sound
            return(id);

            } // end if found
  
        } // end for id

    } // end if
else
   return(-1);
    
// else failure
return(-1);

} // end DSound_Replicate_Sound

//////////////////////////////////////////////////////////

int DSound_Init(void)
{
// this function initializes the sound system
static int first_time = 1; // used to track the first time the function
                           // is entered

// test for very first time
if (first_time)
	{		
	// clear everything out
	memset(sound_fx,0,sizeof(pcm_sound)*MAX_SOUNDS);
	
	// reset first time
	first_time = 0;

	// create a directsound object
	if (FAILED(DirectSoundCreate(NULL, &lpds, NULL)))
		return(0);

	// set cooperation level
	if (FAILED(lpds->SetCooperativeLevel((HWND)main_window_handle,DSSCL_NORMAL)))
		return(0);

	} // end if

// initialize the sound fx array
for (int index=0; index<MAX_SOUNDS; index++)
	{
	// test if this sound has been loaded
	if (sound_fx[index].dsbuffer)
		{
		// stop the sound
		sound_fx[index].dsbuffer->Stop();

		// release the buffer
		sound_fx[index].dsbuffer->Release();
	
		} // end if

	// clear the record out
	memset(&sound_fx[index],0,sizeof(pcm_sound));

	// now set up the fields
	sound_fx[index].state = SOUND_NULL;
	sound_fx[index].id    = index;

	} // end for index

// return sucess
return(1);

} // end DSound_Init

///////////////////////////////////////////////////////////

int DSound_Shutdown(void)
{
// this function releases all the memory allocated and the directsound object
// itself

// first turn all sounds off
DSound_Stop_All_Sounds();

// now release all sound buffers
for (int index=0; index<MAX_SOUNDS; index++)
	if (sound_fx[index].dsbuffer)
		sound_fx[index].dsbuffer->Release();

// now release the directsound interface itself
if (lpds)
   lpds->Release();

// return success
return(1);

} // end DSound_Shutdown

///////////////////////////////////////////////////////////

int DSound_Play(int id, int flags, int volume, int rate, int pan)
{
// this function plays a sound, the only parameter that 
// works is the flags which can be 0 to play once or
// DSBPLAY_LOOPING

if (sound_fx[id].dsbuffer)
	{
	// reset position to start
	if (FAILED(sound_fx[id].dsbuffer->SetCurrentPosition(0)))
		return(0);
	
	// play sound
	if (FAILED(sound_fx[id].dsbuffer->Play(0,0,flags)))
		return(0);
	} // end if

// return success
return(1);

} // end DSound_Play

///////////////////////////////////////////////////////////

int DSound_Set_Volume(int id,int vol)
{
// this function sets the volume on a sound 0-100

if (sound_fx[id].dsbuffer->SetVolume(DSVOLUME_TO_DB(vol))!=DS_OK)
	return(0);

// return success
return(1);

} // end DSound_Set_Volume

///////////////////////////////////////////////////////////

int DSound_Set_Freq(int id,int freq)
{
// this function sets the playback rate

if (sound_fx[id].dsbuffer->SetFrequency(freq)!=DS_OK)
	return(0);

// return success
return(1);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人精品www牛牛影视| 欧美系列日韩一区| 欧美私模裸体表演在线观看| 91精品国产色综合久久不卡电影 | 国产成人综合在线| 5月丁香婷婷综合| 亚洲欧美日韩国产手机在线| 精彩视频一区二区三区| 欧美日韩一区二区三区在线 | 色婷婷久久一区二区三区麻豆| 欧美一区二区三区视频| 亚洲欧美国产77777| 国产精品 欧美精品| 666欧美在线视频| 一区二区三区精密机械公司| 成人性生交大片免费看中文网站| 欧美高清视频在线高清观看mv色露露十八 | 亚洲一区中文日韩| 成人毛片在线观看| 国产精品天美传媒沈樵| 精品亚洲aⅴ乱码一区二区三区| 欧美天堂一区二区三区| 亚洲日本一区二区| 99精品欧美一区| 最近日韩中文字幕| 色综合色综合色综合| 国产精品少妇自拍| 成人影视亚洲图片在线| 国产清纯白嫩初高生在线观看91| 国产乱人伦偷精品视频不卡| 日韩免费视频一区二区| 蜜臀精品一区二区三区在线观看| 欧美日韩成人在线一区| 天堂va蜜桃一区二区三区漫画版 | 亚洲主播在线播放| 色菇凉天天综合网| 亚洲一区二区三区精品在线| 99精品欧美一区二区三区小说| 亚洲欧洲日韩一区二区三区| 成人动漫一区二区在线| 亚洲天堂福利av| 欧美午夜电影网| 亚洲福中文字幕伊人影院| 欧美日韩中文一区| 午夜欧美2019年伦理| 8v天堂国产在线一区二区| 首页国产丝袜综合| 26uuu精品一区二区三区四区在线| 麻豆成人久久精品二区三区红| 亚洲精品在线观看视频| 成人一区二区三区在线观看| 中文字幕一区二区不卡| 欧美日韩dvd在线观看| 蜜桃久久av一区| 国产欧美一区视频| 91无套直看片红桃| 午夜视频在线观看一区二区 | 色婷婷久久一区二区三区麻豆| 国产精品免费网站在线观看| 91啪亚洲精品| 天天色 色综合| 26uuu另类欧美| 91女人视频在线观看| 日韩有码一区二区三区| 久久女同精品一区二区| 91丝袜呻吟高潮美腿白嫩在线观看| 亚洲视频一二区| 日韩欧美你懂的| 99久久精品99国产精品| 视频一区国产视频| 中文字幕免费不卡| 欧美日韩精品电影| 成人av手机在线观看| 午夜av一区二区三区| 久久九九国产精品| 欧美视频在线一区二区三区| 国产在线看一区| 亚洲影院理伦片| 欧美高清在线精品一区| 欧美精品丝袜中出| 成人97人人超碰人人99| 另类专区欧美蜜桃臀第一页| 亚洲激情图片小说视频| 久久久久久久久免费| 精品视频1区2区3区| 成人av影院在线| 国产精品一区二区91| 免费成人你懂的| 亚洲国产裸拍裸体视频在线观看乱了 | 欧美系列日韩一区| 成人性生交大片免费看在线播放| 亚洲国产日韩精品| 亚洲人成精品久久久久| 久久久国际精品| 欧美精品免费视频| 91久久一区二区| 99久久久久久| 国产成人av电影在线| 久久www免费人成看片高清| 日日夜夜免费精品视频| 一区二区三区免费网站| 国产精品国产三级国产有无不卡| 欧美大片国产精品| 日韩一区二区三区视频在线 | 1024亚洲合集| 国产日韩av一区| 国产三级欧美三级| 久久精品免视看| 久久久久国产精品麻豆ai换脸| 欧美一卡在线观看| 制服丝袜在线91| 91精品国产欧美一区二区| 精品视频在线免费看| 欧美日韩亚洲综合一区二区三区| 一本大道久久a久久综合 | 成人午夜在线免费| 国产伦精品一区二区三区免费| 美女网站色91| 久久er精品视频| 国产盗摄视频一区二区三区| 国产成人8x视频一区二区| 丁香婷婷综合激情五月色| av中文字幕在线不卡| 日本高清不卡在线观看| 欧美日韩在线不卡| 91精品国产综合久久久久久久| 91麻豆精品国产91久久久使用方法| 欧美精品在线观看播放| 日韩欧美国产三级| 久久久精品影视| 国产精品国产自产拍高清av王其| 亚洲欧美日韩国产一区二区三区| 一区二区三区产品免费精品久久75| 一个色综合av| 免费久久精品视频| 丁香啪啪综合成人亚洲小说| 91免费在线看| 日韩欧美国产午夜精品| 国产欧美一区二区在线观看| 亚洲欧美国产77777| 日韩电影免费在线| 国产精品1区2区3区| 91一区二区在线| 7777精品久久久大香线蕉 | 亚洲一区在线电影| 免费人成在线不卡| 成人美女视频在线观看18| 欧美日韩一区三区| 久久久久97国产精华液好用吗| 亚洲欧美另类久久久精品| 视频一区在线视频| www.色综合.com| 欧美一卡在线观看| 亚洲欧美综合另类在线卡通| 午夜精品影院在线观看| 国产精品资源在线| 欧美色综合久久| 国产精品久久久久久久裸模| 亚洲不卡av一区二区三区| 精品一二三四区| 欧美在线不卡一区| 久久久美女毛片| 亚洲成年人影院| 91尤物视频在线观看| 欧美tickling挠脚心丨vk| 亚洲国产日韩精品| 不卡的看片网站| 久久婷婷一区二区三区| 亚洲香蕉伊在人在线观| 成人av网站大全| 久久色在线视频| 美腿丝袜在线亚洲一区 | 成人永久免费视频| 日韩欧美另类在线| 亚洲成人综合视频| 91无套直看片红桃| 日本一区二区三区视频视频| 亚洲大片一区二区三区| 91丨porny丨国产| 国产午夜精品理论片a级大结局| 亚洲成av人影院在线观看网| 成人av午夜影院| 日本一区二区视频在线| 韩国欧美一区二区| 3d成人h动漫网站入口| 亚洲国产成人av| 色女孩综合影院| 亚洲人xxxx| 99精品久久只有精品| 国产精品国产三级国产普通话99 | 丰满少妇在线播放bd日韩电影| 日韩欧美中文字幕精品| 午夜精品福利在线| 在线免费观看视频一区| 中文字幕亚洲成人| 91丨九色丨黑人外教| 国产精品麻豆欧美日韩ww| 激情综合网av| 久久久三级国产网站| 国产成人激情av|