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

            天行健 君子當(dāng)自強(qiáng)而不息

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

             

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

            為了增強(qiáng)MUSIC_CHANNEL類的音樂(lè)回放特性,可以使用DLS類。

            來(lái)看看類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的實(shí)現(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類的惟一用途是包含單個(gè)DLS集。像MUSIC_CHANNEL類一樣,也只能調(diào)用一次DLS::create函數(shù),因?yàn)镈LS::free函數(shù)只能釋放一個(gè)已加載的DLS集。注意在DLS::load函數(shù)中,filename參數(shù)的缺省值為NULL,此缺省值指定了默認(rèn)的DLS集。

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

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

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


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            嫩草影院久久国产精品| 亚洲精品tv久久久久| 99国产精品久久| 久久亚洲天堂| 久久超碰97人人做人人爱| 成人午夜精品久久久久久久小说 | 色诱久久久久综合网ywww| 国产精品一区二区久久 | 久久久久人妻精品一区二区三区| 91精品国产综合久久精品| 色综合久久久久综合99| 久久91精品久久91综合| 亚洲香蕉网久久综合影视| 狠狠人妻久久久久久综合蜜桃| 亚洲级αV无码毛片久久精品| 99久久精品国产综合一区| 久久国产色AV免费观看| 一级做a爰片久久毛片看看| 亚洲一区中文字幕久久| 久久精品国产亚洲AV高清热| 久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 | 久久国产精品-国产精品| 日韩精品久久久久久免费| 久久久久亚洲AV无码去区首| 精品久久久噜噜噜久久久| 午夜不卡久久精品无码免费 | 国产午夜精品久久久久免费视| 久久久久se色偷偷亚洲精品av| 久久嫩草影院免费看夜色| 久久99精品国产麻豆婷婷| 国产精品久久久99| 国产女人aaa级久久久级| 久久精品国产亚洲av瑜伽| 91秦先生久久久久久久| 国产综合成人久久大片91| 国产999精品久久久久久| 国产69精品久久久久9999| 国产成人精品综合久久久| 久久国产热这里只有精品| 久久久精品视频免费观看| 久久精品国产99国产精品|