• Welcome to Dark Bit Factory & Gravity.
 

[C/C++] Using FreeBasic-version of MiniFmod library

Started by Clyde, November 26, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clyde

Hiya DBF - GVY gang,

I know there's some really cool music routines that have been modified for usuage in FreeBASIC and Pure Basic. What Im hoping for is that these can also be converted to C++, im especially interested in miniFmod with it's syncing abilities; plus when you make an exciting toy to play with could you try and give good user instructions. I've used bassmod + bass but they give me weird hangs and crashes, plus I like the idea of one final executable without the need for a dll ( static libraries ), I'd be really keen and it would help me awesomely on seeing the sfx libraries converted.

Cheers and big respect,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

Rbz' FreeBasic-version of MiniFmod is actually a c-library.
Just tell your linker to use "libminifmod170.a" (and "winmm.lib", too) and add a functions-definition to your source (that's what's in "minifmod170.bi" originally):

extern "C"
{
  int MiniFmod_Init(void*, int);
  void MiniFmod_Play();
  void MiniFmod_Stop();
  void MiniFmod_Free();
  int MiniFmod_GetOrder();
  int MiniFmod_GetRow();
  unsigned int MiniFmod_GetTime();
  unsigned int MiniFmod_GetSynch(int);
  int MiniFmod_GetChannels();
  int MiniFmod_SetVolume(float);
};

Challenge Trophies Won:

Clyde

loading from a list of unsigned char's an everythings working up until I use:


load_minifmod_music( &music_data[0], 103963);

void load_minifmod_music( unsigned char *tune, int length)
{ 
  MiniFmod_Init( tune, length );
}


then it breaks.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

Tried, works.
You're probably doing it wrong.
Post your project and I'll have a look.
Challenge Trophies Won:

Clyde

Most probably dude ;)

Is there another way in code to tell it what additional dependancies to use too?

Here's a surprise & cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

ninogenio

#5
i cant get past the linking process,

in visual studio 2005.


libminifmod170.a(system_file.obj) : fatal error LNK1103: debugging information corrupt; recompile module


i have never seen this before and a bit of google pointed me in turning debug information off but this doesnt work for me any ideas? cheers

@clyde are you remebering to add winmm.lib to your linker dependancies and also try calling mmsystem.h near the top of your main file i get an error when i try to open your project at my end so i cant have a tinker.
Challenge Trophies Won:

Jim

#6
You haven't told it about the libraries.
Open up Project->Properties->Configuration Properties->Linker->Input
and paste this line into Additional Dependencies:

libs\libminifmod170.a winmm.lib libs\libtinyptc_ext.lib


'REEEED SEC-TOR' - Works for me :)

<edit>->nino we're all using VS2008 so that might be the problem.  Also, Clyde never posts his actual code which adds to the fun :P

Jim
Challenge Trophies Won:

Clyde

#7
Something weird is happening then, as main 1-1.cpp is in that zip attachment i have just double checked it, along with the project file, also in the libs folder is all the relevant stuffs.

I have put those libs into the linker->input->additional dependencies. you need to move the cursor right a bit to see them, as it hides them in the box.

I can see this in the add depend in release:
libs\libtinyptc_ext.lib libs\libmmx.lib libs\MSVCRTS.lib libs\libminifmod170.a winmm.lib
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

Quote from: ninogenio on November 26, 2009
i cant get past the linking process,
in visual studio 2005.

libminifmod170.a(system_file.obj) : fatal error LNK1103: debugging information corrupt; recompile module


You have to install this patch to make vc2008-libs work in vc2005.
Challenge Trophies Won:

Clyde

I'll try one more time with uploading the project. dont understand why it's not working for me and working for some. here's a n ew zop.

thanks for your patience and assistance,
Clyde "baffled" Radcliffe.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

#10
At the moment I've only got VC2005 installed, so I can't check if there's anything awkward in your settings.

I'm not sure if this is a problem but in "media/riseup.h" you specified "xm_music_length" as 200255 but "xm_music_data[]" contains 200256 values.

Generally you should allocate bigger amounts of memory on the heap (using 'new' or 'malloc'):

unsigned int *screen_buffer;

screen_buffer= new unsigned int[640*480];


I'd also recommend to put your data into cpp files and just include the declaration:

riseup.cpp:

int xm_music_length=200255;
unsigned char xm_music_data[]= { ...,...,... };


riseup.h:

extern int xm_music_length;
extern unsigned char xm_music_data[];

This way the compiler will build the source only once and won't have to parse it again everytime you build your source. This will save quite some time when including a few megabytes of data.

And this:
ptc_update ( &screen_buffer[0] );
is equivalent to this:
ptc_update ( screen_buffer );
(an array holds the adress of the first element)

