GithubHelp home page GithubHelp logo

pmdmini's Introduction

pmdmini

pmdmini is a C library with a simple API which can play back MDX chiptunes from the PC-98. The PC-98 was a very popular series of Japanese home computers. With its Yamaha YM2203 or YM2608 sound chip, for which many games and songs were written; the Professional Music Driver (PMD) library was a popular music library created by M. Kajihara. pmdmini allows playing back music written using PMD.

Some sample PMD music can be found at the Modland FTP and at the website of Zun (creator of the Touhou series of games).

Usage

Detailed API documentation is available in the pmdmini.h header file, but the following sample program shows how to use mdxmini to open a file, extract some metadata, and play back music:

// Initializes the library, before performing any other actions.
pmd_init();
// Check if the file is a valid PMD file before doing anything else!
int is_valid = pmd_is_pmd(path_to_file);
if (!is_valid) {
    fprintf(stderr, "Failed to open input file: %s\n", path_to_file);
    return 1;
}

// Before playback begins, call pmd_setrate to set the preferred sampling rate for generated audio.
int playback_rate = 48000;
pmd_setrate(playback_rate);

// Opens the file on disk and prepares the player for playback.
pmd_play(path_to_file, path_to_samples);

// Get the song duration, in whole seconds.
int length = pmd_length_sec();
printf("Song length: %i seconds\n", length);

// pmd_get_title allows the song's title to be fetched; this is usually encoded in Shift-JIS.
char title[1024];
pmd_get_title(title);
printf("Title: %s\n", title);
// The composer is stored separately; this is also Shift-JIS.
char compo[1024];
pmd_get_compo(compo);
printf("Composer: %s\n", title);

// For playback, define a buffer into which we'll render raw PCM data.
int buf_len = 8192;
short buf[buf_len];
// Number of channels, which we'll fetch for display later.
// This is constant for a given song, so just fetch it once.
int number_of_channels = pmd_get_tracks();
printf("Number of channels: %i\n", number_of_channels);
// A buffer into which we'll write information about the notes being played in a given frame.
int notes[32];

int position;

// Track the number of buffers played so far, which is useful to calculate the current position.
int played_buffers = 0;
int finished = 1;

// The playback loop!
while (finished == 1)
{
    // Calculate the song position based on the buffer size and frequency.
    position = played_buffers / (((playback_rate * 16 * 2) / 8) / (buf_len * 2));
    printf("Current position: %i / %i\n", position, length);

    // Render samples into the buffer
    pmd_renderer(buf, buf_len / 2);
    // Check the position against the reported duration to determine if playback is finished
    if (position >= length) {
        finished = 0;
    }

    // Do something with the calculated sample here; this is platform-dependent, so this intro will omit it.

    // Fill the note buffer with information about the notes in the current frame
    pmd_get_current_notes(notes, number_of_channels);

    for (int i = 0; i < number_of_channels; i++) {
        printf("Note for channel %i is %i\n", i, notes[i]);
    }

    // Increment the count of played buffers.
    played_buffers++;
}

// When playback is over, finalize the library's state.
pmd_stop();

Programs using pmdmini

Credits

  • KAJIHARA Mashahiro - original author of the PMD sound driver for PC-9801
  • AGAWA Koji - Maintainer of PMDXMMS, on which pmdmini was based
  • PMDWin / C60 - PMD sound engine for Windows, on which PMDXMMS was based
  • M88 / cisc - author of OPNA FM sound generator used by PMDWin
  • PPZ8 / Ukky - author of PPZ8 PCM driver
  • BouKiCHi - author of the pmdmini library, and of the Android mdxplayer
  • Misty De Meo - bugfixes and improvements to mdxmini, current maintainer

pmdmini's People

Contributors

mistydemeo avatar boukichi avatar danielnachun avatar fxcoudert avatar

Stargazers

 avatar  avatar  avatar Hanaky avatar Tomás Pollak avatar  avatar Liu Wenyuan avatar Maple Kaede avatar Ethan Kerrick avatar Damian Rogers avatar ::1 avatar mikaela m.d. souza avatar Christian David Becerra Montoya avatar YY avatar  avatar Brian Lee avatar Giangiacomo Zaffini avatar  avatar Anhang Li / Yukidama avatar Alex ODonnell avatar Thomas Daede avatar Shannon Freeman avatar Mike avatar Devin Acker avatar YL avatar  avatar  avatar 冬日 avatar  avatar RGBA_CRT avatar DeltaRazero avatar tcdw avatar Yuxin avatar Gabriel Cavallo avatar mactkg avatar

Watchers

 avatar James Cloos avatar RGBA_CRT avatar  avatar

pmdmini's Issues

licensing mismatch

The last uncorrupted version of cisc's licensing info for his "fmgen" lib states: "商用ソフト(シェアウェア含む) に本ソースコードの一部,または 全部を組み込む際には,事前に作者の合意を得る必要があります." (see FM Sound Generator with OPN/OPM interface Copyright (C) by cisc 1998, 2003.)

If "google translate" did not screw this up completely, then any use of the code for commercial purposes requires cisc's prior consent.

I don't think that any project that builds on this code can use GPL (unless cisc has also issued some additional GPL license that I am unaware of).

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.