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 development > Audio solutions

#82978 - Lazy1 - Thu May 11, 2006 5:26 pm

Take a listen to this file:
http://lazyone.drunkencoders.com/files/getthem.ogg

That is a music track from wolfenstein 3D converted from IMF using winamp and an IMF reading plugin.
I'll be honest here, sound programming is not my thing and the only reason my wolf3d port had any sound at all was because wntrmute added it (thx btw).

I cannot run the YM3812 emulator on the arm9 since all of it's resources are spent running the software renderer.
Ideally, the arm9 would tell the arm7 which track to play and decode leaving valuable time free for the renderer.

From what I understand, this is the basic format of an IMF music file:

[Header]
Adlib command count : word

[Adlib command]
Pause length : halfword
Adlib register : byte
Adlib value : byte

[IMF File]
Header
Adlib command
Adlib command
Adlib command
...
...
...
ect

Could be wrong on that though since I haven't played with it for a few days.

I'm just looking for options now while I re-write my wolf3d port which is going well so far:

Done:
Change 320x200 display to 256x192
Remove statusbar
Uses different files now for i/o and timecount code ( ie. win32/io.c )

Working on:
Menu customizations
Re-arranging screens to fit into 256x192

Todo:
Find a way to display 320x200 images on a 256x192 display
Sampled sounds
PC Speaker ( maybe the PSG on the DS could emulate this? )
Adlib music ( why this topic exists )
Adlib sounds ( ^^^ )
New statusbar on sub screen

Any ideas on formats which IMF would convert nicely too and be playable on the arm7 would be VERY appreciated.
Wolf3d needs it's original music!

#83182 - Lazy1 - Sat May 13, 2006 10:16 pm

Hmm, still no ideas for music?

I have decided on a way to get the adlib sounds working (picking up treasure,keys,knife sounds,ect) without the cost of adlib emulation.
I will write a pre-converter which will turn the adlib sound data into raw PCM data which will be loaded from the cf as needed (I'll do some caching to reduce reads though).

Getting sound to work under win32 has been extremely difficult so far (really wish waveOutWrite would block), but with what I have learned the next nds port will have positioned audio and hacked adlib sounds. Maybe music if I/someone can come up with an idea on how to do it.

Another issue is that sound requires a thread, since threading is difficult on the nds, would a timer interrupt do?
I don't know, audio is still very new to me :/

#83217 - TwinD - Sun May 14, 2006 4:19 am

Yeah, that will work, IIRC that's how most of the music libs on the GBA did it, so should work similarly for DS.

#83221 - tepples - Sun May 14, 2006 7:33 am

Most GBA mixer libraries either . The display frequencies on the GBA (280896 cycles per frame) had quite a few "nice" factors that allowed use of the vertical blank interrupt instead of a dedicated sample-counting timer. But on the DS, you will need to use a timer because 560190 cycles doesn't have near as many factors.

Can a DS sampled sound channel fire an interrupt every time it loops? I can't seem to understand everything in GBATEK's description of DS sound. Or would I need to use a separate timer for this and hope that there isn't a glitch?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#83239 - Lazy1 - Sun May 14, 2006 11:08 am

Hmm, still playing with audio win32 side but Im wondering how I'll do it on the nds...
The way the sdl/linux port worked was by copying sound data into a 512 sample audio buffer and writing it to /dev/dsp.
I asked the author why his sound thread didn't sleep and he says its because writing to /dev/dsp will block.
That explains why I had problems with waveOutWrite which just returns immediately, that and buffer sizes/latency are annoying too.

So, the basic idea is to:
Get the audio sample
Convert it to 16 bit stereo
Send buffer to sound hardware for playback
Wait until sound hardware has finished playing

I know how to do steps 1, 2 and maybe 3 - but 4 I have no idea.

#83273 - gladius - Sun May 14, 2006 10:59 pm

There are plenty of sound examples out there for the DS.

The basic idea is you have 16 sound channels available. Each sound channel gets pointed at a section of memory which contains the sound data, then you tell it to start playing. It's pretty simple actually.

Custom mixing is a bit more tricky, in that you have to set up some timers with IRQ callbacks to let you know when to put more data into the sound buffer. You set the timer up to fire at halfway through the buffer play time, then fill in the half of the buffer that just finished with new sound data. You can set the sound channel to loop, which will give the effect of continuous sound playback.

I still think porting the YM3812 emulator to run on the ARM7 would be feasible. You might need a bit of asm to get the speed up, but it would be feasible.

#83281 - Lazy1 - Mon May 15, 2006 12:05 am

Well, after thinking about it maybe software mixing is not needed.
The only reason I was going to use it was because of positioned audio, but that can be done by adjusting the panning or volume.
I don't really need to handle the sound in 4kb pages either, in the old port wntrmute hacked it to load the entire sample at once. That is probably the best way to do things rather than overcomplicate everything.

I'll give the YM3812 emulator another try though, since my adlib sound converter will require it anyway.