Playing NSF Files

BlitzMax Forums/BlitzMax Programming/Playing NSF Files

QuickSilva(Posted 2008) [#1]
I would like to be able to play Nintendo .NSF files in BMax (NES tunes). Would it be possible? Can anyone give me any helpful pointers?

I know that I could simply convert them into another format but I`m after the small file sizes that this format offers.

Thanks for any advice.

Jason.


REDi(Posted 2008) [#2]
http://www.fly.net/~ant/libs/audio.html#Game_Music_Emu

I might see if I can add it to MaxMod2 at some point. (dont hold your breath though)


REDi(Posted 2008) [#3]
hmm, looking at the source it'll be very easy to implement into maxmod2 ;)


Brucey(Posted 2008) [#4]
It's LGPL... if you integrate the source, you'll either have to create a dll or apps will need to be GPL'd.


REDi(Posted 2008) [#5]
I *think* any derived librarys have to be available to download in source and contain the LGPL/GPL license, and users have to make the source available to the customer (link to maxmod download).

I'll clarify this with the author if can find his email address.


Brucey(Posted 2008) [#6]
No.. that's not how LGPL works... if MaxMod (assuming you've compiled in the LGPL source) is a static library, when you link it into your app, your must release the source to your app.
If MaxMod was a shared library (.so / .dll / .dylib) then that caveat (of having to provide source to your app) wouldn't apply - which is the point of the "L" in LGPL.


Brucey(Posted 2008) [#7]
It's a groovy little library.. I've got it playing an nsf tune on Mac, via BaH.BASS.
Very cool indeed :-)


REDi(Posted 2008) [#8]
Yeah, I've got it going as well, it sounds pretty good :)


6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:

- snip -

d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.




dunno, I'll have a talk to a legal bloke I know, when I bump into him again.


Brucey(Posted 2008) [#9]
That's fine... if you are dynamically linking the code, everything rocks.

There have been numerous posts here in the past that discuss this.

Unless the license with the library specifically exempts static linking (like wxWidgets does, for example), then by statically linking, you must also include the source to the app you are statically linking into.


Brucey(Posted 2008) [#10]
Static linking counts as a "derived work", which turns such code into GPL... as if by magic :-p


REDi(Posted 2008) [#11]

6. As an exception to the Sections above, you may also combine or
link
a "work that uses the Library"...



clutching at straws here ;)


Brucey(Posted 2008) [#12]
Here's an example of an exemption for FLTK - an LGPL'd library :

3. Static linking of applications and widgets to the FLTK library does not constitute a derivative work and does not require the author to provide source code for the application or widget, use the shared FLTK libraries, or link their applications or widgets against a user-supplied version of FLTK.

Full license here : http://www.fltk.org/COPYING.php


REDi(Posted 2008) [#13]
maxmod will be the "derived work" and anyone using will be "work that uses the Library" and get away with supplying a link to the library...? Its all to poxy complicated for me... :) these licenses send you round in circles.


Brucey(Posted 2008) [#14]
Basically, if something says LGPL, and you don't see any exemptions, it's dynamic linking only... or you GPL your stuff.


Anyhoo, I've managed (after bloody ages of hacking a makefile together) a Mac .dylib, which is running great.
I expect Windows to be an utter pain in the arse to get working this way... but if it isn't such a bother, I might knock out a proper module for it.
The basics are working well :
Local music:TMusicEmu = TMusicEmu.Create("ff3.nsf", 44100) ' load final fantasy 3 music :-)

If Not music Then
	Print "Error..."
	End
End If

Print "Tracks = " + music.TrackCount()

music.StartTrack(2)

...
... some BASS init/play stuff
...

Function callback:Int(handle:TBassStream, buffer:Byte Ptr, length:Int, user:Object)
	TMusicEmu(user).Play(length / 2, buffer)
	Return length
End Function



Brucey(Posted 2008) [#15]
maxmod will be the "derived work" and anyone using will be "work that uses the Library" and get away with supplying a link to the library...?

*only* if maxmod is a dll/shared library.
As soon as you statically link anything, it becomes a "derived work". Doesn't matter if you make a library yourself which statically links (or compiles in) the LGPL'd library, which is then itself statically linked in. At each point of a static linking, it becomes LGPL... and so on... and so on.

That's why they call GPL, viral :-)


REDi(Posted 2008) [#16]
last chance...

6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice
, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.



I'll wait and see what the author thinks.

there is more holes in this license than my lucky pair of pants ( which actually only has one, rather large hole in the front :P ).


Hotcakes(Posted 2008) [#17]
Where do your feet go?


QuickSilva(Posted 2008) [#18]
Thanks for looking into this, please let me know what the outcome is.

Ideally I would like to be able to jump to different patterns\positions in the files (such as subsongs, as one file can contain many), loop them, vary the volume\speed etc... Would this be possible to achieve relatively easily?

Thanks for your time with this, it is very much appreciated :)

Jason.


Brucey(Posted 2008) [#19]
Here's something I just knocked together (win32), if you'd like to try it...

bah_gme_example.rar (308kb)
You can drop me marks on presentation :-p

This example uses BASS for audio playback, but it should be fairly easy to get it playing through most audio libs... probably.

<edit>Oh, and of course, this *is* LGPL friendly, so in theory you can ship it with your closed-source work</edit> ;-)


... donations of encouragement always welcome... :-)


Ginger Tea(Posted 2008) [#20]
there is more holes in this license than my lucky pair of pants ( which actually only has one, rather large hole in the front :P ).


Where do your feet go?


my thoughts exactly and how do you get in considering the top is a hole too :p

...

but on lgpl/gpl
they should make it PERFECTLY CLEAR when you can link a file that is NOT going to be compiled into the exe that you have to gpl it or not, no quasi legal speak

include thisgpl.h = gpl code
link to this .dll not gpl code
that kinda thing, cos although your program needs this file in order to work, its not modifing the dll its just using it and if said dll gets deleted the program ceases to work (or atleast breaks in parts)
whereas if it is included code it will be a part of the exe


popcade(Posted 2008) [#21]
How about making it a seperate module like

maxmod.nsf

and not to include it by default, those who want to use NSF format will follw the rule.

BTW..... well, most NSF file has copyright issues if they're from roms.


QuickSilva(Posted 2008) [#22]
That`s not a problem as they are custom made .NSF files.

Thanks Brucey, I`ll give it a go.

Jason.


Brucey(Posted 2008) [#23]
There's an issue with that code, because of the BASS callback into max-code - it's using the default GC, which doesn't handle external callbacks very well - can cause object errors, and other nasty things.

However, I've rewritten it to use a kind of "plug-in" modular system, which avoids this issue by running the callbacks in C++ (but it's hidden from the user).
This should also make it easy to plug in other audio modules, like OpenAL - just needs a driver module, which you import.

Still messing around with it... :-p


QuickSilva(Posted 2008) [#24]
Just tried it and it works great! Would it be easy to get the other formats working too like .SPC (SNES), AY (ZX Spectrum) and so on?

Jason.


Brucey(Posted 2008) [#25]
Yeah, I tried loading an spc and it worked fine.


REDi(Posted 2008) [#26]
Where do your feet go?

I dont have any... no, seriously... :P

my thoughts exactly and how do you get in considering the top is a hole too :p

ah, ya got me, ok I've got four holes in my imaginary lucky pants :)

How about making it a seperate module

yeah, it would be, all formats are in maxmod.

However, I've rewritten it to use a kind of "plug-in" modular system, which avoids this issue by running the callbacks in C++ (but it's hidden from the user).
This should also make it easy to plug in other audio modules, like OpenAL - just needs a driver module, which you import.

This is how maxmod2 handles things, modules for audiodrivers (directsound and openal) and modules for audio formats (ogg,mp3,flac etc and my own mod/xm library) all done in c++, bolted together from blitzmax and handled with the standard TChannel functions.

BTW do you mind if I nab your libs when you're finished? ;)


Damien Sturdy(Posted 2008) [#27]
Dayumn, I just became redundant. ;-) haha


Hotcakes(Posted 2008) [#28]
I dont have any... no, seriously... :P

ah, ya got me, ok I've got four holes in my imaginary lucky pants :)

Now I'm -really- confused : why would you imagine a pair of pants with more holes than you need? =]