gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS homebrew announcements > libmikmod 3.2.0ds1

#147553 - Stonebone - Sat Dec 22, 2007 11:37 pm

I?ve released a new version of libmikmod for Nintendo DS. Here is what?s new:

* Based on libmikmod 3.2.0-beta2
* Many fixes to the hardware mixer by Andreas Back. It is almost as good as the software mixer now!

Download here: http://code.google.com/p/tetattds/downloads/list
Blog: http://blog.dev-scene.com/flatware/

#147589 - jackman - Mon Dec 24, 2007 1:41 am

Thanks for the new release.

Hardware Mode now works better, but with some .mod's there's a timing issue, I hear channels playing which shouldn't play at this time.

MD Mode:
Code:
md_mode |= DMODE_STEREO | DMODE_SURROUND | DMODE_HQMIXER | DMODE_INTERP;


Disabling Surround, HQMixer and/or Interpolation brought the same result. Possibly incorrect Timer0 settings?

Timer0 Code:
Code:
// call update with correct timing
TIMER0_CR = 0;
irqSet(IRQ_TIMER0, TimerInterrupt);
irqEnable(IRQ_TIMER0);
TIMER0_DATA = TIMER_FREQ_256(md_bpm * 50 / 125);
TIMER0_CR = TIMER_DIV_256 | TIMER_IRQ_REQ | TIMER_ENABLE;


in function TimerInterrupt() :
Code:
void TimerInterrupt()
{
   // player tick
   MikMod_Update();
   
   // the bpm can change in the middle of the song
   TIMER0_DATA = TIMER_FREQ_256(md_bpm * 50 / 125);
}

_________________
Equipment:
Nintendo DS, GBAMP v2, SuperCard SD, SuperKey, Acekard 2i

#147607 - Stonebone - Mon Dec 24, 2007 11:38 am

md_mode is ignored by the hardware mixer. It's only used by the software mixer.

But yes, I also think there is some kind of timing issue. Here is what the MikMod documentation says:
http://mikmod.raphnet.net/doc/libmikmod-3.1.10/docs/mikmod.html
Quote:
The player function is called every module tick to process module playback. The rate at which the player function is called is controlled by the sound driver, and is computed by the following equation:
(bpm*50)/125 calls per second, which means every 125000/(bpm*50) milliseconds. The bpm value is the tempo of the module and can change from its initial value when requested by the module.

It's normally the driver's responsibility to control the timing, but instead my driver calls the player function once in the update function. With the timer code you have there it should work, but it doesn't. There must be some flaw in my logic.

#147632 - tepples - Mon Dec 24, 2007 11:45 pm

If you have an update function that's getting called at a constant CLOCKS_PER_SEC Hz, then you can try something like this:
Code:
tempoCounter += mod->curTempo;
while (counter >= CLOCKS_PER_SEC * 5 / 2) {
  updateTick(mod);
  counter -= CLOCKS_PER_SEC * 5 / 2;
}

On the GBA, DS, or an NTSC console, updating on vblank would give CLOCKS_PER_SEC = 60.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#147663 - Stonebone - Tue Dec 25, 2007 7:07 pm

I'm not sure if it is a good idea. It is important that it gets called at the exact right moment.

#148092 - Rajveer - Wed Jan 02, 2008 3:45 am

This is great, first time trying to get music into my game and it was very easy. Thanks!

Just to make sure though, I shouldn't be worried about this line in the ARM9 makefile should I?

Quote:
# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
# *insists* it has a FPU or VFP, and it won't take no for an answer!


Any side effects in using the ARM9tdmi architecture? Also, what's LD?

#148113 - Stonebone - Wed Jan 02, 2008 1:18 pm

That comment comes from an old version of the project template from devkitARM. I think it was fixed in newer version of devkitARM and/or the template. You don't need to worry about it. LD is the linker.

["devkitPro" is the company. -- MOD]

#148160 - Rajveer - Thu Jan 03, 2008 4:30 am

I've got a bit of a problem. I've created an IT file in Modplug Tracker, which doesn't want to work with libmodmik unless I save it in compatibility mode, where it sounds like crap. I read up on Dark Knight Ez's posts about loading it in Impulse Tracker and saving it as IT2xx, but Impulse Tracker doesn't seem to want to load either the original IT or the version saved with compability mode. How did you load and test IT files, or do you not use Modplug Tracker?

