• <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>

            天行健 君子當自強而不息

            創建游戲內核(21)

             

            本篇是創建游戲內核(20)的續篇,有關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的實現:

            //------------------------------------------------------------------------------
            // 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類一樣,也只能調用一次DLS::create函數,因為DLS::free函數只能釋放一個已加載的DLS集。注意在DLS::load函數中,filename參數的缺省值為NULL,此缺省值指定了默認的DLS集。

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

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

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

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            亚洲国产小视频精品久久久三级| 午夜天堂av天堂久久久| 中文字幕无码免费久久| 一本色道久久综合狠狠躁篇| 日韩欧美亚洲综合久久影院d3| av国内精品久久久久影院| 久久亚洲AV成人出白浆无码国产 | 久久热这里只有精品在线观看| 久久精品国产国产精品四凭| 伊人久久大香线蕉影院95| 亚洲国产精品久久66| 99久久国产综合精品网成人影院 | 久久永久免费人妻精品下载| 久久精品无码专区免费青青| 7777久久亚洲中文字幕| 亚洲综合婷婷久久| 久久久久久亚洲精品无码| 麻豆av久久av盛宴av| 国产亚洲精品自在久久| 2021国产成人精品久久| 亚洲精品成人网久久久久久| 亚洲午夜久久久影院| 久久久久久a亚洲欧洲aⅴ| 国产视频久久| 中文字幕精品无码久久久久久3D日动漫| 尹人香蕉久久99天天拍| 久久99国产综合精品免费| 久久精品一区二区影院| 久久夜色精品国产噜噜噜亚洲AV| 国产精品99久久99久久久| 久久人人超碰精品CAOPOREN| 久久这里只有精品18| 欧美麻豆久久久久久中文| 亚洲AV无码久久精品成人| 66精品综合久久久久久久| 国产香蕉久久精品综合网| 久久精品国产精品青草app| 少妇无套内谢久久久久| 91久久国产视频| 69久久夜色精品国产69| 中文字幕无码av激情不卡久久|