LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2013, 06:59 PM   #1
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Rep: Reputation: 22
help adding Mix_SetMusicCMD(aplaymidi -p 128:0); to chocolate-doom & eternity


Trying to add hardware midi support to chocolate-doom and eternity but not getting anywhere. Only want to forward midi songs to an external play via Mix_SetMusicCMD(aplaymidi -p 128:0); in sdl_mixer but having trouble.

Added Mix_SetMusicCMD(aplaymidi -p 128:0); to chocolate-doom-1.7.0/src/i_sdlmusic.c under
Code:
static void I_SDL_PlaySong(void *handle, int looping)
{
    Mix_Music *music = (Mix_Music *) handle;
    int loops;

    if (!music_initialized)
    {
        return;
    }

    if (handle == NULL)
    {
        return;
    }

    if (Mix_SetMusicCMD("aplaymidi -p 128:0")==-1)
    {
    perror("Mix_SetMusicCMD");
    }
but I get
Code:
Cannot open /tmp/doom.mid - No such file or directory
Also tried Mix_SetMusicCMD with eternity but got no midi playback.

I'm totally new with C and C++. Help would be great!

Regards

Last edited by Holering; 06-28-2013 at 08:05 PM.
 
Old 06-30-2013, 01:53 AM   #2
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Original Poster
Rep: Reputation: 22
SOLVED
To get hardware midi going in chocolate-doom; edit i_sdlmusic.c to look like this part:
Code:
    // Load the MIDI

    Mix_SetMusicCMD(getenv("MIDI"));
    music = Mix_LoadMUS(filename);
    if (music == NULL)
    {
        // Failed to load

        fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
    }

    // remove file now

//    remove(filename);

//    Z_Free(filename);

    return music;
}
Only problem is a doom.mid remains in the /tmp folder after closing chocolate-doom.

Make sure 128:0 is changed to your proper midi port; also, aplaymidi didn't loop songs on my end but pmidi worked fine.

If you don't have hardware midi; get really good midi playback and replace pmidi -p 128:0 with
Code:
timidity --no-realtime-load --no-trace --realtime-priority=1 --sequencer-ports=1 -A20,100 -EFvlpf=d -EFchorus=n -EFreverb=n -EFns=0 -EFresamp=g -a -N 34+1 -s 44100 --module=4 -q 0.1/0.1
You can change --module=4 (Roland SC-8850) to --module=1 for a roland sc-55 for authenticity sake. This gives really good midi playback and you won't even need a hardware player (rolands or sound blaster audigy not needed!). Pat sets will render correctly and soundfonts too with all effects. I have pat sets over several gigs in size that blow away real hardware modules and huge soundfonts, but sdl_mixer could never use them due to it's built in version of timidity which is really dated and broken. Timidity++ renders them absolutely fantastically and I don't know why sdl_mixer hasn't included it after more than a decade.

Linux users can have proper midi rendition in all sdl_mixer source ports of doom (or any game that uses sdl_mixer for midi) this way. Didn't know sdl_mixer had this function to call an external player and it's very simple! Just make sure Mix_SetMusicCmd is before Mix_LoadMUS.

It would be best to recognizing a variable (something standard like $MIDI; or $CHOCOLATE_DOOM_MIDI) to use whatever external player a user wants (pmidi, timidity++, etc.) instead of hard coding the desired program into i_sdlmusic.c but I'll leave this here for reference. Old timidity built into sdl_mixer should be kept out on all distributions.

All that's left is fixing the sound latency in chocolate-doom (they should add an option to change sound buffers in chocolate-setup).

EDIT:
Changed code to use environment variable $MIDI. This way you can do [code]export MIDI="nameofprogram options" to use whatever program you want, to process midi.

Here's how to do it for Eternity. Make the following section of sourcecode/source/sdl/i_sdlmusic.cpp to look like this:
Code:
   // Try SDL_mixer locally
//   rw    = SDL_RWFromMem(data, size);
   M_WriteFile("/tmp/doom.mid", data, size);
   char *filename = NULL;
   Mix_SetMusicCMD(getenv("MIDI"));
   filename = "/tmp/doom.mid";
   music = Mix_LoadMUS(filename);
