Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Can I use .NSF too?

Hello,

I found the audio formats extension script by Guillaume777/Andreas21 which I will include at the bottom of this post. It inherently includes support for .PSF/2/minis, .SPC, and .GYM. I've tested it with .SPC and it works great for me ( once I figured out how to use it right ) but I don't know how to make it work with .NSF. I suspect that if I simply add the in_nsf.dll and some copy/edited code it might play the .NSF file, but how do I tell it to play a particular track?
(If you are not familiar with .NSF, NES music files, all of the songs are included in the one .NSF file, like Zelda.nsf would have all of the tracks from the first Zelda game) I really enjoy 8-bit music and would like a way to use particular tracks from some games.

I have searched the forums for .NSF but it didn't find any matches. I hope you can help! : )


#==============================================================================
# Audio formats extension script
#------------------------------------------------------------------------------
# Guillaume777
# 3.1.1
# 2006/04/28
#==============================================================================
# Version 3.0 :
# -New support for in_bass dll ! You can now play those formats :
# '.XM', '.IT', '.S3M', '.MOD', '.MTM', '.UMX', '.MO3'
# -New support for fading !
# -Improved code, now script is really fast
#
#
# Great improvement of Andreas21 'WimAmp plugins', by Guillaume777 ( 2005 )
# Script allows you to play unusual formats ( .psf, .gym, .spc, it, mod, etc. ) if there is a winamp dll for it
# Script works with multiple format/dlls and doesn't require a 'call script' ( just make it play like any BGM )
# Script won't give error unless there is a music file requiring dll and dll is not there

# Instructions
#
# Make sure Winamp.dll, out_wave.dll and the music dlls are in a folder called 'DLL' in your game folder
# If you use in_bass.dll you need to have bass.dll in your game folder.
# Copy your music files to the BGM folder ( you can't import them via RPG XP )
# If you use .minipsf don't forget to include the psflib !!
# Just use an event to play the music like any regular BGM
# The music files won't play in Sound Test, only in the real game
# If you want loop music files you need to edit dlls in winamp and copy the configure files to the DLL folder
#
#
#
#
#
#
# Credits for Winamp class and Winamp.dll to Andreas21 (C) 2004

module G7_AFES_MOD
BGM_DIRECTORY = 'Audio/BGM/' # directory of BGMs
DLL_DIRECTORY = 'DLL/' #directory of dll

OUT_DLL = 'out_wave.dll' #output dll, default = 'out_wave.dll'
WIN_DLL = 'WinAmp.dll' #winamp dll, default = 'winamp.dll'

BGM_EXT = ['.mp3', '.mid', '.ogg', '.wma', '.wave'] #normal extension
PSF_EXT = ['.psf', '.minipsf', '.psf2', '.minipsf2']
SNES_EXT = ['.spc']
GEN_EXT = ['.gym', '.cym']
MOD_EXT = ['.XM', '.IT', '.S3M', '.MOD', '.MTM', '.UMX', '.MO3']


PSF_DLL = 'in_psf.dll'
SNES_DLL= 'in_snes.dll'
GEN_DLL = 'in_ym.dll'
MOD_DLL = 'in_bass.dll'

end

module RPG
class AudioFile
attr_accessor :file_extension #stores the extension of file
attr_accessor :file_name #stores the real file name
attr_accessor :file_dll #store dll required to play it
end
end

module Audio
@winamp = nil #stores audio player
@winamp_volume = nil #stores volume value
@winamp_playing_bgm = nil #stores music played by winamp
@winamp_bgm_fading = nil #stores if bgm is currently fading or not
@winamp_current_dll = nil # stores current dll used by winamp
@fade_dec = nil #stores how much the volume decrease per frame while fading

def Audio.winamp_bgm_fading
return @winamp_bgm_fading
end

#==============================================================================
# Create winamp system, play music file with winamp, set volume
#==============================================================================
def self.winamp_bgm_play(file_name, volume = 100.0, dll = nil)
if @winamp_current_dll != dll then
@winamp_current_dll = dll
@winamp = WinAmp_Plugin_System.new(dll) #new winamp with new dll
end
volume = volume * 2.55 #convert volume from rmxp to winamp
if volume > 255.0 then volume = 255.0 end
@winamp_playing_bgm = file_name
@winamp.play(file_name)
@winamp_volume = volume
@winamp.setvolume(volume)
end #end def


#==============================================================================
# Initiate the fading, calculates @fade_dec
#==============================================================================
def self.winamp_bgm_fade_init(frames)
if @winamp_playing_bgm != nil then
@fade_dec = @winamp_volume / frames
@winamp_bgm_fading = true
self.winamp_bgm_fade
end
end

