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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? midistrm.cpp

?? realtek562x系列驅(qū)動(dòng)源碼。wince
?? CPP
字號(hào):
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/* 
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.  
** Title to the Material remains with Intel Corporation or its suppliers and licensors. 
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.  
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise 
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/

#include "wavemain.h"

void CMidiStream::GainChange()
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get a pointer to the stream context
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);
        pCNote->GainChange();
        pListEntry = pListEntry->Flink;
    }
}

DWORD CMidiStream::MapNoteGain(DWORD NoteGain)
{
    DWORD TotalGain = NoteGain & 0xFFFF;
    DWORD StreamGain = m_dwGain & 0xFFFF;

    TotalGain *= StreamGain; // Calc. aggregate gain
    TotalGain += 0xFFFF;   // Force to round up
    TotalGain >>= 16;

    return MapGain(TotalGain);
}

HRESULT CMidiStream::Open(DeviceContext *pDeviceContext, LPWAVEOPENDESC lpWOD, DWORD dwFlags)
{
    HRESULT Result;
    LPWAVEFORMAT_MIDI pwfxmidi = (LPWAVEFORMAT_MIDI) lpWOD->lpFormat;

    if (pwfxmidi->wfx.cbSize!=WAVEFORMAT_MIDI_EXTRASIZE)
    {
        return E_FAIL;
    }

    m_USecPerQuarterNote  = pwfxmidi->USecPerQuarterNote;
    m_TicksPerQuarterNote = pwfxmidi->TicksPerQuarterNote;

    UpdateTempo();

    m_DeltaSampleCount=0;

    // Add all notes to free list
    InitializeListHead(&m_NoteList);
    InitializeListHead(&m_FreeList);
    for (int i=0;i<NUMNOTES;i++)
    {
        InsertTailList(&m_FreeList,&m_MidiNote[i].m_Link);
    }

    Result = StreamContext::Open(pDeviceContext, lpWOD, dwFlags);

    if (Result==MMSYSERR_NOERROR)
    {
        // Note: Output streams should be initialized in the run state.
        Run();
    }

    return Result;
}

DWORD CMidiStream::Reset()
{
    DWORD dwResult = StreamContext::Reset();
    if (dwResult==MMSYSERR_NOERROR)
    {
        AllNotesOff(0);

        // Note: Output streams should be reset to the run state.
        Run();
    }
    return dwResult;
}

DWORD CMidiStream::Close()
{
    DWORD dwResult = StreamContext::Close();
    if (dwResult==MMSYSERR_NOERROR)
    {
        AllNotesOff(0);
    }
    return dwResult;
}

HRESULT CMidiStream::UpdateTempo()
{
    if (m_USecPerQuarterNote==0)
    {
        m_USecPerQuarterNote = 500000; // If not specified, assume 500000usec = 1/2 sec per quarter note
    }

    if (m_TicksPerQuarterNote==0)
    {
        m_TicksPerQuarterNote = 96;      // If not specified, assume 96 ticks/quarter note
    }

    UINT64 Num = SAMPLERATE;
    Num *= m_USecPerQuarterNote;
    UINT64 Den = 1000000;
    Den *= m_TicksPerQuarterNote;
    UINT64 SamplesPerTick = Num/Den;
    m_SamplesPerTick = (UINT32)SamplesPerTick;
    return S_OK;
}

// Return the delta # of samples until the next midi event
// or 0 if no midi events are left in the queue
UINT32 CMidiStream::ProcessMidiStream()
{
    WAVEFORMAT_MIDI_MESSAGE *pMsg;
    WAVEFORMAT_MIDI_MESSAGE *pMsgEnd;
    UINT32 ThisMidiEventDelta;

    // Process all midi messages up to and including the current sample
    pMsg    = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrData;
    pMsgEnd = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrDataEnd;

    for (;;)
    {
        if (pMsg>=pMsgEnd)
        {
            pMsg = (WAVEFORMAT_MIDI_MESSAGE *)GetNextBuffer();
            if (!pMsg)
            {
                // DEBUGMSG(1, (TEXT("CMidiStream::ProcessMidiStream no more events\r\n")));
                return 0;
            }
            pMsgEnd = (WAVEFORMAT_MIDI_MESSAGE *)m_lpCurrDataEnd;
        }

        ThisMidiEventDelta = DeltaTicksToSamples(pMsg->DeltaTicks);
        if (ThisMidiEventDelta > m_DeltaSampleCount)
        {
            m_lpCurrData = (PBYTE)pMsg;
            INT32 Delta = ThisMidiEventDelta-m_DeltaSampleCount;
            // DEBUGMSG(1, (TEXT("CMidiStream::ProcessMidiStream next event @delta %d\r\n"),Delta));
            return Delta;
        }

        // DEBUGMSG(1, (TEXT("CMidiStream::ProcessMidiStream sending midi message 0x%x\r\n"),pMsg->MidiMsg));
        InternalMidiMessage(pMsg->MidiMsg);
        m_DeltaSampleCount=0;
        pMsg++;
    }
}

PBYTE CMidiStream::Render(PBYTE pBuffer, PBYTE pBufferEnd, PBYTE pBufferLast)
{

    // DEBUGMSG(1, (TEXT("Entering CMidiStream::Render, pBuffer=0x%x, current delta = %d\r\n"), pBuffer, m_DeltaSampleCount));

    // If we're not running, or we don't have any buffers queued and the note list is empty,
    // just return
    if ( (!m_bRunning) || (!StillPlaying() && IsListEmpty(&m_NoteList)) )
    {
        // DEBUGMSG(1, (TEXT("CMidiStream::Render nothing to do\r\n")));
        return pBuffer;
    }

    while (pBuffer<pBufferEnd)
    {
        // Process pending midi messages and get relative sample # of next midi event
        UINT32 NextMidiEvent;
        NextMidiEvent = ProcessMidiStream();

        PBYTE pBufferEndEvent;  // Where to stop on this pass

        // If NextMidiEvent returns 0, it means there are no more midi messages left in the queue.
        if (NextMidiEvent==0)
        {
            // Just process the rest of this buffer
            pBufferEndEvent=pBufferEnd;
        }
        // NextMidiEvent is non-zero, and represents the delta sample value of the next midi event
        else
        {
            // Convert to be a pointer in this buffer
            pBufferEndEvent = pBuffer + (NextMidiEvent * (sizeof(HWSAMPLE) * OUTCHANNELS));

            // If the next event occurs after this buffer, just finish processing this buffer
            if (pBufferEndEvent>pBufferEnd)
            {
                pBufferEndEvent=pBufferEnd;
            }
        }

        // Update the delta for the samples we're about to process
        m_DeltaSampleCount += ((pBufferEndEvent-pBuffer)/(sizeof(HWSAMPLE) * OUTCHANNELS));

        // Process existing notes
        PLIST_ENTRY pListEntry;
        pListEntry = m_NoteList.Flink;
        while (pListEntry != &m_NoteList)
        {
            CMidiNote *pCNote;

            // Get a pointer to the stream context
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

            // Get next list entry, since Render may cause note to go away
            pListEntry = pListEntry->Flink;

            PBYTE pBufferLastThis;
            pBufferLastThis = pCNote->Render(pBuffer, pBufferEndEvent, pBufferLast);
            if (pBufferLast < pBufferLastThis)
            {
                pBufferLast = pBufferLastThis;
            }
        }

        pBuffer = pBufferEndEvent;
    }

    // We need to make sure we clear any unwritten section of the buffer to make sure the DMA controller doesn't stop
    StreamContext::ClearBuffer(pBufferLast,pBufferEnd);
    pBufferLast=pBufferEnd;

    // DEBUGMSG(1, (TEXT("CMidiStream::Render returning, pBufferLast=0x%x, pBufferEnd=0x%x\r\n"),pBufferLast,pBufferEnd));
    return pBufferLast;
}

DWORD CMidiStream::MidiMessage(UINT32 dwMessage)
{
    HRESULT Result;

    Result = InternalMidiMessage(dwMessage);

    // If we're running, and the notelist has notes to render, make sure DMA is enabled
    if ( (m_bRunning) && (m_NoteList.Flink != &m_NoteList) )
    {
        m_pDeviceContext->StreamReadyToRender(this);
    }

    return (Result==S_OK) ? MMSYSERR_NOERROR : MMSYSERR_ERROR;
}

// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::InternalMidiMessage(UINT32 dwData)
{
    UINT32 OpCode = dwData & 0xF0000000;
    switch (OpCode)
    {
    case 0:
        return MidiData(dwData);
    case MIDI_MESSAGE_UPDATETEMPO:
        m_USecPerQuarterNote  = (dwData & 0xFFFFFF);
        return UpdateTempo();
    case MIDI_MESSAGE_FREQGENON:
    case MIDI_MESSAGE_FREQGENOFF:
        {
            UINT32 dwNote = ((dwData) & 0xffff);
            UINT32 dwVelocity = ((dwData >> 16) & 0x7f) ;
            if ((OpCode==MIDI_MESSAGE_FREQGENON)  && (dwVelocity>0))
            {
                return NoteOn(dwNote, dwVelocity, FREQCHANNEL);
            }
            else
            {
                return NoteOff(dwNote, dwVelocity, FREQCHANNEL);
            }
        }
    }
    return E_NOTIMPL;
}

HRESULT CMidiStream::MidiData(UINT32 dwData)
{
    HRESULT Result=E_NOTIMPL;
    UINT32 dwChannel;
    UINT32 dwNote;
    UINT32 dwVelocity;

    if (dwData & 0x80)
    {
        m_RunningStatus = dwData&0xFF;      // status byte...
    }
    else
    {
        dwData = (dwData<<8) | m_RunningStatus;
    }

    dwChannel  = (dwData & 0x0f) ;
    dwNote     = ((dwData >> 8) & 0x7f) ;
    dwVelocity = ((dwData >> 16) & 0x7f) ;

    switch (dwData & 0xf0)
    {
    case 0x90:  // Note on
        if (dwVelocity!=0)
        {
            Result = NoteOn(dwNote, dwVelocity, dwChannel);
            break;
        }
        // If dwVelocity is 0, this is really a note off message, so fall through

    case 0x80:  // Note off
        Result = NoteOff(dwNote, dwVelocity, dwChannel);
        break;

    case 0xB0:  // Control change
        {
            switch (dwNote)
            {
            case 123:   // turns all notes off
                {
                    Result = AllNotesOff(0);
                    break;
                }
            }
            break;
        }
    }

    return Result;
}

CMidiNote *CMidiStream::FindNote(UINT32 dwNote, UINT32 dwChannel)
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get a pointer to the stream context
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

        if (pCNote->NoteVal()==dwNote && pCNote->NoteChannel()==dwChannel)
        {
            return pCNote;
        }

        pListEntry = pListEntry->Flink;
    }
    return NULL;
}

// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::NoteOn(UINT32 dwNote, UINT32 dwVelocity, UINT32 dwChannel)
{
    CMidiNote *pCNote=NULL;

    PLIST_ENTRY pListEntry;

    // First try to find the same note already being played
    pCNote = FindNote(dwNote, dwChannel);
    if (pCNote)
    {
        // If so, just set its velocity to the new velocity
        // This allows us to change volume while a note is being
        // played without any chance of glitching
        pCNote->SetVelocity(dwVelocity);
    }
    else
    {
        // Try to allocate a note from the free list
        pListEntry = m_FreeList.Flink;
        if (pListEntry != &m_FreeList)
        {
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

            // If we got a note from the free list, do an AddRef on this stream context
            AddRef();
        }
        else
        {
            // Note: if we every support multiple instruments, here we should try to steal the oldest
            // note with the same channel before just trying to steal the oldest note.

            // Steal the oldest note (which is the note at the head of the note list)
            // Note: This should _never_ fail, since there must be a note on one of the lists!
            pListEntry = m_NoteList.Flink;
            pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);
        }

        pCNote->NoteOn(this,dwNote,dwVelocity,dwChannel);
    }

    // Move the note from whichever list it was on to the note list at the end.
    // This ensures that if we reused an existing note, its age gets reset.
    NoteMoveToNoteList(pCNote);

    return S_OK;
}

// Assumes lock is taken, and we're already positioned at the correct point in the stream
HRESULT CMidiStream::NoteOff(UINT32 dwNote, UINT32 dwVelocity, UINT32 dwChannel)
{
    CMidiNote *pCNote = FindNote(dwNote, dwChannel);
    if (pCNote)
    {
        pCNote->NoteOff(dwVelocity);
    }

    return S_OK;
}

HRESULT CMidiStream::AllNotesOff(UINT32 dwVelocity)
{
    PLIST_ENTRY pListEntry;
    CMidiNote *pCNote;
    pListEntry = m_NoteList.Flink;
    while (pListEntry != &m_NoteList)
    {
        // Get the note
        pCNote = CONTAINING_RECORD(pListEntry,CMidiNote,m_Link);

        // Get the next link, since NoteOff may remove the note from the queue depeding on the implementation
        pListEntry = pListEntry->Flink;

        // Turn the note off
        pCNote->NoteOff(dwVelocity);
    }
    return S_OK;
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美一区二区免费| 精品久久久久一区| 午夜视频在线观看一区二区三区| 欧美亚洲综合另类| 久久97超碰色| 中文字幕一区二区三区精华液| 91麻豆国产在线观看| 亚洲成人av中文| 久久久久久久久久久黄色| 成人免费av在线| 日本视频一区二区三区| 国产人伦精品一区二区| 欧洲中文字幕精品| 黄色日韩网站视频| 一区二区三区不卡视频| 精品国产欧美一区二区| 99精品欧美一区二区三区综合在线| 一区二区三区免费看视频| 日韩一级完整毛片| 91美女蜜桃在线| 国产一区二区三区免费| 亚洲电影激情视频网站| 国产精品色哟哟| 91精品国产综合久久小美女| 高清在线不卡av| 欧美aaaaa成人免费观看视频| 中文字幕亚洲欧美在线不卡| 日韩欧美国产综合| 91福利视频网站| 国产福利一区二区三区视频在线 | 色综合 综合色| 国产精品香蕉一区二区三区| 日韩av中文字幕一区二区| 国产精品久久久99| 国产精品欧美一级免费| 欧美一区二区视频在线观看2022 | 亚洲成人动漫精品| 亚洲精品视频在线看| 欧美国产日产图区| 久久色成人在线| 日韩欧美国产三级电影视频| 欧美在线免费观看亚洲| 色综合色综合色综合色综合色综合 | 久久伊人蜜桃av一区二区| 欧美揉bbbbb揉bbbbb| 国产麻豆精品在线| 国产福利一区二区三区视频在线| 亚洲大片免费看| 亚洲国产一区二区视频| 亚洲国产日韩在线一区模特| 亚洲一区二区在线观看视频| 国产精品国产精品国产专区不蜜| 精品国产麻豆免费人成网站| 欧美本精品男人aⅴ天堂| 7777精品伊人久久久大香线蕉的 | 精品国产制服丝袜高跟| 2021久久国产精品不只是精品| 久久久蜜桃精品| 国产精品午夜在线| 亚洲欧美日韩国产另类专区| 一区二区三区精品在线观看| 亚洲第一成人在线| 精一区二区三区| 国产精品一区二区在线观看不卡 | 午夜精品aaa| 激情综合网av| 91麻豆精东视频| 6080午夜不卡| 国产精品久久久久久久久快鸭| 亚洲免费观看高清完整版在线观看| 亚洲高清免费在线| 国产综合久久久久影院| 色94色欧美sute亚洲13| 欧美电视剧在线观看完整版| 国产精品萝li| 久久精品国产久精国产| 97精品久久久午夜一区二区三区 | 久久影院午夜片一区| 亚洲日本护士毛茸茸| 久久成人免费电影| 在线视频国产一区| 欧美xxxx在线观看| 亚洲一区二区影院| 国产精品1区二区.| 51精品国自产在线| 亚洲欧美自拍偷拍| 国产精品亚洲第一| 91精品国产aⅴ一区二区| 国产欧美一区二区精品婷婷| 天堂va蜜桃一区二区三区漫画版 | 日韩激情在线观看| 92精品国产成人观看免费 | 欧美三区在线观看| 中文字幕一区二区三区不卡| 国产在线精品一区二区| 欧美精选午夜久久久乱码6080| 奇米在线7777在线精品| 欧美色倩网站大全免费| 久久亚洲综合色一区二区三区 | 爽好久久久欧美精品| 免费av网站大全久久| 国产成人自拍高清视频在线免费播放| 成人丝袜高跟foot| 爽好多水快深点欧美视频| 美女视频网站黄色亚洲| 欧美日高清视频| 亚洲主播在线观看| 色狠狠色噜噜噜综合网| 亚洲欧美日韩中文字幕一区二区三区| 国产乱一区二区| 久久久久国产免费免费| 国产剧情av麻豆香蕉精品| 欧美三级电影网| 国产亚洲成年网址在线观看| 国内精品伊人久久久久av一坑| 91精品婷婷国产综合久久竹菊| 午夜精品一区在线观看| 欧美精品久久久久久久久老牛影院| 一区二区三区不卡在线观看 | 最新国产精品久久精品| 99re视频精品| 亚洲电影第三页| 日韩欧美中文字幕公布| 国内精品久久久久影院薰衣草| 久久久五月婷婷| 91免费视频观看| 爽好久久久欧美精品| 久久久久久久国产精品影院| 国产成人av一区二区三区在线观看| 国产精品视频你懂的| 91玉足脚交白嫩脚丫在线播放| 亚洲成在人线免费| 日韩一区二区精品在线观看| 国产99精品国产| 亚洲综合一二三区| 久久丝袜美腿综合| 欧美日韩综合在线| 国产a视频精品免费观看| 亚洲一区二区精品视频| 欧美成人乱码一区二区三区| 成人h动漫精品| 蜜臀av性久久久久av蜜臀妖精| 国产精品视频线看| 在线不卡一区二区| 风间由美一区二区av101 | 精品国产成人系列| 欧美性极品少妇| 国产精品一区二区久激情瑜伽| 亚洲自拍偷拍图区| 国产视频视频一区| 日韩欧美久久久| 欧美日韩免费不卡视频一区二区三区| 成人国产精品免费网站| 激情综合色综合久久| 首页国产欧美久久| 一区二区三区在线观看网站| 欧美—级在线免费片| 精品国精品国产尤物美女| 91麻豆精品国产91久久久使用方法 | 日韩一区欧美小说| 国产日韩在线不卡| 日韩欧美另类在线| 欧美一级黄色大片| 欧美日韩一区二区三区高清| 91精品福利在线| 色噜噜狠狠成人中文综合| 福利电影一区二区三区| 国产福利电影一区二区三区| 黄色小说综合网站| 国产在线国偷精品产拍免费yy| 裸体健美xxxx欧美裸体表演| 蜜桃视频一区二区三区在线观看| 日韩av中文字幕一区二区三区 | 久久精品视频一区二区三区| 精品国产欧美一区二区| 久久久国际精品| 国产精品系列在线| 亚洲欧美日韩久久| 亚洲福利电影网| 麻豆免费精品视频| 国产精品一二三四| 欧美在线播放高清精品| 在线免费观看日本一区| 91精品国产综合久久蜜臀| 欧美v国产在线一区二区三区| 久久综合九色综合97_久久久| 国产精品乱人伦| 午夜婷婷国产麻豆精品| 久久99在线观看| 粉嫩av一区二区三区在线播放 | 91蜜桃传媒精品久久久一区二区 | 日本中文字幕一区二区视频| 久久99久久精品| 一本色道亚洲精品aⅴ| 欧美日韩国产成人在线免费| 久久精品人人做人人爽97 | 91精品国产综合久久久久久| 精品国产乱码久久久久久免费 | 日韩精品一区第一页| 国产a视频精品免费观看|