• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            創(chuàng)建游戲內(nèi)核(21)

             

            本篇是創(chuàng)建游戲內(nèi)核(20)的續(xù)篇,有關DirectAudio和DirectShow的基礎知識請參閱用DirectX Audio和DirectShow播放聲音和音樂

            為了增強MUSIC_CHANNEL類的音樂回放特性,可以使用DLS類。

            來看看類DLS的定義:

            //======================================================================================
            // This class encapsulates for downloadable sound.
            //======================================================================================
            typedef class DLS
            {
            public:
                DLS();
                ~DLS();

                IDirectMusicCollection8* get_dm_colletion();

                BOOL create(SOUND_PTR sound);
                BOOL load(
            const char* filename = NULL);
                BOOL free();

                
            long get_num_patches();
                
            long get_patch(long index);
                BOOL exists(
            long patch);

            private:
                SOUND_PTR _sound;
                IDirectMusicCollection* _dm_collection;
            } *DLS_PTR;
             

            以及類DLS的實現(xiàn):

            //------------------------------------------------------------------------------
            // Constructor, zero member data.
            //------------------------------------------------------------------------------
            DLS::DLS()
            {
                memset(
            this, 0, sizeof(*this));
            }

            //------------------------------------------------------------------------------
            // Destructor, release DirectMusic resource.
            //------------------------------------------------------------------------------
            DLS::~DLS()
            {
                free();
            }

            //------------------------------------------------------------------------------
            // Release DirectMusic collection object.
            //------------------------------------------------------------------------------
            BOOL DLS::free()
            {
                
            if(_sound == NULL || _sound->get_dm_loader() == NULL)
                    
            return FALSE;

                
            if(_dm_collection)
                {
                    
            if(FAILED(_sound->get_dm_loader()->ReleaseObjectByUnknown(_dm_collection)))
                        
            return FALSE;
                }

                release_com(_dm_collection);

                
            return TRUE;
            }

            //------------------------------------------------------------------------------
            // Create DLS object.
            //------------------------------------------------------------------------------
            BOOL DLS::create(SOUND_PTR sound)
            {
                free();

                _sound = sound;

                
            if(_sound == NULL || _sound->get_dm_loader() == NULL)
                    
            return FALSE;

                
            return TRUE;
            }

            //------------------------------------------------------------------------------
            // Load DirectMusic collection object from specified filename.
            //------------------------------------------------------------------------------
            BOOL DLS::load(const char* filename)
            {
                free();

                
            if(_sound == NULL || _sound->get_dm_loader() == NULL)
                    
            return FALSE;

                DMUS_OBJECTDESC object_desc;

                ZeroMemory(&object_desc, 
            sizeof(DMUS_OBJECTDESC));

                object_desc.dwSize    = 
            sizeof(DMUS_OBJECTDESC);
                object_desc.guidClass = CLSID_DirectMusicCollection;

                
            if(filename == NULL)
                {
                    
            // get the default collection
                    object_desc.guidObject  = GUID_DefaultGMCollection;
                    object_desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_OBJECT;
                }
                
            else
                {
                    
            // get the colletion object
                    object_desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME | DMUS_OBJ_FULLPATH;
                    mbstowcs(object_desc.wszName, filename, MAX_PATH);
                }

                HRESULT rv = _sound->get_dm_loader()->GetObject(&object_desc, 
                                            IID_IDirectMusicCollection8, (LPVOID*)&_dm_collection);    

                
            if(rv != S_OK)
                {
                    
            if(rv == DMUS_E_LOADER_FAILEDCREATE)
                        err_msg_box("The object could not be found or created.");
                    
            else if(rv == DMUS_E_LOADER_FAILEDOPEN)
                        err_msg_box("File open failed because the file does not exist or is locked.");
                    
            else if(rv == DMUS_E_LOADER_FORMATNOTSUPPORTED)            
                        err_msg_box("The object cannot be loaded because the data format is not supported.");
                    
            else if(rv == DMUS_E_LOADER_NOCLASSID)
                        err_msg_box("No class identifier was supplied in the object description.");
                    
            else if(rv == E_FAIL)
                        err_msg_box("The method did not succeed.");
                    
            else if(rv == E_INVALIDARG)
                        err_msg_box("Invalid argument. Often, this error results from failing to initialize the dwSize member"
                                    " of a structure before passing it to the method.");
                    
            else if(rv == E_OUTOFMEMORY)
                        err_msg_box("Insufficient memory to complete the task.");
                    
            else if(rv == E_POINTER)
                        err_msg_box("An invalid pointer, usually NULL, was passed as a parameter.");
                    
            else if(rv == REGDB_E_CLASSNOTREG)
                        err_msg_box("The object class is not registered.");

                    
            return FALSE;
                }

                
            return TRUE;
            }

            //------------------------------------------------------------------------------
            // Return DirectMusic collection object.
            //------------------------------------------------------------------------------
            IDirectMusicCollection8* DLS::get_dm_colletion()
            {
                
            return _dm_collection;
            }

            //------------------------------------------------------------------------------
            // Return number of patches in DirectMusic collection.
            //------------------------------------------------------------------------------
            long DLS::get_num_patches()
            {
                DWORD patch;
                
            long  index = 0;

                
            // retrieves the patch number and name of an instrument by its index in the collection
                while(_dm_collection->EnumInstrument(index, &patch, NULL, 0))
                    ++index;

                
            return index;
            }

            //------------------------------------------------------------------------------
            // Return patch number by index of the instrument.
            //------------------------------------------------------------------------------
            long DLS::get_patch(long index)
            {
                DWORD patch;

                
            if(_dm_collection == NULL)
                    
            return -1;

                
            if(FAILED(_dm_collection->EnumInstrument(index, &patch, NULL, 0)))
                    
            return -1;

                
            return (long) patch;
            }

            //------------------------------------------------------------------------------
            // Judge whether specified patch exists.
            //------------------------------------------------------------------------------
            BOOL DLS::exists(long patch)
            {
                IDirectMusicInstrument8* dm_instrument;

                
            if(_dm_collection == NULL)
                    
            return FALSE;

                
            // retrieve an instrument by its patch number
                if(FAILED(_dm_collection->GetInstrument(patch, &dm_instrument)))
                    
            return FALSE;

                dm_instrument->Release();

                
            return TRUE;
            }

            DLS類的惟一用途是包含單個DLS集。像MUSIC_CHANNEL類一樣,也只能調(diào)用一次DLS::create函數(shù),因為DLS::free函數(shù)只能釋放一個已加載的DLS集。注意在DLS::load函數(shù)中,filename參數(shù)的缺省值為NULL,此缺省值指定了默認的DLS集。

            調(diào)用DLS::get_num_patches函數(shù)可以得到類中所包含的樂器的數(shù)目。使用DLS::get_patch函數(shù)可以遍歷每種樂器,得到它的音色(patch)數(shù)。使用DLS::exists函數(shù)可以檢查在DLS集中是否存在某種特定的音色,如果此函數(shù)返回值為TRUE,就表示存在這種音色;否則表示不存在這種音色。

            該類的實現(xiàn)可能并不完整,暫不提供測試代碼。
             

            posted on 2007-10-09 23:03 lovedday 閱讀(220) 評論(0)  編輯 收藏 引用

            公告

            導航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            亚洲人成伊人成综合网久久久| 国内精品伊人久久久久网站| 久久天天躁狠狠躁夜夜av浪潮 | 久久国产色AV免费观看| 香蕉久久夜色精品国产尤物| 久久精品亚洲精品国产欧美| 精品久久久久久久久久中文字幕| 久久这里只有精品久久| 久久精品国产99国产精偷| 久久99精品国产99久久| 99久久伊人精品综合观看| 中文字幕亚洲综合久久| 久久精品不卡| 精品久久久久久无码不卡| 亚洲色大成网站www久久九| 久久精品人人槡人妻人人玩AV | 久久久午夜精品福利内容| 久久综合久久鬼色| 免费无码国产欧美久久18| 亚洲精品国产字幕久久不卡| 久久精品9988| 怡红院日本一道日本久久| 久久99国产精品成人欧美| 亚洲国产综合久久天堂| 久久人妻少妇嫩草AV无码专区| 久久精品嫩草影院| 一本久久a久久精品综合香蕉 | 久久伊人五月天论坛| 久久人人爽人人人人爽AV| 精品免费tv久久久久久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 青青草国产精品久久| 久久久精品人妻无码专区不卡| 久久午夜福利无码1000合集| 久久99精品久久久久久| 久久久久亚洲精品日久生情 | 久久精品国产亚洲AV无码偷窥| 国产精品99久久久久久董美香| 亚洲午夜久久久影院| 久久亚洲2019中文字幕| 国产精品一久久香蕉产线看 |