#==============================================================================
# Fade volume by @fade_dec
#==============================================================================
def self.winamp_bgm_fade
@winamp_volume += -@fade_dec
@winamp.setvolume(@winamp_volume) #drop in volume for a fade
if @winamp_volume <= 0
self.winamp_bgm_stop
end
end

#==============================================================================
# Stops playing music
#==============================================================================
def self.winamp_bgm_stop
if @winamp_playing_bgm != nil then
@winamp.setvolume(255)
@winamp.stop #stop winamp
end
@winamp_bgm_fading = false
@fade_dec = false
@winamp_volume = nil
@winamp_playing_bgm = nil
end

#==============================================================================
# Uses Win32API and WinAmp.dll to add winamp functions
#==============================================================================
class WinAmp_Plugin_System #This part was done by Andreas21
def initialize(in_dll)
# DLL Pfaht festlegen
dll_directory = G7_AFES_MOD::DLL_DIRECTORY
in_dll = dll_directory + in_dll
out_dll = dll_directory + G7_AFES_MOD::OUT_DLL
winamp_dll = dll_directory + G7_AFES_MOD::WIN_DLL
# 2 API Funktionen die gebraucht werden für das Fenster Handel
@ReadIni = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
@FindWindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'
# Benötigte DLL Funktionen Laden
@Init_Winamp = Win32API.new winamp_dll, 'Init_Winamp', %w(p p l), 'l'
@Quit_Winamp = Win32API.new winamp_dll, 'Quit_Winamp', '', ''
@Winamp_Play = Win32API.new winamp_dll, 'Winamp_Play', 'p', 'l'
@Winamp_Pause = Win32API.new winamp_dll, 'Winamp_Pause', '', ''
@Winamp_Stop = Win32API.new winamp_dll, 'Winamp_Stop', '', 'l'
@Winamp_OnlyExtensions = Win32API.new winamp_dll, 'Winamp_OnlyExtensions', '', 'p'
@Winamp_OutName = Win32API.new winamp_dll, 'Winamp_OutName', '', 'p'
@Winamp_OutConfig = Win32API.new winamp_dll, 'Winamp_OutConfig', 'l', ''
@Winamp_OutAbout = Win32API.new winamp_dll, 'Winamp_OutAbout', 'l', ''
@Winamp_IsPlaying = Win32API.new winamp_dll, 'Winamp_IsPlaying', '', 'l'
@Winamp_InName = Win32API.new winamp_dll, 'Winamp_InName', '', 'p'
@Winamp_Extensions = Win32API.new winamp_dll, 'Winamp_Extensions', '', 'p'
@Winamp_InConfig = Win32API.new winamp_dll, 'Winamp_InConfig', 'l', ''
@Winamp_InAbout = Win32API.new winamp_dll, 'Winamp_InAbout', 'l', ''
@Winamp_GetFileInfo = Win32API.new winamp_dll, 'Winamp_GetFileInfo', %w(p l), 'p'
@Winamp_InfoBox = Win32API.new winamp_dll, 'Winamp_InfoBox', %w(p l), 'l'
@Winamp_GetLength = Win32API.new winamp_dll, 'Winamp_GetLength', '', 'l'
@Winamp_LengthStr = Win32API.new winamp_dll, 'Winamp_LengthStr', 'l', 'p'
@Winamp_GetOutputTime = Win32API.new winamp_dll, 'Winamp_GetOutputTime', '', 'l'
@Winamp_SetVolume = Win32API.new winamp_dll, 'Winamp_SetVolume', 'l', ''
@Winamp_SetPan = Win32API.new winamp_dll, 'Winamp_SetPan', 'l', ''
@Winamp_setoutputtime = Win32API.new winamp_dll, 'winamp_setoutputtime', 'l', ''
@Winamp_IsPaused = Win32API.new winamp_dll, 'Winamp_IsPaused', '', 'l'

