pre-passage f32
This commit is contained in:
@@ -40,14 +40,95 @@ impl Speaker {
|
||||
}
|
||||
|
||||
pub fn get_stream_config(&self) -> StreamConfig {
|
||||
let config = self.get_output_config();
|
||||
let mut stream_config: StreamConfig = config.into();
|
||||
stream_config.channels = 2;
|
||||
stream_config.sample_rate = SampleRate(44100);
|
||||
// stream_config.buffer_size = BufferSize::Fixed(960);
|
||||
stream_config
|
||||
// Lister toutes les configurations supportées
|
||||
self.print_supported_configs();
|
||||
|
||||
StreamConfig {
|
||||
channels: 2,
|
||||
sample_rate: SampleRate(44100),
|
||||
buffer_size: BufferSize::Default
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_supported_configs(&self) {
|
||||
println!("\n=== CONFIGURATIONS AUDIO DISPONIBLES ===");
|
||||
|
||||
// Configuration par défaut
|
||||
match self.device.default_output_config() {
|
||||
Ok(config) => {
|
||||
println!("📌 Configuration par défaut:");
|
||||
println!(" Canaux: {}", config.channels());
|
||||
println!(" Sample Rate: {} Hz", config.sample_rate().0);
|
||||
println!(" Format: {:?}", config.sample_format());
|
||||
println!(" Buffer Size: {:?}", config.buffer_size());
|
||||
},
|
||||
Err(e) => println!("❌ Impossible d'obtenir la config par défaut: {}", e)
|
||||
}
|
||||
|
||||
// Toutes les configurations supportées
|
||||
println!("\n📋 Toutes les configurations supportées:");
|
||||
match self.device.supported_output_configs() {
|
||||
Ok(configs) => {
|
||||
for (i, config_range) in configs.enumerate() {
|
||||
println!("\n Config #{}", i + 1);
|
||||
println!(" Canaux: {}", config_range.channels());
|
||||
println!(" Sample Rate: {} - {} Hz",
|
||||
config_range.min_sample_rate().0,
|
||||
config_range.max_sample_rate().0);
|
||||
println!(" Format: {:?}", config_range.sample_format());
|
||||
println!(" Buffer Size: {:?}", config_range.buffer_size());
|
||||
|
||||
// Suggestions de sample rates courants
|
||||
let common_rates = [8000, 11025, 16000, 22050, 44100, 48000, 88200, 96000];
|
||||
let mut supported_common = Vec::new();
|
||||
for rate in common_rates {
|
||||
if rate >= config_range.min_sample_rate().0 && rate <= config_range.max_sample_rate().0 {
|
||||
supported_common.push(rate);
|
||||
}
|
||||
}
|
||||
if !supported_common.is_empty() {
|
||||
println!(" Sample rates courants supportés: {:?}", supported_common);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => println!("❌ Impossible de lister les configs: {}", e)
|
||||
}
|
||||
|
||||
// Informations sur le device
|
||||
println!("\n🎧 Informations du device:");
|
||||
if let Ok(name) = self.device.name() {
|
||||
println!(" Nom: {}", name);
|
||||
}
|
||||
|
||||
// Test de configurations spécifiques
|
||||
println!("\n🧪 Test de configurations spécifiques:");
|
||||
let test_configs = [
|
||||
(44100, 1, "Mono 44.1kHz"),
|
||||
(44100, 2, "Stéréo 44.1kHz"),
|
||||
(48000, 1, "Mono 48kHz"),
|
||||
(48000, 2, "Stéréo 48kHz"),
|
||||
(22050, 2, "Stéréo 22.05kHz"),
|
||||
];
|
||||
|
||||
for (sample_rate, channels, description) in test_configs {
|
||||
let test_config = StreamConfig {
|
||||
channels,
|
||||
sample_rate: SampleRate(sample_rate),
|
||||
buffer_size: BufferSize::Default
|
||||
};
|
||||
|
||||
// Test si cette config est supportée (tentative de création d'un stream fictif)
|
||||
let dummy_callback = |_: &mut [f32], _: &cpal::OutputCallbackInfo| {};
|
||||
match self.device.build_output_stream(&test_config, dummy_callback, |_| {}, None) {
|
||||
Ok(_) => println!(" ✅ {} - SUPPORTÉ", description),
|
||||
Err(_) => println!(" ❌ {} - NON SUPPORTÉ", description),
|
||||
}
|
||||
}
|
||||
|
||||
println!("\n===========================================\n");
|
||||
}
|
||||
|
||||
|
||||
pub fn build_stream<F>(&self, callback: F) -> Stream
|
||||
where
|
||||
F: FnMut(&mut [i16], &cpal::OutputCallbackInfo) + Send + 'static,
|
||||
@@ -104,7 +185,6 @@ impl AudioPlayback {
|
||||
if !stream_running.load(Ordering::Relaxed){
|
||||
return;
|
||||
}
|
||||
println!("Audio playback stream tick");
|
||||
|
||||
let audio_mixer = mixer.read(data.len());
|
||||
data.copy_from_slice(&audio_mixer);
|
||||
|
||||
Reference in New Issue
Block a user