Render audio waveforms on gpu

This commit is contained in:
Skyler Lehmkuhl
2026-02-11 14:38:58 -05:00
parent fc58f29ccd
commit 8ac5f52f28
12 changed files with 1100 additions and 855 deletions
+35
View File
@@ -1812,6 +1812,16 @@ impl Engine {
None => QueryResponse::PoolFileInfo(Err(format!("Pool index {} not found", pool_index))),
}
}
Query::GetPoolAudioSamples(pool_index) => {
match self.audio_pool.get_file(pool_index) {
Some(file) => QueryResponse::PoolAudioSamples(Ok((
file.data.clone(),
file.sample_rate,
file.channels,
))),
None => QueryResponse::PoolAudioSamples(Err(format!("Pool index {} not found", pool_index))),
}
}
Query::ExportAudio(settings, output_path) => {
// Perform export directly - this will block the audio thread but that's okay
// since we're exporting and not playing back anyway
@@ -2898,6 +2908,31 @@ impl EngineController {
Err("Query timeout".to_string())
}
/// Get raw audio samples from pool (samples, sample_rate, channels)
pub fn get_pool_audio_samples(&mut self, pool_index: usize) -> Result<(Vec<f32>, u32, u32), String> {
if let Err(_) = self.query_tx.push(Query::GetPoolAudioSamples(pool_index)) {
return Err("Failed to send query - queue full".to_string());
}
let start = std::time::Instant::now();
let timeout = std::time::Duration::from_secs(5); // Longer timeout for large audio data
while start.elapsed() < timeout {
if let Ok(response) = self.query_response_rx.pop() {
match response {
QueryResponse::PoolAudioSamples(result) => return result,
QueryResponse::AudioExported(result) => {
self.cached_export_response = Some(result);
}
_ => {}
}
}
std::thread::sleep(std::time::Duration::from_millis(1));
}
Err("Query timeout".to_string())
}
/// Request waveform chunks to be generated
/// This is an asynchronous command - chunks will be returned via WaveformChunksReady events
pub fn generate_waveform_chunks(
+4
View File
@@ -299,6 +299,8 @@ pub enum Query {
AddAudioClipSync(TrackId, usize, f64, f64, f64),
/// Add an audio file to the pool synchronously (path, data, channels, sample_rate) - returns pool index
AddAudioFileSync(String, Vec<f32>, u32, u32),
/// Get raw audio samples from pool (pool_index) - returns (samples, sample_rate, channels)
GetPoolAudioSamples(usize),
/// Get a clone of the current project for serialization
GetProject,
/// Set the project (replaces current project state)
@@ -368,6 +370,8 @@ pub enum QueryResponse {
AudioClipInstanceAdded(Result<AudioClipInstanceId, String>),
/// Audio file added to pool (returns pool index)
AudioFileAddedSync(Result<usize, String>),
/// Raw audio samples from pool (samples, sample_rate, channels)
PoolAudioSamples(Result<(Vec<f32>, u32, u32), String>),
/// Project retrieved
ProjectRetrieved(Result<Box<crate::audio::project::Project>, String>),
/// Project set