# Winamp Plugin Systen Start
@Init_Winamp.call(in_dll, out_dll, handel)
end
# Play the file. Return 0 if no error happend.
def play(file)
return @Winamp_Play.call(file)
end
# First call pause the sound and the second call unpause it.
def pause
@Winamp_Pause.call()
end
# Stop playing.
def stop
return @Winamp_Stop.call()
end
# Quit WinAmp
def quit
@Quit_Winamp.call()
end
# Return all the supported mediafiles.
def onlyextensions
return @Winamp_OnlyExtensions.call()
end
# Out_DLL Infos
def outname
return @Winamp_OutName.call()
end
# Open the config-dialog of the out-plugin.
def outconfig
@Winamp_OutConfig.call(handel)
end
# Open the about-dialog of the out-plugin
def outabout
@Winamp_OutAbout.call(handel)
end
# Return <>0 if a sound is playing, but doesn't work if in-plugin don't need the out-plugin
def isplaying
return @Winamp_IsPlaying.call()
end
# Return the name of the in-plugin.
def inname
return @Winamp_InName.call()
end
# Return the extentions and the type name of all supported mediafiles
def extensions
return @Winamp_Extensions.call()
end
# Open the config-dialog of the in-plugin.
def inconfig
@Winamp_InConfig.call(handel)
end
# Open the about-dialog of the in-plugin.
def inabout
@Winamp_InAbout.call(handel)
end
# return the title of a file and the length in ms.
def getfileinfo(playfile,length_adr)
return @Winamp_GetFileInfo.call(playfile,length_adr)
end
# Open the file-info-dialog of the in-plugin. Not supported of all pluggins (=the will do nothing)
def infobox(playfile)
return @Winamp_InfoBox.call(playfile,handel)
end
# Returns the length of the playing file in ms.
def getlength
return @Winamp_GetLength.call()
end
# Convert the length to a string. Format: "h:mm:ss".
def lengthstr(length)
return @Winamp_LengthStr.call(length)
end
# Return the current playing position.
def getoutputtime
return @Winamp_GetOutputTime.call()
end
# Set the volume (0 to 255)
def setvolume(volume)
@Winamp_SetVolume.call(volume)
end
# Set the pan (left=-127 to 127=right)
def setpan(pan)
@Winamp_SetPan.call(pan)
end
# Set the playing position position. Not supported of all in-plugins. Can be very slow.
def setoutputtime(time)
@Winamp_setoutputtime.call(time)
end
# Return <>0 if paused.
def ispaused
return @Winamp_IsPaused.call()
end
def handel
game_name = 0.chr * 255
zeichen = @ReadIni.call('Game','Title','',game_name,255,'.\\Game.ini')
return @FindWindow.call('RGSS Player',game_name.slice!(0,zeichen))
end #end of init
end #end of class
end #end of module




#==============================================================================
# â–  Game_System
#------------------------------------------------------------------------------
# Changes added to the bgm_play, bgm_stop and bgm_fade functions.
#==============================================================================

class Game_System
#--------------------------------------------------------------------------
# ● Play BGM either normally or by using winamp plugin
#--------------------------------------------------------------------------
def bgm_play(bgm)
if bgm == nil then #if not playing anything
Audio.winamp_bgm_stop
Audio.bgm_stop
return
end


@playing_bgm = bgm
if bgm.file_extension == nil then #stores extension of file
bgm.file_extension = self.get_file_extension(bgm.name)
end
if bgm.file_name == nil then #stores path and name of file
bgm.file_name = G7_AFES_MOD::BGM_DIRECTORY + bgm.name + bgm.file_extension
end

if bgm != nil and bgm.name != ''
if bgm.file_extension == '' or G7_AFES_MOD::BGM_EXT.include?(bgm.file_extension) #normal music file
Audio.winamp_bgm_stop
Audio.bgm_play( bgm.file_name, bgm.volume, bgm.pitch)
else #if file required winamp plugin to play
Audio.winamp_bgm_stop
Audio.bgm_stop
if bgm.file_dll == nil then
bgm.file_dll = self.get_dll(bgm.file_extension) # get dll required to play file
end
Audio.winamp_bgm_play(bgm.file_name, bgm.volume, bgm.file_dll) #Play the new audio format
end
else #if playing nothing
Audio.winamp_bgm_stop
Audio.bgm_stop
end
Graphics.frame_reset
end

def bgm_fade(time)
@playing_bgm = nil
Audio.bgm_fade(time * 1000)
Audio.winamp_bgm_fade_init(time * 41.0) #line added
end


def bgm_stop
Audio.bgm_stop
Audio.winamp_bgm_stop #line added
end

#--------------------------------------------------------------------------
# ● Update the sound level if fading
#--------------------------------------------------------------------------
alias g7_afes_game_system_update update
def update
g7_afes_game_system_update #update normally
if Audio.winamp_bgm_fading
Audio.winamp_bgm_fade #lower volume for the frame
end
end

