Skip to content

Commit

Permalink
Merge pull request #54 from sevonj/devices/psg
Browse files Browse the repository at this point in the history
Devices/psg
  • Loading branch information
sevonj authored Dec 10, 2023
2 parents ab7dd98 + b63752f commit fbed288
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/emulator/devices.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
//!
//! This module contains device traits, and the Bus struct, which parents all devices.
//!
//! A device means a piece of hardware that is made accessible to the program via IO calls.
//! A device here means a piece of hardware that is made accessible to the program via IO traits.
//!
//! Every device is accessible from the Bus struct.
//!
//! If you're writing a new device, it must implement the Device trait, and also one of, or both MMIO and PMIO traits.
//! If you're writing a new device, it must implement the Device trait, and at least one of the IO traits.
use self::{
dev_crt::DevCRT, dev_display_classic::DevDisplayClassic, dev_kbd::DevKBD, dev_pic::DevPIC,
dev_ram::DevRAM, dev_rtc::DevRTC, psg::DevPSG,
dev_ram::DevRAM, dev_rtc::DevRTC, dev_psg::DevPSG,
};
mod dev_crt;
mod dev_display_classic;
mod dev_kbd;
mod dev_pic;
mod dev_ram;
mod dev_rtc;
mod psg;
mod dev_psg;
mod dev_midi;
mod dev_pad;
#[cfg(test)]
mod tests;

Expand Down
2 changes: 1 addition & 1 deletion src/emulator/devices/dev_display_classic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//!
//! Color screen with memory mapped framebuffer
//! Memory mapped framebuffer
//!
use super::{Device, MMIO};
use image::Rgba;
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/devices/dev_midi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//!
//! This will become a port-mapped midi controller.
//! This will become the MIDI port.
//!
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
//! This will become a gamepad port.
//!
//use super::PMIO;

41 changes: 30 additions & 11 deletions src/emulator/devices/psg.rs → src/emulator/devices/dev_psg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//!
use super::{Device, MMIO};
use rodio::{OutputStream, OutputStreamHandle, Sink, Source};
use rodio::{OutputStream, Sink, Source};
use std::sync::{Arc, Mutex};

mod envelope;
Expand All @@ -33,8 +33,7 @@ const SAMPLE_RATE: u32 = 22050;
/// Device struct.
///
pub(crate) struct DevPSG {
_stream: OutputStream,
stream_handle: OutputStreamHandle,
stream: Option<OutputStream>,
sink0: Sink,
sink1: Sink,
sink2: Sink,
Expand All @@ -47,15 +46,36 @@ pub(crate) struct DevPSG {

impl Default for DevPSG {
fn default() -> Self {
// Create a new sink for this device
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink0 = Sink::try_new(&stream_handle).unwrap();
//
let try_default = OutputStream::try_default();

let sink0;
let sink1;
let sink2;
let sink3;

let stream;
// Host has an audio device, create sinks.
if try_default.is_ok() {
let (_stream, _stream_handle) = try_default.unwrap();
stream = Some(_stream);
sink0 = Sink::try_new(&_stream_handle).unwrap();
sink1 = Sink::try_new(&_stream_handle).unwrap();
sink2 = Sink::try_new(&_stream_handle).unwrap();
sink3 = Sink::try_new(&_stream_handle).unwrap();
}
// No audio devices available. Create sinks that do nothing.
else {
stream = None;
(sink0, _) = Sink::new_idle();
(sink1, _) = Sink::new_idle();
(sink2, _) = Sink::new_idle();
(sink3, _) = Sink::new_idle();
}

sink0.pause();
let sink1 = Sink::try_new(&stream_handle).unwrap();
sink1.pause();
let sink2 = Sink::try_new(&stream_handle).unwrap();
sink2.pause();
let sink3 = Sink::try_new(&stream_handle).unwrap();
sink3.pause();

// Create channels
Expand All @@ -71,8 +91,7 @@ impl Default for DevPSG {
sink3.append(AudioSource::new(ch3.clone()));

DevPSG {
_stream,
stream_handle,
stream: stream,
sink0,
sink1,
sink2,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fbed288

Please sign in to comment.