Author Topic: [XP][VX][VXA] MCI Audio Player  (Read 24230 times)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
[XP][VX][VXA] MCI Audio Player
« on: April 29, 2012, 11:58:53 PM »
MCI Audio Player
Authors: ForeverZer0
Version: 1.3
Type: Custom Audio Module
Key Term: Game Utility

Introduction

This script acts a either a drop-in replacement or enhancement to the built-in Audio module. It contains a plethora of functions that the default player lacks, such as seek, pause, record, fade in/out, and many more. It works by totally bypassing the built-in audio library, and directly accessing Window's "winmm" library using Ruby's Win32API. This library is home to the Media Control Interface, or MCI, which provides functions for manipulating audio and video. This allows for much more control over sound, and the ability for RPG Maker to play additional audio formats, since all that is needed is to distribute the appropriate codecs along with your game in order to use them.

Features

  • Full seek functions, accurate to the millisecond
  • Ability to read file lengths
  • Ability to pause and resume a playing file
  • Functions for transitioning from one volume to another over a given number of frames, to both lower and higher volumes
  • Can create as many mixers as needed, which allows to play multiple sounds simultaneously, which gives the ability to play more than one BGM or BGS at a time
  • Record function to capture input from the user (.wav format only)
  • Ability to set volume to left and right speaker independently
  • Mute functions
  • Can set the speed of playback
  • Ability to set treble and bass (Not all devices support this)
  • Searches RTP files and uses them automatically if file is not local
  • Easy access for additional calls to the Media Control Interface
  • No porting external libraries with your game, all functioning is done within the script and the operating system
  • Can use any audio format you wish, so long as the appropriate codec is installed on the host computer
  • Compatibility with RMXP, RMVX, and RMVXA
  • Memorize/Restore audio on all/some channels

Screenshots

(click to show/hide)

Demo

Demo Link (RMXP)(1.3)

Script

(click to show/hide)

Instructions

Simply set the code in the configuration to what version of RPG Maker you are using.
See script for detailed instructions on scrip calls available to you, and demo for examples of a few.

On some systems, audio can continue to play after the RGSS player has closed. To prevent this, add the following line to the botton of "Main", after all the code:

Code: [Select]
Audio.mci_eval('close all')

Compatibility

  • Not tested on Linux running under Wine. I don't have a VM installed at the present time, so if anyone tests this, let me know.
  • High chance of incompatibility with programs that encrypt audio files
  • Due to vast differences in how the format is handled, some of this player's features do not work with MIDI, most notably volume control, which also effects fading. I have created alternate controls to control MIDI volume, but they can only work with the sacrifice of many other functions, and the volume applies to ALL playing MIDIs, not just the one the volume is applied to. I decided this was not worth it, so I omitted volume control of MIDI by default, but if you are willing to make these sacrifices, there is a setting to enable it. If you your game relies heavily on MIDI, but you still would like to use this script, there are conversion programs available, which I can assist you with if need be.

Credits and Thanks

  • ForeverZer0, for the script

Author's Notes

If you are looking for a good codec pack, I recommend K-Lite Codec Pack. This is a single package that will cover pretty much every standard audio format available, and even a few exotics (especially with the Mega-Pack).

Changing pitch will be different. MCI does not have a function for this, so I am changing the speed as a generic substitute. Changing the speed does change the pitch, but it true sound pitch alters the sampling rate as well, which this player does not. You have a couple alternatives if you absolutely need the pitch change:

  • Edit the files using an external editor and import it
  • Use the default system to play such sounds using the alias names

For more information about using MCI commands, please see the full documentation at MSDN.

Most audio formats should play by default on most systems, but most notably is a lack of an OGG codec that will be used by default.
If your OGG files fail to play, download and install the codec found here.

OpenCodecs (2.53 MB)(x86/x64)
 
« Last Edit: July 05, 2014, 03:39:23 PM by ForeverZer0 »
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Calintz

  • Guardian of Chaos
  • ********
  • Posts: 3803
  • LV: 108
  • Gender: Male
  • A Pixel's Worst Nightmare
    • View Profile
Re: [XP] MCI Audio Player
« Reply #1 on: April 30, 2012, 12:35:03 AM »
well this looks wonderful, +1.

Offline nathmatt

  • Chaos User
  • ******
  • Posts: 1289
  • LV: 114
  • Gender: Male
  • The Add_on King
    • View Profile
    • Nathmatt Productions
Re: [XP] MCI Audio Player
« Reply #2 on: April 30, 2012, 12:43:13 AM »
the music u set to play dose not stop after you close the rgss player
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #3 on: April 30, 2012, 12:48:27 AM »
Hmm, I don't have a problem with that, but either way, there is an easy solution.

At the bottom of Main, add this line:

Code: [Select]
Audio.mci_eval('close all')
I can't reproduce the issue, but I'll add a note to the main post. Thanks for letting me know.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline nathmatt

  • Chaos User
  • ******
  • Posts: 1289
  • LV: 114
  • Gender: Male
  • The Add_on King
    • View Profile
    • Nathmatt Productions
Re: [XP] MCI Audio Player
« Reply #4 on: April 30, 2012, 12:54:40 AM »
thats not working it's stuck playing
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #5 on: April 30, 2012, 01:02:39 AM »
Is 'Game.exe' in your active processes list in the Task Manager?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline nathmatt

  • Chaos User
  • ******
  • Posts: 1289
  • LV: 114
  • Gender: Male
  • The Add_on King
    • View Profile
    • Nathmatt Productions
