@@ -875,6 +875,15 @@ bool AudioSystem::IsHRTFEnabled() const {
875875 return hrtfEnabled;
876876}
877877
878+ void AudioSystem::SetHRTFCPUOnly (bool cpuOnly) {
879+ hrtfCPUOnly = cpuOnly;
880+ std::cout << " HRTF processing mode set to " << (cpuOnly ? " CPU-only" : " Vulkan shader (when available)" ) << std::endl;
881+ }
882+
883+ bool AudioSystem::IsHRTFCPUOnly () const {
884+ return hrtfCPUOnly;
885+ }
886+
878887bool AudioSystem::LoadHRTFData (const std::string& filename) {
879888 if (!filename.empty ()) {
880889 std::cout << " Loading HRTF data from: " << filename << std::endl;
@@ -1001,15 +1010,63 @@ bool AudioSystem::LoadHRTFData(const std::string& filename) {
10011010}
10021011
10031012bool AudioSystem::ProcessHRTF (const float * inputBuffer, float * outputBuffer, uint32_t sampleCount, const float * sourcePosition) {
1004- if (!hrtfEnabled || !renderer || !renderer-> IsInitialized () ) {
1005- // If HRTF is disabled or renderer is not available , just copy input to output
1013+ if (!hrtfEnabled) {
1014+ // If HRTF is disabled, just copy input to output
10061015 for (uint32_t i = 0 ; i < sampleCount; i++) {
10071016 outputBuffer[i * 2 ] = inputBuffer[i]; // Left channel
10081017 outputBuffer[i * 2 + 1 ] = inputBuffer[i]; // Right channel
10091018 }
10101019 return true ;
10111020 }
10121021
1022+ // Check if we should use CPU-only processing or if Vulkan is not available
1023+ if (hrtfCPUOnly || !renderer || !renderer->IsInitialized ()) {
1024+ // Use CPU-based HRTF processing (either forced or fallback)
1025+ // Skip Vulkan buffer creation and go directly to CPU processing
1026+ } else {
1027+ // Use Vulkan shader-based HRTF processing
1028+ // Create buffers for HRTF processing if they don't exist or if the sample count has changed
1029+ if (!createHRTFBuffers (sampleCount)) {
1030+ std::cerr << " Failed to create HRTF buffers" << std::endl;
1031+ return false ;
1032+ }
1033+
1034+ // Copy input data to input buffer
1035+ void * data = inputBufferMemory.mapMemory (0 , sampleCount * sizeof (float ));
1036+ memcpy (data, inputBuffer, sampleCount * sizeof (float ));
1037+ inputBufferMemory.unmapMemory ();
1038+
1039+ // Set up HRTF parameters
1040+ struct HRTFParams {
1041+ float sourcePosition[3 ];
1042+ float listenerPosition[3 ];
1043+ float listenerOrientation[6 ]; // Forward (3) and up (3) vectors
1044+ uint32_t sampleCount;
1045+ uint32_t hrtfSize;
1046+ uint32_t numHrtfPositions;
1047+ float padding; // For alignment
1048+ } params;
1049+
1050+ // Copy source and listener positions
1051+ memcpy (params.sourcePosition , sourcePosition, sizeof (float ) * 3 );
1052+ memcpy (params.listenerPosition , listenerPosition, sizeof (float ) * 3 );
1053+ memcpy (params.listenerOrientation , listenerOrientation, sizeof (float ) * 6 );
1054+ params.sampleCount = sampleCount;
1055+ params.hrtfSize = hrtfSize;
1056+ params.numHrtfPositions = numHrtfPositions;
1057+ params.padding = 0 .0f ;
1058+
1059+ // Copy parameters to parameter buffer
1060+ data = paramsBufferMemory.mapMemory (0 , sizeof (HRTFParams));
1061+ memcpy (data, ¶ms, sizeof (HRTFParams));
1062+ paramsBufferMemory.unmapMemory ();
1063+
1064+ // TODO: Add actual Vulkan compute shader dispatch here
1065+ // For now, fall through to CPU processing
1066+ }
1067+
1068+ // CPU-based HRTF processing (used for both CPU-only mode and fallback)
1069+
10131070 // Create buffers for HRTF processing if they don't exist or if the sample count has changed
10141071 if (!createHRTFBuffers (sampleCount)) {
10151072 std::cerr << " Failed to create HRTF buffers" << std::endl;
0 commit comments