#148182 - Stonebone - Thu Jan 03, 2008 11:37 am

No I did not use MPT since I normally use linux, but the thing is I know very little about mods. It might sound strange porting mikmod to ds and all, but I just needed something to play music in tetattds. Music which somebody else wrote.

But basically, if it doesn't load at all, then it's a problem with mikmod itself, not the ds port. If it sounds crap it might be the ds port.

#148183 - Rajveer - Thu Jan 03, 2008 11:56 am

Nah I'm sure it's not the ds port as Dark Knight ez wrote (on another forum) that it should be fine as long as you can convert to IT2xx within Impulse Tracker itself, so it seems to be a problem between MTP and Impulse Tracker compatibility. I'll stop spamming this thread with my problems now, thanks for the port :)

#150666 - SiW - Sun Feb 10, 2008 12:22 am

Is there any reason why I can't get single samples working? (Update: see below) I haven't tried loading from file as my project isn't setup for FAT, so I had to add a load from memory routine in mikmod/arm9/source/memoryloader.c:

Code:
MIKMODAPI extern SAMPLE* Sample_LoadMemory(const void* buffer, size_t size )
{
   SAMPLE* sample = 0;

   MMEMORYREADER* reader=(MMEMORYREADER*)malloc(sizeof(MMEMORYREADER));
   if (reader) {
      reader->core.Eof  = &MemoryReader_Eof;
      reader->core.Read = &MemoryReader_Read;
      reader->core.Get  = &MemoryReader_Get;
      reader->core.Seek = &MemoryReader_Seek;
      reader->core.Tell = &MemoryReader_Tell;
      reader->buffer = (const UBYTE*)buffer;
      reader->size = size;

      sample = Sample_LoadGeneric((MREADER*)reader);
      free(reader);
   }

   return sample;
}


But Sample_LoadGeneric is returning NULL. I'm passing it what should be a legitimate buffer (a mono .wav passed through bin2o, tried 8 and 16 bit) so I'm not sure what gives.

Anyone know how quickly Martin Korth is processing no$ payments these days so I can actually debug this? :*)

Update - I'm now wondering if there's actually any point to getting this working when I could just use playSound. My thinking was it would be nice to use the mikmod stuff to maintain portability with some of my other projects, but..

#150672 - Dark Knight ez - Sun Feb 10, 2008 12:48 pm

Quote:
Nah I'm sure it's not the ds port as Dark Knight ez wrote (on another forum) that it should be fine as long as you can convert to IT2xx within Impulse Tracker itself, so it seems to be a problem between MTP and Impulse Tracker compatibility. I'll stop spamming this thread with my problems now, thanks for the port :)

Really late response to this. Sorry. Just read it.
Anyway, the newest versions of ModPlug Tracker and such should not be used. Instead, use the older versions which save to a a somewhat older IT format which -can- be converted to the old IT2xx format by Impulse Tracker. (Download here.)
_________________
AmplituDS website

#156941 - M3d10n - Fri May 16, 2008 5:20 pm

Any idea on how much CPU the software mixing uses? I'm trying to convert some .mid files to .it using ModPlug, but it keeps generating files with 16+ channels for some reason (even if the channels are empty in MP) and the hardware playback gets buggy.

--EDIT--
Heh, I found I can limit the number of channels... but even so the hardware mixer still sounds glitchy with the files I'm using. I want to use .IT tracks as background music for my 3D game, so CPU-usage is important.

#156962 - tepples - Fri May 16, 2008 10:40 pm

M3d10n wrote:
I'm trying to convert some .mid files to .it using ModPlug, but it keeps generating files with 16+ channels for some reason (even if the channels are empty in MP) and the hardware playback gets buggy.

You can make MPT delete empty channels. Go into Song Properties and reduce the number of channels. It'll ask you which channels to delete, highlighting a few empty channels if it finds any.

Quote:
I want to use .IT tracks as background music for my 3D game, so CPU-usage is important.

Then compose the tracks directly in .it.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#156968 - M3d10n - Sat May 17, 2008 12:42 am

I got proper sounding .IT tracks now, but the hardware mixer can't reproduce them properly. The software mixer, however, is perfect, even if a little grainy. The tracks are using 5 to 7 channels. I just hope there's CPU left for the game, or it's bye bye 60fps.