main streaming callback this is the main state-machine; check comments in function for details */
| 932 | this is the main state-machine; check comments in function for details |
| 933 | */ |
| 934 | signed char CMusicSystem::StreamingCallback(CS_STREAM *pStream, void *pBuffer, int nLength) |
| 935 | { |
| 936 | CSmartCriticalSection SmartCriticalSection(m_CS); |
| 937 | if (m_pStream!=pStream) |
| 938 | { |
| 939 | // wrong stream; this should never happen |
| 940 | CryError( "<CrySound> (CMusicSystem::StreamingCallback) Wrong Stream" ); |
| 941 | return FALSE; |
| 942 | } |
| 943 | // Ignore if not playing. |
| 944 | if (!m_bPlaying) |
| 945 | return TRUE; |
| 946 | if (!m_musicEnable) |
| 947 | return TRUE; |
| 948 | |
| 949 | signed short *pOutput=(signed short*)pBuffer; |
| 950 | int nOfs=0; |
| 951 | int nSamples=nLength/m_nBytesPerSample; |
| 952 | // check if theme and mood are valid |
| 953 | if ((!m_pCurrTheme) || (!m_pCurrMood) || (!UpdateCurrentPatternSet(m_pCurrMood, nSamples, false))) |
| 954 | { |
| 955 | // no theme or mood set |
| 956 | if (m_pCurrPattern) |
| 957 | { |
| 958 | SMusicPatternPlayInfo PlayInfo; |
| 959 | PlayInfo.nLayer=MUSICLAYER_MAIN; |
| 960 | PlayInfo.pPatternInstance=m_pCurrPattern; |
| 961 | PlayInfo.eBlendType=EBlend_FadeOut; |
| 962 | PushPatternToMixList(PlayInfo); |
| 963 | m_pCurrPattern=NULL; |
| 964 | } |
| 965 | memset(&(pOutput[nOfs]), 0, nSamples*m_nBytesPerSample); |
| 966 | MixStreams(&(pOutput[nOfs]), nSamples); |
| 967 | return TRUE; |
| 968 | } |
| 969 | // if no patterns are chosen, lets choose one |
| 970 | if (!m_pCurrPattern) |
| 971 | m_pCurrPattern=ChoosePattern(m_pCurrMood); |
| 972 | if (!m_pNextPattern) |
| 973 | m_pNextPattern=ChoosePattern(m_pCurrMood); |
| 974 | for (;;) |
| 975 | { |
| 976 | if (!m_pCurrPattern) |
| 977 | { |
| 978 | // there is no pattern available... weired |
| 979 | memset(&(pOutput[nOfs]), 0, nSamples*m_nBytesPerSample); |
| 980 | break; |
| 981 | } |
| 982 | // retrieve samples to next fade-point so we can decide if we wanna play additional layers |
| 983 | int nSamplesToNextFade=m_pCurrPattern->GetSamplesToNextFadePoint(); // fast |
| 984 | // lets add some other layers |
| 985 | if ((!m_bBridging) && (nSamplesToNextFade<=nSamples)) // are we not bridging and is the fade point in this block ? |
| 986 | { |
| 987 | // adjust streams ref-count, so it will free up patterns which will finish this frame |
| 988 | AdjustMixStreamsRefCount(nSamplesToNextFade); |
| 989 | // ...yes, lets eventually choose some layered patterns |
| 990 | // rhythmic layer |
| 991 | if ((m_nLayeredRhythmicPatterns < m_pCurrMood->pCurrPatternSet->nMaxSimultaneousRhythmicPatterns) && |
no test coverage detected