Why are you using that "msvcrts.lib" ?
Challenge Trophies Won:

Jim

->Hellfire - that msvclib is something to do with the way the tinyptc lib is built, and the way that even though /nodefaultlib is/must be supplied to make the whole thing work, you can carry on using C runtime stuff as long as you link with that lib.  This is what caused all the trouble we had getting Clyde bootstrapped in his other thread.  The tinyptc lib is nonsensical with its entry point and crt requirements, but it has always been like that and will always need to be like that to be backwards compatible (at least, that's what I had to tell myself).

->Clyde.  I unzipped your first zip archive to my desktop, double clicked the .sln file and, when it didn't build, I added the stuff it needed to the additional dependencies as I described.  Then it worked.  I think you keep adding stuff to the global dependencies, in the Tools->Options menu, this means a lot of stuff will only work for you - these options are not saved in the sln/csproj files.  Ideally you'd never ever change anything in there, except perhaps when adding the DirectX SDK.

Jim
Challenge Trophies Won:

hellfire

Quote from: Jimthat msvclib is something to do with the way the tinyptc lib is built, and the way that even though /nodefaultlib is/must be supplied to make the whole thing work, you can carry on using C runtime stuff as long as you link with that lib.  This is what caused all the trouble we had getting Clyde bootstrapped in his other thread.  The tinyptc lib is nonsensical with its entry point and crt requirements, but it has always been like that and will always need to be like that to be backwards compatible (at least, that's what I had to tell myself).
Sounds a bit strange to me. I'm not familiar with the internals of tinyptc, though.
I also created a new solution for clyde's source because my VC2005 denied to load projects created with VC2008.
However, I can use the default runtimes without problem. Maybe the "troubles" you described are VC2008-specific?
I'm adding my project for completeness.
Challenge Trophies Won:

Clyde

#13
Thanks Hellfire :)

I converted it to express 2008, and as i expected it works. Although im confused as to having riseup.cpp and riseup.h in the project tree, and also in the code it has #include "riseup.h"

I've changed it to be a release and use multithreaded /mt plus added in MSVCRTS.lib ( which I use for smaller exe's ) , not yet changed it from console mode, also noticed a message about it doing away with the w64 thing. When ever i make a new project it arranges the new directory with: project_name\project_name ( each contain release and debug )
I will try doing what you've done in my project. fingers crossed :D

if I comment out the load_minifmod_music call it doesnt crash with this:

Unhandled exception at 0x7c9100e8 in MiniFmod_Example.exe: 0xC0000005: Access violation reading location 0x00000010.


Jim, I havent got anything extra in the projects and solutions hanger, other than the usual suspects.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

ninogenio

clyde are you sure mate that some of the paths in your visual studo set up isnt dependand on the project being in a certain place on your comp as that was the sort of error i got.
Challenge Trophies Won:

Rbz

@Clyde: in your first example, just change:
Linker / Input / Ignore all default libraries = YES
and
C/C++ / Code Generation / Buffer Security Check = NO

And everything will be fine.
Challenge Trophies Won:

Clyde

Thanks mr rbz that works an absolute charm :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Clyde

I have a query, say i want to get hold of sample 6 which is the drum and only if it's note c-5, which is on channel number 2.

With the following, it's almost there, but it picks up on there being that particular drum played at the start of the tune, once it loops it works as per the song. so i dont know if it's the lib itself or the song has a hidden drum sound with no volume that hasnt been cleaned from the final song.

I've found that if it's channel 2, it is in fact 1.

Basically what i'd like to do, is check for the sample on the track_num eg, channel number, with the note and octave eg, C-5


int sample_check_minifmod( int sample_num, int channel_num )
{   
unsigned int scanner;
   
int result,sample_check, note_check;
       
    scanner     =MiniFmod_GetSynch( channel_num );
   
    sample_check =int(scanner >> 8);
    note_check   =int(scanner & 0xff);
       
    if ( int(sample_check)==sample_num)
{
result=1;
}
else
{
        result=0;
}
   
    return result;
}   


Cheers big ears,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

hellfire

Quote from: Clyde Radcliffe on November 30, 2009
Basically what i'd like to do, is check for the sample on the track_num eg, channel number, with the note and octave eg, C-5

Should be something like this:

            int note= MiniFmod_GetSynch(channel) & 0xff;
            if (note!=0)
            {
               static char *noteNames[12]={"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-" };
               note--;
               int octave= note/12;
               char *name= noteNames[note%12];
               printf("%s%d ", name, octave);
            }

Challenge Trophies Won:

Clyde

Thankyou so much mate.

im having a bit of a to do, with incorparating that to returning the result either false or true.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: