Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on November 26, 2009

Title: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on November 26, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: hellfire on November 26, 2009
Rbz' FreeBasic-version of MiniFmod (http://www.dbfinteractive.com/forum/index.php/topic,3832.0.html) 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);
};

Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 26, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: hellfire on November 26, 2009
Tried, works.
You're probably doing it wrong.
Post your project and I'll have a look.
Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 26, 2009
Most probably dude ;)

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

Here's a surprise & cheers,
Clyde.
Title: Re: Modified Libs Conversion Request
Post by: 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


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.
Title: Re: Modified Libs Conversion Request
Post by: Jim on November 27, 2009
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
Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 27, 2009
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
Title: Re: Modified Libs Conversion Request
Post by: hellfire on November 27, 2009
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 (https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=18623) to make vc2008-libs work in vc2005.
Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 27, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: hellfire on November 27, 2009
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" ?
Title: Re: Modified Libs Conversion Request
Post by: Jim on November 27, 2009
->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
Title: Re: Modified Libs Conversion Request
Post by: hellfire on November 27, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 27, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: ninogenio on November 27, 2009
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.
Title: Re: Modified Libs Conversion Request
Post by: Rbz on November 28, 2009
@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.
Title: Re: Modified Libs Conversion Request
Post by: Clyde on November 28, 2009
Thanks mr rbz that works an absolute charm :)
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on November 30, 2009
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.
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: hellfire on December 01, 2009
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);
            }

Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on December 08, 2009
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.
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Jim on December 09, 2009
Hellfire shows how to work out which note at which octave is playing.  You already know how to work out which sample is playing.
What else do you need?  Alternatively, what do you mean you're having a problem incorporating it?

Jim
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: hellfire on December 09, 2009
So you want to compare a numeric xm-note with an textual representation as shown in a tracker ?

Try something like this:

int stringToXmNote(char *note)
{
   char map[7]={
      9, // A- A#
     11, // B-
      0, // C- C#
      2, // D- D#
      4, // E-
      5, // F- F#
      7  // G- G#
   };

   // map first character from [C,D,E,F,G,A,B] to [0,2,4,5,7,9,11]
   int n= map[note[0]-'A'];
   // half note: second character is '#'
   if (note[1]=='#') n++;
   // extract octave
   int o= note[2] - '0';
   // convert to note-number
   return (o*12)+n+1;
}


Use like this:

int xmnote= MiniFmod_GetSynch(channel) & 0xff;
if (xmnote == stringToXmNote("D#4"))
{
  ...
}


Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on December 09, 2009
Thanks alot dude.
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on September 30, 2010
I've got back to this, it looks brilliant the snippet above Dude, but it's not working with the stringToXMNote.


int xmnote= MiniFmod_GetSynch(5) & 0xff;
if (xmnote == stringToXmNote("D-6"))
{
draw_box();
}


Huge thanks,
Clyde.
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: hellfire on September 30, 2010
Quoteit looks brilliant the snippet above Dude, but it's not working
Yes, Dude, that's quite possible!
That's either because my code is crap or you're using it wrong, Dude.
Can you be more specific, Dude, or even post an example?
;D
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on September 30, 2010
Dude, it's just using your code above, and the bit I posted above dude.

you could try it out with the riseup module, if you wanted Hellfire dude.

Cheers Dude!
Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: hellfire on October 03, 2010
Quote from: Clyde on September 30, 2010you could try it out with the riseup module
That's a 4-channel module, but you're reading the note from channel 5:
Quoteint xmnote= MiniFmod_GetSynch(5) & 0xff;

Try

int xmnote= MiniFmod_GetSynch(3) & 0xff;
if (xmnote == stringToXmNote("A-4")) ...

Title: Re: [C/C++] Using FreeBasic-version of MiniFmod library
Post by: Clyde on October 03, 2010
Ok thanks mate, I need to remember it's -1 for the channel / track.