• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

TiMidity++ 改造版 (Windows 専用)


コミットメタ情報

リビジョン00e5dabfc795ef5b33465080be0294865b8a07d5 (tree)
日時2017-11-12 21:26:47
作者Starg <starg@user...>
コミッターStarg

ログメッセージ

Append null bytes if the size of the audio buffer is not aligned. Previously such data were trimmed.

変更サマリ

差分

--- a/timidity/wasapi_a.c
+++ b/timidity/wasapi_a.c
@@ -182,21 +182,31 @@ void DeleteRenderBuffer(RenderBuffer* pRenderBuffer)
182182 pRenderBuffer->pFree = NULL;
183183 }
184184
185+/* if *ppData == NULL, appends `size` count of zeros */
185186 void PushToRenderBufferPartial(RenderBufferNode* pNode, const char** ppData, size_t* pSize)
186187 {
187- size_t copyLength = pNode->Capacity - pNode->CurrentSize;
188+ size_t pushLength = pNode->Capacity - pNode->CurrentSize;
188189
189- if (copyLength > *pSize)
190+ if (pushLength > *pSize)
190191 {
191- copyLength = *pSize;
192+ pushLength = *pSize;
192193 }
193194
194- memcpy(pNode->Data + pNode->CurrentSize, *ppData, copyLength);
195- *ppData += copyLength;
196- *pSize -= copyLength;
197- pNode->CurrentSize += copyLength;
195+ if (*ppData)
196+ {
197+ memcpy(pNode->Data + pNode->CurrentSize, *ppData, pushLength);
198+ *ppData += pushLength;
199+ }
200+ else
201+ {
202+ memset(pNode->Data + pNode->CurrentSize, 0, pushLength);
203+ }
204+
205+ *pSize -= pushLength;
206+ pNode->CurrentSize += pushLength;
198207 }
199208
209+/* if pData == NULL, appends `size` count of zeros */
200210 int PushToRenderBuffer(RenderBuffer* pRenderBuffer, const char* pData, size_t size)
201211 {
202212 while (size > 0)
@@ -255,6 +265,11 @@ int PushToRenderBuffer(RenderBuffer* pRenderBuffer, const char* pData, size_t si
255265 return TRUE;
256266 }
257267
268+int PushZeroToRenderBuffer(RenderBuffer* pRenderBuffer, size_t size)
269+{
270+ return PushToRenderBuffer(pRenderBuffer, NULL, size);
271+}
272+
258273 size_t CalculateRenderBufferSize(RenderBuffer* pRenderBuffer, size_t maxSize)
259274 {
260275 size_t size = 0;
@@ -587,17 +602,31 @@ int WASAPIDoWriteBuffer(void)
587602 size_t numberOfBytesToCopy = CalculateRenderBufferSize(&g_WASAPIContext.Buffer, (g_WASAPIContext.BufferSizeInFrames - padding) * g_WASAPIContext.FrameSize);
588603 size_t numberOfFramesToCopy = numberOfBytesToCopy / g_WASAPIContext.FrameSize;
589604
590- if (numberOfFramesToCopy > 0)
605+ if (g_WASAPIContext.IsExclusive && numberOfFramesToCopy < g_WASAPIContext.BufferSizeInFrames)
591606 {
592- BYTE* pData;
593- HRESULT hr = IAudioRenderClient_GetBuffer(g_WASAPIContext.pAudioRenderClient, numberOfFramesToCopy, &pData);
607+ if (!PushZeroToRenderBuffer(&g_WASAPIContext.Buffer, g_WASAPIContext.BufferSizeInFrames * g_WASAPIContext.FrameSize - numberOfBytesToCopy))
608+ {
609+ return FALSE;
610+ }
594611
595- if (hr == AUDCLNT_E_BUFFER_SIZE_ERROR)
612+ numberOfBytesToCopy = g_WASAPIContext.BufferSizeInFrames * g_WASAPIContext.FrameSize;
613+ numberOfFramesToCopy = numberOfBytesToCopy / g_WASAPIContext.FrameSize;
614+ }
615+ else if (numberOfFramesToCopy == 0)
616+ {
617+ if (!PushZeroToRenderBuffer(&g_WASAPIContext.Buffer, g_WASAPIContext.FrameSize - numberOfBytesToCopy))
596618 {
597- PopRenderBuffer(&g_WASAPIContext.Buffer, numberOfFramesToCopy * g_WASAPIContext.FrameSize);
598- return TRUE;
619+ return FALSE;
599620 }
600- else if (FAILED(hr))
621+
622+ numberOfBytesToCopy = g_WASAPIContext.FrameSize;
623+ numberOfFramesToCopy = 1;
624+ }
625+
626+ {
627+ BYTE* pData;
628+
629+ if (FAILED(IAudioRenderClient_GetBuffer(g_WASAPIContext.pAudioRenderClient, numberOfFramesToCopy, &pData)))
601630 {
602631 return FALSE;
603632 }
@@ -605,10 +634,6 @@ int WASAPIDoWriteBuffer(void)
605634 PopRenderBuffer(&g_WASAPIContext.Buffer, ReadRenderBuffer(&g_WASAPIContext.Buffer, (char*)pData, numberOfFramesToCopy * g_WASAPIContext.FrameSize));
606635 IAudioRenderClient_ReleaseBuffer(g_WASAPIContext.pAudioRenderClient, numberOfFramesToCopy, 0);
607636 }
608- else
609- {
610- ClearRenderBuffer(&g_WASAPIContext.Buffer);
611- }
612637 }
613638
614639 return TRUE;