#--------------------------------------------------------------------------
# ● Returns correct extension of file
#--------------------------------------------------------------------------
def get_file_extension(bgm_name)
file_name= G7_AFES_MOD::BGM_DIRECTORY + bgm_name
extensions = G7_AFES_MOD::BGM_EXT + G7_AFES_MOD::PSF_EXT + G7_AFES_MOD::SNES_EXT + G7_AFES_MOD::GEN_EXT + G7_AFES_MOD::MOD_EXT
file_extension = '' #nil by default

for extension in extensions
if FileTest.exist?(file_name + extension) #if it found extension
file_extension = extension # remember extension
break
end
end
return file_extension
end

#--------------------------------------------------------------------------
# ● Returns dll required to play file with winamp system
#--------------------------------------------------------------------------
def get_dll(file_extension)
if G7_AFES_MOD::PSF_EXT.include?(file_extension)
dll = G7_AFES_MOD::PSF_DLL
elsif G7_AFES_MOD::MOD_EXT.include?(file_extension)
dll = G7_AFES_MOD::MOD_DLL
elsif G7_AFES_MOD::SNES_EXT.include?(file_extension)
dll = G7_AFES_MOD::SNES_DLL
elsif G7_AFES_MOD::GEN_EXT.include?(file_extension)
dll = G7_AFES_MOD::GEN_DLL
else
dll = nil
end

return dll
end
end #end class
 
Landarma;145483":13j9xd0y said:
It would be possible, but unless you split each tracks to files(or compose your own .nsf), I doubt you can use it with current script..
Would you know of any scripts for playing .NSF? I will look into splitting/working with .NSF later tonight.
 
The big problem with the .NSF format is that they're a whole library of files. You've got the driver and all the tracks in one file. You'd need a bit more scripting to get those to work, I'd imagine, to select which channel you'd want to use. It wouldn't be nearly as easy to use as the .PSF script which just lets you select tracks as if they were .MP3 or whatever.

I'm sure it could be done, but I think it would be extremely difficult. The main problems would be figuring out just how to get the files to be read, then which channels to run.
 
Sol_Fury;145522":202mnikd said:
The big problem with the .NSF format is that they're a whole library of files. You've got the driver and all the tracks in one file. You'd need a bit more scripting to get those to work, I'd imagine, to select which channel you'd want to use. It wouldn't be nearly as easy to use as the .PSF script which just lets you select tracks as if they were .MP3 or whatever.

I'm sure it could be done, but I think it would be extremely difficult. The main problems would be figuring out just how to get the files to be read, then which channels to run.
Oh http://divine.yorisou.net/sprites/FF6/Cyan/upsetl.gif[/img] I see. I assumed that someone must have done it at one point or another. Thank you for the information; I didn't realize that .NSF files also contained all of that extra data, but taking another look at my NSF player (NotSo Fatso plugin for winamp) it makes sense.

I suppose the other file formats will have to do. Thanks again!


Landarma;145531":202mnikd said:
However, there are single-track .nsf files, too. Most of them are not extracted from actual game, but composed and compiled. See this site:
http://mck2ch.hp.infoseek.co.jp/

Oh! Thank you very much. http://divine.yorisou.net/sprites/Kirby ... rbythx.php[/img] I will definitely check that out.
 
Sol_Fury;145522 said:
The big problem with the .NSF format is that they're a whole library of files. You've got the driver and all the tracks in one file. You'd need a bit more scripting to get those to work, I'd imagine, to select which channel you'd want to use. It wouldn't be nearly as easy to use as the .PSF script which just lets you select tracks as if they were .MP3 or whatever.

I'm sure it could be done, but I think it would be extremely difficult. The main problems would be figuring out just how to get the files to be read, then which channels to run.

The same as .HES and .GBS. Since they can contain multiple tracks in single file, it's more difficult to use.
 
Well, if it generates an ini file in your Winamp plugins dir, copy that to where your plugin is (in your project) - sometimes it allows you to set preferences for your particular plugin. I'm not sure if it'll help or not, but it's worth a try.
 
Dirtie;145697 said:
Well, if it generates an ini file in your Winamp plugins dir, copy that to where your plugin is (in your project) - sometimes it allows you to set preferences for your particular plugin. I'm not sure if it'll help or not, but it's worth a try.
Though it helps to set playing time or looping, it never helps to play multi-track .nsf(or .hes, .gbs). To play certain track in such file, you have to set not only file name, but also track number, but currently, there are no such script.
 
Hmm, maybe if there was some sort of way to issue a "next track" command to the Winamp dll... is there a list of functions for this particular dll somewhere, or are they all in the script already?

I just realized why I recognized your name by the way Sky Render - you wrote that Harvest Moon: BTN FAQ (and some others) ;)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top