#49147 - wiz - Tue Jul 26, 2005 8:35 pm
Dear all once again,
There is a few things I need clearing up to do with sounds.
I have never programmed sound routines before but I have read up enough to understand the basics. You need to fill a buffer, and keep it flowing with data which is output as audio..
Im guessing that you need "channels" in order to play 2 sounds at the same time. Does more than one channel mean there is more than one buffer?
The way Im thinking about it is to have 1 channel that will play "looped" sounds and another that can play standard sounds. Is this the correct way of thinking?
Now music would get a lot more complicated and Im not sure what to ask but I will try anyway:
I have managed to set up the mod player "AFM" and Im amazed that I got a mod playing in my own rom :D !!! This is a library so I have no idea how it works. Would this mod player cause me any issues with using up available sound "channels" or "buffers"? What about it affecting the available DMA's and IRQ's? (that I may someday need to use - thats 2 other areas I barely know anything about)
I don't understand a few key things and I'm scared of conflicts when I try to put the 2 together.
Thanks again, I always appreciate the help and time people give on this forum.
#49359 - headspin - Fri Jul 29, 2005 2:02 am
AFM is quite good, but a little dated and it won't play FX. There are many other MOD players that will play effects also. Check out the link in my sig for some general comparisons. The document is a little dated now as well, alot of the players have been updated, AAS for example is updated quite regularly. Check the author's websites for the latest versions.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#49622 - wiz - Sun Jul 31, 2005 11:26 pm
Hi Headspin,
Thanks for the reference, its a nice site to look through.
However I wish to attempt to code a "sound mixer" myself before resorting to using an existing library and Im trying to understand the concept of playing multiple sounds at once and having a looping sound work with other sounds etc.
Im reading a few sites I found and Im starting to understand in bits.. but it doesnt help the fact that I have no idea which resources AFM use (timers, dma's all that)
I'll keep working at it and ask more when I know more ;)
Thanks for the site :)
#49629 - DekuTree64 - Mon Aug 01, 2005 1:52 am
The basic flow of a MOD-style music player/sound system is to have a mixer with a bunch of channels, and each of those channels can play a sound, with optional pitch/volume/looping. Then the mixer adds them all up and fills the playing buffer, which is fed to the hardware.
Then the music player sits on top of it and tells the channels which sounds to play and at what volume/pitch/etc.
Usually the resources used will be timer 0 to set the hardware channel frequency, and DMA 1 to feed the mixing buffer to it. For stereo sound, you'll also need DMA2.
Some sound systems use a second timer to count samples until it's time to reset the DMA back to the start of the buffer, but usually it's easier/more reliable to time it off VBlank instead.
I wrote some tutorials on sound a while back, so have a look if you haven't seen them before.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#49634 - tepples - Mon Aug 01, 2005 2:42 am
DekuTree64 wrote: |
The basic flow of a MOD-style music player/sound system is to have a mixer with a bunch of channels, and each of those channels can play a sound, with optional pitch/volume/looping. Then the mixer adds them all up and fills the playing buffer, which is fed to the hardware.
Then the music player sits on top of it and tells the channels which sounds to play and at what volume/pitch/etc. |
And a few players have only enough voices available in the mixer for the music and none for other samples, which may be the problem with AFM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#49664 - wiz - Mon Aug 01, 2005 12:34 pm
Hi DekuTree64, your tutorial is the great tutorial I'm currently getting my head around. I'm glad I get to thank you personally for writing it!
Tepples, so do you think it could not be possible to write a sound-fx system while AFM is in use? I messed around a bit but when I tried to play a sound it caused the music (played by the AFM lib) to mess up. I guessed I hit a DMA or Timer that AFM used. but what if it uses all of them? :(
Something to note for anyone working on sounds for the 1st time, if your emulator is not running 100% speed the sound will jump a lot. I spent hours tweaking code to find out the sound skipping was nothing code-related!
#49691 - headspin - Mon Aug 01, 2005 6:53 pm
From afm.h...
Code: |
used resources:
Timers 0 and 1, DMA1 (for sound stream, always active)
DMA3 (occasionaly used in mixer) |
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#49812 - wiz - Tue Aug 02, 2005 7:50 pm
thanks for pointing that out headspin, I should have double checked.
so Im guessing that it means its not possible to add sound fx while AFM is playing? :(
I tried your 'sample 8' DekuTree64, I noticed that the music stops some of the music while a sound fx is played.. not that Im complaining or anything I just want to know how much more work would be involved if I was to try and allow music to play without interruption. As sound is a whole new world to me at the moment I dont have a clue what the possibilities are.
The stuff about DMA's and Timers are not sinking in to me at all, I'll go and read up about them some more if I can.
#58695 - SittingDuck - Tue Oct 25, 2005 1:22 pm
Usually, both the Direct Sound channels are used for stereo sound. (headphones make the GBA sound much better!)