├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── README.md ├── examples └── audio_driver.rs └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - stable 4 | - beta 5 | - nightly 6 | matrix: 7 | allow_failures: 8 | - rust: beta 9 | - rust: nightly 10 | notifications: 11 | email: 12 | - jake@fusetools.com 13 | os: 14 | - osx # TODO: Should actually run on all OS' supported eventually (once conditional compilation etc gates the right features) 15 | before_script: 16 | - rustc --version 17 | - cargo --version -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "emu" 3 | version = "0.1.3" 4 | authors = ["ferris "] 5 | description = "A set of libraries for writing emulators in Rust." 6 | homepage = "https://github.com/emu-rs/emu" 7 | repository = "https://github.com/emu-rs/emu" 8 | keywords = ["emu", "emulator"] 9 | license = "BSD-2-Clause" 10 | 11 | [dependencies] 12 | emu-audio = "0.1.2" 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Jake "ferris" Taylor 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # emu [![Build Status](https://travis-ci.org/emu-rs/emu.svg)](https://travis-ci.org/emu-rs/emu) [![Crates.io](https://img.shields.io/crates/v/emu.svg)](https://crates.io/crates/emu) [![Crates.io](https://img.shields.io/crates/l/emu.svg)](https://github.com/emu-rs/emu/blob/master/LICENSE) 2 | Because bad code don't fly! 3 | 4 | ## what 5 | emu is set of libraries full of infrastruture code for writing emulators in Rust. At the moment it's very much in its 6 | infancy and highly incomplete. The first goal is to port/rewrite enough existing infrastructure from my older 7 | [Fel library](https://github.com/yupferris/FerrisLibs/tree/master/Fel) to support porting various emulators I've 8 | written to Rust (like [this one](https://github.com/emu-rs/snes-apu) and 9 | [this one](https://github.com/yupferris/Vip8)), and from there it's all about exploration and writing more 10 | emulators :) . There will also be an effort throughout the project to separate as much of the code as possible 11 | into smaller crates that can be used in other projects (for example, I foresee the audio abstractions could be 12 | of use in other domains). 13 | 14 | ## why 15 | I've always been fascinated by emulators and emulation, and I've spent much of my time in the last 5 years 16 | exploring what makes them tick and different ways to make them. As with most of my projects, this is purely 17 | for personal exploration/growth, while still making an effort to produce production-quality code that's safe 18 | to [ab]use in the wild. This is one of the primary motivations for writing this library in Rust, another being 19 | bare-metal speed. 20 | 21 | ## license 22 | This code is licensed under the BSD2 license (see LICENSE). 23 | -------------------------------------------------------------------------------- /examples/audio_driver.rs: -------------------------------------------------------------------------------- 1 | extern crate emu; 2 | 3 | use emu::audio_driver::{AudioDriver, RenderCallback}; 4 | use emu::audio_driver_factory::create_default; 5 | 6 | use std::f64::consts::PI; 7 | 8 | use std::thread; 9 | 10 | struct TestUserResource { 11 | name: String, 12 | phase: f64 13 | } 14 | 15 | impl TestUserResource { 16 | fn new(name: String) -> TestUserResource { 17 | println!("Test user resource created ({})", name); 18 | TestUserResource { name: name, phase: 0.0 } 19 | } 20 | } 21 | 22 | impl Drop for TestUserResource { 23 | fn drop(&mut self) { 24 | println!("Test user resource destroyed ({})", self.name); 25 | } 26 | } 27 | 28 | fn main() { 29 | let mut driver = { 30 | let mut test_user_resource = TestUserResource::new(String::from("a")); 31 | let callback: Box = Box::new(move |buffer, num_frames| { 32 | for i in 0..num_frames { 33 | let value = (test_user_resource.phase * PI).sin() as f32; 34 | let buffer_index = i * 2; 35 | buffer[buffer_index + 0] = value; 36 | buffer[buffer_index + 1] = value; 37 | test_user_resource.phase += 440.0 / 44100.0; 38 | } 39 | }); 40 | 41 | let mut ret = create_default(); 42 | ret.set_render_callback(Some(callback)); 43 | ret 44 | }; 45 | 46 | println!("All systems are go."); 47 | 48 | println!("Starting render callback tests."); 49 | thread::sleep_ms(1000); 50 | 51 | println!("Swapping callback..."); 52 | 53 | { 54 | let mut test_user_resource = TestUserResource::new(String::from("b")); 55 | let callback: Box = Box::new(move |buffer, num_frames| { 56 | for i in 0..num_frames { 57 | let value = (test_user_resource.phase * 2.0 * PI).sin() as f32; 58 | let buffer_index = i * 2; 59 | buffer[buffer_index + 0] = value; 60 | buffer[buffer_index + 1] = value; 61 | test_user_resource.phase += 440.0 / 44100.0; 62 | } 63 | }); 64 | 65 | driver.set_render_callback(Some(callback)); 66 | } 67 | 68 | println!("Callback swapped"); 69 | thread::sleep_ms(1000); 70 | 71 | println!("Render callback tests completed."); 72 | 73 | println!("Starting is enabled tests."); 74 | 75 | println!("Driver is enabled: {}", driver.is_enabled()); 76 | thread::sleep_ms(1000); 77 | 78 | driver.set_is_enabled(false); 79 | println!("Driver is enabled: {}", driver.is_enabled()); 80 | thread::sleep_ms(1000); 81 | 82 | driver.set_is_enabled(true); 83 | println!("Driver is enabled: {}", driver.is_enabled()); 84 | thread::sleep_ms(1000); 85 | 86 | println!("Is enabled tests completed."); 87 | 88 | println!("Starting sample rate tests."); 89 | 90 | println!("Driver sample rate: {}", driver.sample_rate()); 91 | thread::sleep_ms(1000); 92 | 93 | driver.set_sample_rate(32000); 94 | println!("Driver sample rate: {}", driver.sample_rate()); 95 | thread::sleep_ms(1000); 96 | 97 | driver.set_sample_rate(22050); 98 | println!("Driver sample rate: {}", driver.sample_rate()); 99 | thread::sleep_ms(1000); 100 | 101 | driver.set_sample_rate(11025); 102 | println!("Driver sample rate: {}", driver.sample_rate()); 103 | thread::sleep_ms(1000); 104 | 105 | driver.set_sample_rate(96000); 106 | println!("Driver sample rate: {}", driver.sample_rate()); 107 | thread::sleep_ms(1000); 108 | 109 | driver.set_sample_rate(44100); 110 | println!("Driver sample rate: {}", driver.sample_rate()); 111 | thread::sleep_ms(1000); 112 | 113 | println!("Sample rate tests completed."); 114 | 115 | //let mut derp = String::new(); 116 | //io::stdin().read_line(&mut derp).ok(); 117 | } 118 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate emu_audio; 2 | 3 | pub use self::emu_audio::*; 4 | --------------------------------------------------------------------------------