Re: [XP] MCI Audio Player
« Reply #6 on: April 30, 2012, 01:04:45 AM »
some how firefox was the problem i closed it and the music stopped
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #7 on: April 30, 2012, 01:13:27 AM »
That is very strange.
Has it done it on any following plays?

I only ask cause I have ran this multiple thousands of times, experimenting with all sorts of things, and never had that happen once. If its a problem on machines other than my own, or an issue with other software, I want to get it taken care off.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline nathmatt

  • Chaos User
  • ******
  • Posts: 1289
  • LV: 114
  • Gender: Male
  • The Add_on King
    • View Profile
    • Nathmatt Productions
Re: [XP] MCI Audio Player
« Reply #8 on: April 30, 2012, 01:17:36 AM »
never mind i feel completely retarded my bro had a web based game going that was the music i was hearing not yours :^_^':
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script
(click to show/hide)

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #9 on: April 30, 2012, 01:22:21 AM »
You're killing me, lol  :D

Oh, well, glad to hear all is good.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: [XP] MCI Audio Player
« Reply #10 on: April 30, 2012, 02:33:28 AM »
Very nice job F0. Seriously, this is seriously amazing. I used your built in trebble and bass methods and had a lot of fun with my sub woofer. :3 *levels up*

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #11 on: April 30, 2012, 03:24:09 AM »
Working on VX and VXA support right now. Everything is pretty much the same except for the RTP searching, but for some reason the "RGSSGetPathWithRTP" function in VX's DLL isn't returning the correct path. It returns only "C" instead of the actual RTP path. Maybe its my install or something...

If someone who has VX installed has the time, and is willing to spend 10 seconds running a test for me, please paste the following code in your script editor and tell me what the message window says. It doesn't matter where you paste it.

Code: [Select]
ini = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L')
library = "\0" * 256
ini.call('Game', 'Library', '', library, 256, '.\\Game.ini')
library.delete!("\0")

RGSSGetRTPPath = Win32API.new(library, 'RGSSGetRTPPath', 'L', 'L')
RGSSGetPathWithRTP = Win32API.new(library, 'RGSSGetPathWithRTP', 'L', 'P')

paths = []
[1, 2, 3].each {|id|
  rtp = RGSSGetRTPPath.call(id)
  path = RGSSGetPathWithRTP.call(rtp)
  paths.push(path) if path != ''
}
p paths
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: [XP] MCI Audio Player
« Reply #12 on: April 30, 2012, 03:32:04 AM »
Does the same for me. :\

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] MCI Audio Player
« Reply #13 on: April 30, 2012, 03:36:33 AM »
Damn, time to try and dissect the DLL then. Thanks for checking for me G_G. ;)


EDIT:
Sorry for updating again so fast, but I added a few things:

  • Added RPVX compatibility
  • Added RPVXA compatibility
  • Fixed a typo
  • Made a minimum audio transition of 1, since nothing would happen if you used 0
  • Added a "start position" argument to "play". This was mainly to maintain functionality of VXA's Audio module, but it can be used by all three now.
« Last Edit: April 30, 2012, 05:08:27 AM by ForeverZer0 »
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline G_G

  • Green Gmod Game_Guy AKA G4 AKA hyper-G AKA G-force
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 6585
  • LV: 407
  • Gender: Male
    • View Profile
Re: [XP][VX][VXA] MCI Audio Player
« Reply #14 on: April 30, 2012, 06:03:18 AM »
Awesome. ^3^

Offline LiTTleDRAgo

  • Astral Trancist
  • *****
  • Posts: 841
  • LV: 514
  • Gender: Male
    • View Profile
    • ~
Re: [XP][VX][VXA] MCI Audio Player
« Reply #15 on: May 18, 2012, 12:29:29 PM »
sound with *.ogg extension can't be played

there is no error message, but the sound isn't played

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX][VXA] MCI Audio Player
« Reply #16 on: May 18, 2012, 01:29:33 PM »
Quote
Can use any audio format you wish, so long as the appropriate codec is installed on the host computer
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19930
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: [XP][VX][VXA] MCI Audio Player
« Reply #17 on: May 18, 2012, 01:49:54 PM »
Basically if Media Player can play it, this script can play it. wma should also work.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline LiTTleDRAgo

  • Astral Trancist
  • *****
  • Posts: 841
  • LV: 514
  • Gender: Male
    • View Profile
    • ~
Re: [XP][VX][VXA] MCI Audio Player
« Reply #18 on: May 18, 2012, 02:00:09 PM »
yes, I already installed the codec (K-Lite ver 8.xx standard)
the *.ogg files also can played normally if I remove the script or set MCI_DEFAULT to false

also I noticed another error
Quote
    #---------------------------------------------------------------------------
    # * Use MCI Player play function
    #---------------------------------------------------------------------------
    alias mci_se_play se_play
    def se_play(filename, volume = 100, pitch = 100, start = 0)
      if MCI_DEFAULT
        mixer_play('SE', filename, volume, pitch, false, start)
      elsif RPG_VERSION == 2
        mci_se_play(filename, volume, pitch, start)
      else
        mci_se_play(filename, volume, pitch, start)
      end
    end

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3247
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP][VX][VXA] MCI Audio Player
« Reply #19 on: May 18, 2012, 02:10:50 PM »
Setting MCI_DEFAULT to false simply uses RM's engine, you are just bypassing the script.
Here's an .ogg codec.

http://xiph.org/dshow/downloads/
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.