#mod #player #audio #music #time #file

bin+lib mod_player

A library for parsing and playing mod music files

5 releases

0.1.4 Jun 2, 2019
0.1.3 May 20, 2019
0.1.2 Apr 29, 2019
0.1.1 Apr 2, 2019
0.1.0 Mar 31, 2019

#192 in Audio

Download history 20/week @ 2022-03-14 16/week @ 2022-03-21 5/week @ 2022-04-18 30/week @ 2022-04-25 30/week @ 2022-05-02 5/week @ 2022-05-09 85/week @ 2022-05-16 27/week @ 2022-05-23 32/week @ 2022-05-30 15/week @ 2022-06-06 2/week @ 2022-06-20

59 downloads per month

MIT license

2MB
1.5K SLoC

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;
        }
    }
 }

No runtime deps