Dark Bit Factory &  Gravity
		PROGRAMMING => Freebasic => Topic started by: Clyde on August 25, 2007
		
			
			- 
				I know there's a way of converting a Mod / XM tune into data and for use with UFMod. But is there a way to do this with Bass?
Cheers and all the very best,
Clyde.
			 
			
			- 
				Hey,
as far as I know it relies only on the capability of a player - if it supports in-mem loading  you may easily use the tool bin2bas by rbraz (http://www.rbraz.com/tools.htm (http://www.rbraz.com/tools.htm))
or did I get your question wrong?
Cheers,
  SLiPPY
			 
			
			- 
				Nope I think you got the question right Slippy.
Aaand There's s bug in your sig :P I just tried to squash the ant crawling on my monitor. hehe.
			 
			
			- 
				You could also try using voodooattack's incfile macro: http://www.freebasic.net/forum/viewtopic.php?t=8504
			
 
			
			- 
				Thanks for that dudes, how'd I load that with Bass and not UFMod?
Cheers,
Clyde.
			 
			
			- 
				I couldn't figure out how to get the incfile macro working with the full BASS library, however if you are using the the mod only bassmod.dll, this should work:
#include once "bassmod.bi"
#include once "incfile.bi"
incfile(cuteball, "cuteball.xm", share)
BASSMOD_Init(-1,44100,BASS_MUSIC_LOOP)
BASSMOD_MusicLoad(1, cuteball,0,0,0)
BASSMOD_MusicPlay()
?BASSMOD_ErrorGetCode
sleep
BASSMOD_MusicFree
			 
			
			- 
				Cheers Merick.
			
 
			
			- 
				oops, I made a little mistake. With incfile(handle, file, share), share should be either "true" or "false" depending on whether you want the handle for the incfile'd file to be dimmed as shared or not
			
 
			
			- 
				
Aaand There's s bug in your sig :P I just tried to squash the ant crawling on my monitor. hehe.
me too lol
			 
			
			- 
				Ok cheers Merick. Going to try this abit later.
I was wondering if this can be done with the full bass lib.
			 
			
			- 
				I've been trying to figure out how to use it with the full bass lib, but there's a problem with bass_musicload:
#include once "bass.bi"
#include once "incfile.bi"
incfile(cuteball, "cuteball.xm", true)
BASS_Init(-1,44100,0,0,0)
dim as hmusic music = BASS_MusicLoad(true, cuteball, 0, cuteball_len, BASS_MUSIC_FT2MOD, 44100)
?BASS_ChannelPlay(false, music)
?BASS_ErrorGetCode
sleep
BASS_Free
When I run this, "?BASS_ErrorGetCode" prints out 5, which is the code assigned to a bad handle, which means that BASS_MusicLoad is failing. I think the problem is that I don't really know what you're supposed to put in for the 3rd argument - "offset"
			 
			
			- 
				Here's an example about loading music from memory
'---------------------------------------------------------
'
'   Bass Music Player - Loading from Memory using Bin2Bas
'
'   Code : Rbraz - 2006
'
'--------------------------------------------------------
option explicit
'Includes
#include once "bass.bi"
#include once "windows.bi"
'Include Music
#include "music.bas
 
    Dim Shared module as HMUSIC
  
    'Initialyze Bass system
	if( BASS_GetVersion( ) < MAKELONG(2,2) ) then
        MessageBox( NULL, "Error: BASS version 2.2 or above required", "Bass Music Player", MB_ICONERROR )
		BASS_Free()   
        end -1
	end if
	
	if( not BASS_Init( -1, 44100, 0, 0, 0 ) ) then
        MessageBox( NULL, "Error: BASS_Init failed", "Bass Music Player", MB_ICONERROR )
		BASS_Free()
        end -1
	end if
    'Load module from memory
    module = BASS_MusicLoad( TRUE, _                    '    BOOL mem,
                            @music(0) , _               '    void *file,
                            0, _                        '    DWORD offset,
                            50601, _                    '    DWORD length,
                            BASS_MUSIC_AUTOFREE or _    '    DWORD flags,
                            BASS_MUSIC_RAMPS    or _    '
                            BASS_MUSIC_PRESCAN  or _    '
                            BASS_MUSIC_SURROUND,   _    '
                                0 )                     '    DWORD freq
                                                           
	if( module = 0 ) then
		MessageBox( NULL, "Can't load music "  , "Bass Music Player", MB_ICONERROR )
		BASS_Free()
        end -1
    else
        BASS_ChannelPlay(module, TRUE)
	end if
    
    MessageBox( NULL, "Playing :) ..."  , "Bass Music Player", MB_ICONEXCLAMATION )
    
    BASS_Free()
    
			 
			
			- 
				Ah, looks like the problem isn't with Bass_MusicLoad, but rather it's that BASS_init fails :(
			
 
			
			- 
				Cheers Rbraz :)
Gonna try this tommorrow with Bin2Bas. :D
			 
			
			- 
				rbraz, with "not" being a bitwise operator, in your example, you will need to change this line:
if( not BASS_Init( -1, 44100, 0, 0, 0 ) ) then
to this:
if BASS_Init( -1, 44100, 0, 0, 0 ) = False then
or it will always show the bass_init failure popup
(at least with the latest svn of FB)
which means that the problem with my code really does have something to do with MusicLoad :(
*edit*
oops, I accidentally swapped some arguments, here's the corrected code, with this you can compile the music into the exe without having to convert it with Bin2Bas:
#include once "bass.bi"
#include once "incfile.bi"
incfile(cuteball, "cuteball.xm", true)
if (BASS_Init( -1, 44100, 0, 0, 0 )) = false then
	?"Error: BASS_Init failed"
	?BASS_ErrorGetCode()
	BASS_Free()
end if
	
	
dim as HMUSIC music = BASS_MusicLoad(true, cuteball, 0, 0, BASS_MUSIC_FT2MOD, 44100)
if BASS_ChannelPlay(music, false) = false then
	?"Error: BASS_ChannelPlay failed"
	?BASS_ErrorGetCode
endif
sleep
BASS_Free
			 
			
			- 
				Now that is very useful indeed Merick. Thank you very much.
I will try it out myself :)
			 
			
			- 
				you should thank voodooattack, he's the one who came up with the macro  ;)