Git Product home page Git Product logo

mod_player's Introduction

mod_player is a crate that reads and plays back mod audio files. The mod_player decodes the audio one sample pair (left,right) at a time that can be streamed to an audio device or a file.

For playback, only two functions are needed;

  • read_mod_file to read the file into a Song structure
  • next_sample to get the next sample

To use the library to decode a mod file and save it to disk ( using the hound audio crate for WAV saving )

use hound;
 
fn main() {
    let spec = hound::WavSpec { 
    channels: 2,
        sample_rate: 48100,
        bits_per_sample: 32,
        sample_format: hound::SampleFormat::Float,
    };

    let mut writer = hound::WavWriter::create( "out.wav", spec).unwrap();
    let song = mod_player::read_mod_file("BUBBLE_BOBBLE.MOD");
    let mut player_state : mod_player::PlayerState = mod_player::PlayerState::new( 
                                song.format.num_channels, spec.sample_rate );
    loop {
        let ( left, right ) = mod_player::next_sample(&song, &mut player_state);
        writer.write_sample( left  );
        writer.write_sample( right  );
        if player_state.song_has_ended || player_state.has_looped { 
            break;
        }
    }
 }

mod_player's People

Contributors

hrydgard avatar janiorca avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

hrydgard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.