//   music = Mix_LoadMUS_RW(rw);
Someone also made a patch to make this work a slightly different way (used SDL_RWwrite to write a temporary midi file instead of M_WriteFile) but the patch fails on my end. Will post patch if it gets fixed.

Last edited by Holering; 07-08-2013 at 08:17 PM.
 
Old 09-22-2013, 10:56 AM   #3
Holering
Member
 
Registered: Feb 2010
Distribution: Slackware - Gentoo - Debian
Posts: 197

Original Poster
Rep: Reputation: 22
Quote:
Originally Posted by Holering View Post
SOLVED
To get hardware midi going in chocolate-doom; edit i_sdlmusic.c to look like this part:
Code:
    // Load the MIDI

    Mix_SetMusicCMD(getenv("MIDI"));
    music = Mix_LoadMUS(filename);
    if (music == NULL)
    {
        // Failed to load

        fprintf(stderr, "Error loading midi: %s\n", Mix_GetError());
    }

    // remove file now

//    remove(filename);

//    Z_Free(filename);

    return music;
}
Only problem is a doom.mid remains in the /tmp folder after closing chocolate-doom.

Make sure 128:0 is changed to your proper midi port; also, aplaymidi didn't loop songs on my end but pmidi worked fine.

If you don't have hardware midi; get really good midi playback and replace pmidi -p 128:0 with
Code:
timidity --no-realtime-load --no-trace --realtime-priority=1 --sequencer-ports=1 -A20,100 -EFvlpf=d -EFchorus=n -EFreverb=n -EFns=0 -EFresamp=g -a -N 34+1 -s 44100 --module=4 -q 0.1/0.1
You can change --module=4 (Roland SC-8850) to --module=1 for a roland sc-55 for authenticity sake. This gives really good midi playback and you won't even need a hardware player (rolands or sound blaster audigy not needed!). Pat sets will render correctly and soundfonts too with all effects. I have pat sets over several gigs in size that blow away real hardware modules and huge soundfonts, but sdl_mixer could never use them due to it's built in version of timidity which is really dated and broken. Timidity++ renders them absolutely fantastically and I don't know why sdl_mixer hasn't included it after more than a decade.

Linux users can have proper midi rendition in all sdl_mixer source ports of doom (or any game that uses sdl_mixer for midi) this way. Didn't know sdl_mixer had this function to call an external player and it's very simple! Just make sure Mix_SetMusicCmd is before Mix_LoadMUS.

It would be best to recognizing a variable (something standard like $MIDI; or $CHOCOLATE_DOOM_MIDI) to use whatever external player a user wants (pmidi, timidity++, etc.) instead of hard coding the desired program into i_sdlmusic.c but I'll leave this here for reference. Old timidity built into sdl_mixer should be kept out on all distributions.

All that's left is fixing the sound latency in chocolate-doom (they should add an option to change sound buffers in chocolate-setup).

EDIT:
Changed code to use environment variable $MIDI. This way you can do
Code:
export MIDI="nameofprogram options"
to use whatever program you want, to process midi.

Here's how to do it for Eternity. Make the following section of sourcecode/source/sdl/i_sdlmusic.cpp to look like this:
Code:
   // Try SDL_mixer locally
//   rw    = SDL_RWFromMem(data, size);
   M_WriteFile("/tmp/doom.mid", data, size);
   char *filename = NULL;
   Mix_SetMusicCMD(getenv("MIDI"));
   filename = "/tmp/doom.mid";
   music = Mix_LoadMUS(filename);
//   music = Mix_LoadMUS_RW(rw);
Someone also made a patch to make this work a slightly different way (used SDL_RWwrite to write a temporary midi file instead of M_WriteFile) but the patch fails on my end. Will post patch if it gets fixed.
Special thanks to Fraggle and Quasar from Doomworld forums; for their help!

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ZDoom 2.2.0 & Eternal Doom IV Raymond C. Glassford Linux - General 0 07-08-2008 09:49 AM
Mandriva & ATI 128 issues illusha Linux - Software 38 09-01-2005 04:43 PM
doom legacy & sound rusty_slacker Linux - Games 0 07-03-2005 06:01 PM
Adding Unsigned Integers of 128 bit bluechicken Programming 1 06-27-2005 02:27 PM
aplaymidi deucedlt Linux - Newbie 0 11-25-2004 06:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration