Welcome! Log In Create A New Profile

Advanced

Using Modplay and playing sounds at the same time

Posted by Titmouse 
Using Modplay and playing sounds at the same time
March 18, 2011 12:01AM
How do I play a tracker module and sound effects at the same time?

I can play a modules fine, I can play sounds fine too… but not both together

Using the latest libs I just can't seem to get Modplay to work alongside any of the sound commands – apart from the low level AUDIO DMA which does as you would expect, but that’s only good for one sound as far as I can see.
The latest version of ‘gcmodplay’ uses the ‘-laesnd’ libarary, looking into the past I found other code i.e. TowerDefence used ‘-lasnd’ and it plays both sound and mods (i.e. using things like MODPlay_Start & ASND_SetVoice);

The latest version of GCModPlay now depends the ‘-laesnd’ libarary, why? As soon as a call is made to AESND_Init you can kiss goodbye to anything else as this lib looks like it can’t be uninitialized. I’ve found it impossible to close down the ‘-laesnd’ library once started, the problem here is that it stops you using any of the other sound libs.
Re: Using Modplay and playing sounds at the same time
March 18, 2011 06:34PM
Ok - I've found a simple work around for my issue, ( I'm using Version=1.8.6 of the ogc libs)

I downloaded the older lib 'libogc-src-1.8.3' & compiled.
I then replaced the old 'libmodplay.a' with the newly built 'libmodplay.a' + .h file over the top of my current devpro libs (header file was still the same)

My project now complies without the need for aesndlib, "which was nice"

I found the source at: [sourceforge.net], url was found this by looking in the devkitProUpdate.ini installer thingy.
Re: Using Modplay and playing sounds at the same time
March 18, 2011 11:14PM
The correct answer is to just use the equivalent functions from aesndlib to play your sounds and do away with asndlib.
Re: Using Modplay and playing sounds at the same time
March 19, 2011 10:53PM
Odd - Why do you say that? aesndlib depends on asndlib to compile, so I think you are a bit confused architecture wise.

Anyway, yeah tried that as my first step, but I was stopped in my tracks as part of the user interface is hidden!
For example, look at something simple like 'setvoicestop'
void AESND_SetVoiceStop(AESNDPB *pb,bool stop);
It uses a structure AESNDPB, which is of type aesndpb_t and then the trail goes all cold.
Also noticed Aesndlib makes use of callbacks, AESNDVoiceCallback & AESNDAudioCallback, the audio one sticks out as an odd thing.
I'm going to make a wild guess that aesndlib is wrapper around asndlib and you have to register a AESNDAudioCallbackfor for it work, but since there are not examples or docs I'm just guessing and have no idea.
Re: Using Modplay and playing sounds at the same time
March 20, 2011 04:54PM
In the recent libogc versions, I have just used -laesnd in my makefile if I want modplay as well, no need for -lasnd. Some snippets from recent code of mine.

AESND_Init(NULL);
MODPlay_Init(&music);
MODPlay_SetMOD(&music, mod_bg);
MODPlay_Start(&music);
AESND_Pause(0);
channel=AESND_AllocateVoice(NULL);
AESND_SetVoiceVolume(channel,48,48);

(...)

AESND_PlayVoice(channel,VOICE_MONO16,(void*)snd_beep,LEN_SND_BEEP*2,44100,0,0);

I may well be doing something wrong though as there is sometimes distortion at the start of my sound samples. I can work around this by inserting 50 or so milliseconds of silence at the start of the samples but this is obviously not as "correct" as I have claimed so maybe you should stick with what works for you.
Re: Using Modplay and playing sounds at the same time
March 21, 2011 04:30PM
Chris - Thanks for the feedback, looks like something’s up, I just tried compiling the standard example that’s comes with devkit.
"devkitPro\examples\wii\audio\modplay" - gives compile errors without '-lasnd', now that can't be good.

Can you try that, see what it does?

I get ... c:/devkitPro/libogc/lib/wii\libmodplay.a(gcmodplay.o): In function `SndBufStop':
gcmodplay.c:(.text.SndBufStop+0x1c): undefined reference to `ASND_StopVoice'
c:/devkitPro/libogc/lib/wii\libmodplay.a(gcmodplay.o): In function `SndBufStart'
gcmodplay.c:(.text.SndBufStart+0x150): undefined reference to `ASND_SetVoice'
gcmodplay.c:(.text.SndBufStart+0x168): undefined reference to ...


Normally I just let devkitProUpdater-1.5.0.exe update my environment, wonder if it worth me deleting the lot and installing again.
If I get the same behaviour, then something is probably broken outside my control.


'devkitProUpdate.ini' shows...

[libogc]
Version=1.8.6
File=libogc-1.8.6.tar.bz2
Size=2748
[wiiexamples]
Version=20109030
File=wii-examples-20100930.tar.bz2
Size=93
Re: Using Modplay and playing sounds at the same time
March 21, 2011 05:17PM
Fresh env compiles modplay, silly me rollingback just '-lasnd' breaks the modplay example as it now uses ‘-laesnd’

So as I see it, older code using modplay and '-lasnd' will no longer work, thats a bit un·friend·ly.
Think I'll stick to ver libogc-src-1.8.3 of modplay that uses '-lasnd'.

BTW Chris, how did you work out the details like passing NULL to AESND_AllocateVoice, think I'm missing some cool resources somewhere!
Re: Using Modplay and playing sounds at the same time
March 21, 2011 10:52PM
Libaesnd is not a wrapper around libasnd, it's more or less the same thing written differently (and more efficiently). Both are high level API to play audio streams using the audio DSP to process sample data and both are perfectly usable in the last libogc, so if you don't know how to use libaesnd then keep using the older libasnd functions in your code, it's not really a problem, just don't use both at the same time.
Examples are what they are called for, if they don't work as they should , report to devkitpro support forum.
Finally, documentation for libogc is generally libogc code itself so I'd advise to take a look at libaesnd code to see what you are missing.
Re: Using Modplay and playing sounds at the same time
March 22, 2011 11:39AM
Quote
Titmouse
BTW Chris, how did you work out the details like passing NULL to AESND_AllocateVoice, think I'm missing some cool resources somewhere!

I suddenly ran into the same problem you did, when I had always been able to use music and sound at the same time before, and spent a lot of time thinking the problem must be with my code. When I eventually worked out what the problem was, a lot of the functions in aesndlib.h could be worked out by comparing them to the much better documented asndlib.h. I also googled the names of any functions I did not understand to get hints on their usage. Callbacks can often be optional and in this case passing NULL if you don't need them seems to work.

libogc 1.8.4 did break a lot of code in this area and while I personally don't have a problem with this in the name of progress, it would have been nice if this had been pointed out to save a lot of headscratching.
Re: Using Modplay and playing sounds at the same time
March 22, 2011 05:04PM
'ekeeke' - had no idea the source was available until a few days ago when I stumbled across it, thanks the tip.
'Chris' - know how you felt, I have just started using modplay, so I was in complete land of confusion.

Using [downloads.sourceforge.net]
Had a peek at gcmodplay.c, it uses #def's __AESNDLIB_H__ to compile it using that lib.
It still supports either '-lasnd’ or '-laesnd’, you just need to pick one if you wish to
rebuild the libs i.e. #include "aesndlib.h" or include "asndlib.h"
(package 1.8.6 - gcmodplay uses '-laesnd')

Looks like it’s a breeze for gcmodplay to support both flavours of '-lasnd’ & '-laesnd’. I'm happy.



Edited 1 time(s). Last edit at 03/22/2011 05:15PM by Titmouse.
Sorry, only registered users may post in this forum.

Click here to login