Skip to content

Commit

Permalink
[audiosource] removed unnecessary SDL_CreateAudioStream call from Stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Feb 13, 2025
1 parent 348c298 commit cdfda95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
58 changes: 29 additions & 29 deletions runtime/Rendering/Renderer_Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,40 +1371,40 @@ namespace spartan
return;

cmd_list->BeginTimeblock("light_integration_environment_filter");
{
uint32_t mip_count = tex_environment->GetMipCount();
uint32_t mip_level = mip_count - m_environment_mips_to_filter_count;
SP_ASSERT(mip_level != 0);

// generate mips as light_integration.hlsl expects them
if (mip_level == 0)
{
Pass_Downscale(cmd_list, tex_environment, Renderer_DownsampleFilter::Average);
}

uint32_t mip_count = tex_environment->GetMipCount();
uint32_t mip_level = mip_count - m_environment_mips_to_filter_count;
SP_ASSERT(mip_level != 0);

// generate mips as light_integration.hlsl expects them
if (mip_level == 0)
{
Pass_Downscale(cmd_list, tex_environment, Renderer_DownsampleFilter::Average);
}

// set pipeline state
static RHI_PipelineState pso;
pso.name = "light_integration_environment_filter";
pso.shaders[Compute] = shader_c;
cmd_list->SetPipelineState(pso);

cmd_list->SetTexture(Renderer_BindingsSrv::environment, tex_environment);
cmd_list->SetTexture(Renderer_BindingsUav::tex, tex_environment, mip_level, 1);
// set pipeline state
static RHI_PipelineState pso;
pso.name = "light_integration_environment_filter";
pso.shaders[Compute] = shader_c;
cmd_list->SetPipelineState(pso);

// set pass constants
m_pcb_pass_cpu.set_f3_value(static_cast<float>(mip_level), static_cast<float>(mip_count), 0.0f);
cmd_list->PushConstants(m_pcb_pass_cpu);
cmd_list->SetTexture(Renderer_BindingsSrv::environment, tex_environment);
cmd_list->SetTexture(Renderer_BindingsUav::tex, tex_environment, mip_level, 1);

const uint32_t thread_group_count = 8;
const uint32_t resolution_x = tex_environment->GetWidth() >> mip_level;
const uint32_t resolution_y = tex_environment->GetHeight() >> mip_level;
cmd_list->Dispatch(
static_cast<uint32_t>(ceil(static_cast<float>(resolution_y) / thread_group_count)),
static_cast<uint32_t>(ceil(static_cast<float>(resolution_y) / thread_group_count))
);
// set pass constants
m_pcb_pass_cpu.set_f3_value(static_cast<float>(mip_level), static_cast<float>(mip_count), 0.0f);
cmd_list->PushConstants(m_pcb_pass_cpu);

m_environment_mips_to_filter_count--;
const uint32_t thread_group_count = 8;
const uint32_t resolution_x = tex_environment->GetWidth() >> mip_level;
const uint32_t resolution_y = tex_environment->GetHeight() >> mip_level;
cmd_list->Dispatch(
static_cast<uint32_t>(ceil(static_cast<float>(resolution_y) / thread_group_count)),
static_cast<uint32_t>(ceil(static_cast<float>(resolution_y) / thread_group_count))
);

m_environment_mips_to_filter_count--;
}
cmd_list->EndTimeblock();
}

Expand Down
7 changes: 3 additions & 4 deletions runtime/World/Components/AudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace spartan
float camera_dot_sound = abs(Vector3::Dot(camera->GetEntity()->GetForward(), camera_to_sound));

// todo
// use like something SDL_SetAudioStreamPutCallback or similar to have a callback
// use something like SDL_SetAudioStreamPutCallback to have a callback
// in which we can modulate the bytes of each channel to do panning
// or maybe use the audio_device::spec somehow
}
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace spartan
// store the filename from the provided path
m_name = FileSystem::GetFileNameFromFilePath(file_path);

// allocate an audio spec and load the wav file into our buffer
// load the wav file into our buffer
CHECK_SDL_ERROR(SDL_LoadWAV(file_path.c_str(), &audio_device::spec, &m_buffer, &m_length));
}

Expand Down Expand Up @@ -221,9 +221,8 @@ namespace spartan
if (!m_is_playing)
return;

// re-create the stream so that playback can start from the beginning again
SDL_DestroyAudioStream(m_stream);
m_stream = SDL_CreateAudioStream(&audio_device::spec, &audio_device::spec);
m_stream = nullptr;

m_is_playing = false;
}
Expand Down

0 comments on commit cdfda95

Please sign in to comment.