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

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

?? midistrm.cpp

?? 音頻編解碼器Codec: UCB1400 WinCE6.0音頻驅動WAVEDEV2
?? CPP
字號:
//
// 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;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩欧美国产麻豆| 亚洲一区免费在线观看| 欧美日韩亚洲综合在线| 国产一区二区福利视频| 亚洲成人综合视频| 亚洲伦理在线精品| 久久精品综合网| 精品精品国产高清一毛片一天堂| www.成人网.com| 国产69精品久久久久毛片| 日韩成人免费电影| 亚洲国产一二三| 亚洲欧美精品午睡沙发| 国产欧美综合在线观看第十页| 欧美一区二区三区播放老司机| 97久久超碰国产精品电影| 成人小视频在线观看| 国产一区二区三区在线观看免费视频| 精品一区二区三区影院在线午夜 | 狠狠色综合色综合网络| 亚洲成av人片在线| 亚洲成人激情av| 亚洲第一成人在线| 免费观看在线综合| 蜜桃视频在线观看一区| 蜜臀久久99精品久久久久宅男 | 日产精品久久久久久久性色| 亚洲一区二区三区美女| 亚洲美女免费在线| 自拍视频在线观看一区二区| 亚洲麻豆国产自偷在线| 亚洲自拍与偷拍| 精品亚洲国产成人av制服丝袜| 久久99国产精品久久99果冻传媒| 狠狠色综合播放一区二区| 国产jizzjizz一区二区| 欧美一区二区三区四区视频| 精品国产区一区| 91成人在线精品| 色综合久久99| 国产精品亚洲а∨天堂免在线| 日韩理论电影院| 99re视频精品| 欧美偷拍一区二区| 精品国产乱码久久久久久久| 中文字幕乱码日本亚洲一区二区| 亚洲欧美激情在线| 麻豆视频一区二区| 91丨九色丨尤物| 精品久久久久99| 亚洲成人在线免费| 99久久伊人精品| 成人精品一区二区三区中文字幕| 国产主播一区二区三区| 欧美亚洲综合在线| 国产精品欧美久久久久一区二区| 亚洲不卡一区二区三区| 99久精品国产| 国产精品情趣视频| 国产一区免费电影| 欧美一卡二卡三卡四卡| 亚洲3atv精品一区二区三区| 成a人片国产精品| 国产日韩欧美一区二区三区乱码 | 琪琪一区二区三区| 欧美色图第一页| 亚洲免费av网站| 99麻豆久久久国产精品免费| 欧美高清在线一区二区| 国产一区二区三区四| 日韩欧美国产1| 久久99久久99| 日韩精品一区国产麻豆| 日本成人在线网站| 日韩美女视频在线| 久国产精品韩国三级视频| 亚洲精品在线一区二区| 久久99这里只有精品| 欧美一区二区三区免费在线看| 麻豆国产91在线播放| 依依成人综合视频| 91国偷自产一区二区使用方法| 亚洲色欲色欲www在线观看| 一本久久综合亚洲鲁鲁五月天| 中文字幕一区二区三区蜜月| 91麻豆国产自产在线观看| 亚洲综合久久久| 欧美一区二区高清| 成人99免费视频| 午夜视频在线观看一区二区| 欧美tickle裸体挠脚心vk| 高清国产一区二区| 天堂资源在线中文精品| 26uuu国产电影一区二区| 色综合久久精品| 国产资源精品在线观看| 午夜久久福利影院| 国产欧美日韩亚州综合| 91麻豆精品国产91久久久使用方法| 日本不卡高清视频| 亚洲欧美精品午睡沙发| 日韩一区二区在线看片| 97久久精品人人做人人爽| 免费观看一级欧美片| 亚洲精品午夜久久久| www精品美女久久久tv| 欧美日韩精品欧美日韩精品| av在线不卡网| 粉嫩一区二区三区在线看| 首页国产丝袜综合| 亚洲一区二区三区美女| 亚洲欧洲av在线| 欧美国产1区2区| 久久久久9999亚洲精品| 日韩欧美自拍偷拍| 欧美精品久久久久久久多人混战| 99r国产精品| 91蜜桃婷婷狠狠久久综合9色| 国模一区二区三区白浆| 裸体歌舞表演一区二区| 男人的天堂久久精品| 午夜精品久久久| 美女网站一区二区| 麻豆传媒一区二区三区| 精品无人区卡一卡二卡三乱码免费卡 | 色综合久久综合网97色综合| 成人午夜精品在线| 国产精品99久久久久久久女警| 奇米777欧美一区二区| 久久不见久久见中文字幕免费| 日本sm残虐另类| 寂寞少妇一区二区三区| 国产激情视频一区二区三区欧美 | 欧洲av一区二区嗯嗯嗯啊| 欧美偷拍一区二区| 日韩欧美国产午夜精品| 26uuu色噜噜精品一区二区| 国产精品丝袜91| 午夜av电影一区| 韩国视频一区二区| 色偷偷久久人人79超碰人人澡| 欧美最猛性xxxxx直播| 日韩精品在线网站| 久久久久久久久97黄色工厂| 国产精品乱人伦| 五月天激情综合| 国产69精品一区二区亚洲孕妇| 欧美日韩亚洲综合一区二区三区| 精品国产欧美一区二区| 亚洲女人的天堂| 久久电影国产免费久久电影| 91丨porny丨户外露出| 日韩免费一区二区| 亚洲夂夂婷婷色拍ww47 | 欧美伊人精品成人久久综合97| 日韩精品专区在线影院观看| 综合欧美一区二区三区| 久久成人av少妇免费| 日本乱码高清不卡字幕| 久久综合色一综合色88| 亚洲国产精品一区二区www在线| 国产在线播放一区三区四| 欧美日本在线观看| 亚洲欧美日韩国产成人精品影院| 国产一区二区三区在线观看精品| 欧美日韩国产系列| 伊人色综合久久天天人手人婷| 国产精品1区2区3区在线观看| 欧美丰满嫩嫩电影| 亚洲国产精品久久久久秋霞影院 | 亚洲精品成人a在线观看| 国产精品18久久久久久久久| 26uuu亚洲| 国产一区中文字幕| 久久久国产一区二区三区四区小说| 免费观看在线综合| 日韩精品影音先锋| 国产在线视视频有精品| 国产亚洲制服色| 国内精品久久久久影院薰衣草| 久久夜色精品一区| 国产成人综合在线| 亚洲欧洲在线观看av| 色婷婷综合久色| 视频一区欧美日韩| 欧美精品一区二| 成人三级在线视频| 亚洲国产精品久久人人爱蜜臀| 欧美日韩极品在线观看一区| 免费高清视频精品| 久久午夜电影网| caoporen国产精品视频| 一区二区在线电影| 欧美一级高清片| 成人妖精视频yjsp地址| 亚洲主播在线观看| 国产网红主播福利一区二区| 色综合久久综合网97色综合| 老司机精品视频导航| 国产精品高潮呻吟|