mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add code to ignore jack as an audio device
Former-commit-id: 1dbaa796f82f2e9be26a3648e9aaca81f3348134
This commit is contained in:
parent
5a04e98725
commit
315767f19f
BIN
assets/voxygen/audio/soundtrack/Ethereal_Bonds.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/Ethereal_Bonds.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/Mineral_Deposits.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/Mineral_Deposits.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/Ruination.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/Ruination.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/Snowtop.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/Snowtop.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/fiesta_del_pueblo.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/fiesta_del_pueblo.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/library_theme_with_harpsichord.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/library_theme_with_harpsichord.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/sacred_temple.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/sacred_temple.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/voxygen/audio/soundtrack/veloren_title_tune-3.ogg
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/audio/soundtrack/veloren_title_tune-3.ogg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -24,6 +24,10 @@ conrod_core = { git = "https://gitlab.com/veloren/conrod.git" }
|
||||
conrod_winit = { git = "https://gitlab.com/veloren/conrod.git" }
|
||||
euc = "0.2"
|
||||
|
||||
# Audio
|
||||
rodio = "0.8"
|
||||
lewton = "0.9"
|
||||
|
||||
# ECS
|
||||
specs = "0.14"
|
||||
|
||||
|
94
voxygen/src/audio/mod.rs
Normal file
94
voxygen/src/audio/mod.rs
Normal file
@ -0,0 +1,94 @@
|
||||
//extern crate byteorder;
|
||||
extern crate lewton;
|
||||
extern crate rodio;
|
||||
|
||||
use common::assets;
|
||||
use rodio::{Decoder, Device, Source, SpatialSink};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
path::PathBuf,
|
||||
sync::mpsc::{channel, Receiver, Sender, TryRecvError},
|
||||
thread,
|
||||
thread::{sleep, JoinHandle},
|
||||
time::Duration,
|
||||
};
|
||||
use vek::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Position {
|
||||
pub relative: bool,
|
||||
pub pos: Vec3<f32>,
|
||||
pub vel: Vec3<f32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Fade {
|
||||
pub in_duration: Duration,
|
||||
pub out_duration: Duration,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Stream {
|
||||
pub buffer: u64,
|
||||
pub start_tick: Duration,
|
||||
pub duration: Duration,
|
||||
pub volume: f32,
|
||||
pub repeat: Option<()>,
|
||||
pub positional: Option<Position>,
|
||||
pub fading: Option<Fade>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Buffer {
|
||||
File(PathBuf),
|
||||
Raw(Vec<u8>),
|
||||
}
|
||||
|
||||
enum Msg {
|
||||
Position(Vec3<f32>, Vec3<f32>, Mat4<f32>),
|
||||
CreateSource(Buffer),
|
||||
Stop,
|
||||
}
|
||||
|
||||
pub struct AudioFrontend {
|
||||
device: Device,
|
||||
streams: HashMap<String, SpatialSink>, //always use SpatialSink even if no possition is used for now
|
||||
}
|
||||
|
||||
impl AudioFrontend {
|
||||
pub fn new() -> Self {
|
||||
let mut device = rodio::default_output_device().unwrap();
|
||||
|
||||
for d in rodio::devices() {
|
||||
if d.name().contains("jack") {
|
||||
continue;
|
||||
}
|
||||
|
||||
device = d;
|
||||
break;
|
||||
}
|
||||
|
||||
AudioFrontend {
|
||||
device,
|
||||
streams: HashMap::<String, SpatialSink>::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_music(&mut self, path: &str) {
|
||||
let file = File::open(format!("assets/{}", path)).unwrap();
|
||||
let src = Decoder::new(BufReader::new(file)).unwrap();
|
||||
|
||||
let mut sink = rodio::SpatialSink::new(
|
||||
&self.device,
|
||||
[0.0, 0.0, 0.0],
|
||||
[1.0, 0.0, 0.0],
|
||||
[-1.0, 0.0, 0.0],
|
||||
);
|
||||
|
||||
sink.append(src);
|
||||
|
||||
self.streams.insert(path.to_string(), sink);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#[macro_use]
|
||||
pub mod ui;
|
||||
pub mod anim;
|
||||
pub mod audio;
|
||||
pub mod error;
|
||||
pub mod hud;
|
||||
pub mod key_state;
|
||||
@ -19,7 +20,7 @@ pub mod window;
|
||||
// Reexports
|
||||
pub use crate::error::Error;
|
||||
|
||||
use crate::{menu::main::MainMenuState, settings::Settings, window::Window};
|
||||
use crate::{audio::AudioFrontend, menu::main::MainMenuState, settings::Settings, window::Window};
|
||||
use log;
|
||||
use simplelog::{CombinedLogger, Config, TermLogger, WriteLogger};
|
||||
use std::{fs::File, mem, panic, str::FromStr, thread};
|
||||
@ -31,6 +32,7 @@ const DEFAULT_PUBLIC_SERVER: &'static str = "server.veloren.net";
|
||||
pub struct GlobalState {
|
||||
settings: Settings,
|
||||
window: Window,
|
||||
audio: AudioFrontend,
|
||||
}
|
||||
|
||||
impl GlobalState {
|
||||
@ -91,7 +93,9 @@ fn main() {
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
// Set up panic handler to relay swish panic messages to the user.
|
||||
let audio = AudioFrontend::new();
|
||||
|
||||
// Set up panic handler to relay swish panic messages to the user
|
||||
let settings_clone = settings.clone();
|
||||
let default_hook = panic::take_hook();
|
||||
panic::set_hook(Box::new(move |panic_info| {
|
||||
@ -153,7 +157,11 @@ fn main() {
|
||||
default_hook(panic_info);
|
||||
}));
|
||||
|
||||
let mut global_state = GlobalState { settings, window };
|
||||
let mut global_state = GlobalState {
|
||||
settings,
|
||||
window,
|
||||
audio,
|
||||
};
|
||||
|
||||
// Set up the initial play state.
|
||||
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(&mut global_state))];
|
||||
|
@ -47,6 +47,10 @@ impl PlayState for MainMenuState {
|
||||
// Used for client creation.
|
||||
let mut client_init: Option<ClientInit> = None;
|
||||
|
||||
global_state
|
||||
.audio
|
||||
.play_music("voxygen/audio/soundtrack/veloren_title_tune-3.ogg");
|
||||
|
||||
loop {
|
||||
// Handle window events.
|
||||
for event in global_state.window.fetch_events() {
|
||||
|
Loading…
Reference in New Issue
Block a user