MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / Spkr_DSInit

Function Spkr_DSInit

source/Speaker.cpp:873–922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

871//=============================================================================
872
873bool Spkr_DSInit()
874{
875 //
876 // Create single Apple speaker voice
877 //
878
879 if (!DSAvailable())
880 {
881 LogFileOutput("Spkr_DSInit: DSAvailable=0\n");
882 return false;
883 }
884
885 SpeakerVoice.bIsSpeaker = true;
886
887 HRESULT hr = DSGetSoundBuffer(&SpeakerVoice, g_dwDSSpkrBufferSize, SPKR_SAMPLE_RATE, g_nSPKR_NumChannels, "Spkr");
888 if (FAILED(hr))
889 {
890 LogFileOutput("Spkr_DSInit: DSGetSoundBuffer failed (%08X)\n", hr);
891 return false;
892 }
893
894 if (!DSZeroVoiceBuffer(&SpeakerVoice, g_dwDSSpkrBufferSize))
895 {
896 LogFileOutput("Spkr_DSInit: DSZeroVoiceBuffer failed\n");
897 return false;
898 }
899
900 hr = SpeakerVoice.lpDSBvoice->SetVolume(SpeakerVoice.nVolume);
901 LogFileOutput("Spkr_DSInit: SetVolume(%d) res = %08X\n", SpeakerVoice.nVolume, (uint32_t)hr);
902
903 //
904
905 DWORD dwCurrentPlayCursor, dwCurrentWriteCursor;
906 hr = SpeakerVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
907 if (FAILED(hr))
908 LogFileOutput("Spkr_DSInit: GetCurrentPosition failed (%08X)\n", (uint32_t)hr);
909 if (SUCCEEDED(hr) && (dwCurrentPlayCursor == dwCurrentWriteCursor))
910 {
911 // KLUDGE: For my WinXP PC with "VIA AC'97 Enhanced Audio Controller"
912 // . Not required for my Win98SE/WinXP PC with PCI "Soundblaster Live!"
913 Sleep(200);
914
915 hr = SpeakerVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
916 LogFileOutput("Spkr_DSInit: GetCurrentPosition kludge (%08X)\n", (uint32_t)hr);
917 LogOutput("[DSInit] PC=%08X, WC=%08X, Diff=%08X\n", (uint32_t)dwCurrentPlayCursor,
918 (uint32_t)dwCurrentWriteCursor, (uint32_t)(dwCurrentWriteCursor-dwCurrentPlayCursor));
919 }
920
921 return true;
922}
923
924static void Spkr_DSUninit()
925{

Callers 1

SpkrInitializeFunction · 0.85

Calls 7

DSAvailableFunction · 0.85
LogFileOutputFunction · 0.85
DSGetSoundBufferFunction · 0.85
DSZeroVoiceBufferFunction · 0.85
LogOutputFunction · 0.85
GetCurrentPositionMethod · 0.80
SetVolumeMethod · 0.45

Tested by

no test coverage detected