Re: Playing Sounds
April 01, 2009 04:02AM
#include mp3player.h --- with the greater than less than around it

And I used Codeblocks on Windows to make the sample I showed

forgot the lib

LIBS := -lfat -lwiiuse -lmad -lbte -logc -lm

don't forget -lmad !



Edited 2 time(s). Last edit at 04/01/2009 04:08AM by scanff.
Re: Playing Sounds
April 01, 2009 04:13AM
Okay, all the above has been fixed, but I'm still getting some linking errors:

c:/devkitPro/libogc/lib/wii\libmad.a(mp3player.o): In function `StreamPlay':
mp3player.c:(.text.StreamPlay+0x44c): undefined reference to `ASND_StopVoice'
mp3player.c:(.text.StreamPlay+0x554): undefined reference to `ASND_SetVoice'
c:/devkitPro/libogc/lib/wii\libmad.a(mp3player.o): In function `MP3Player_Init':
mp3player.c:(.text.MP3Player_Init+0x28): undefined reference to `ASND_Pause'
mp3player.c:(.text.MP3Player_Init+0x30): undefined reference to `ASND_StopVoice'
c:/devkitPro/libogc/lib/wii\libmad.a(mp3player.o): In function `DataTransferCallback':
mp3player.c:(.text.DataTransferCallback+0x19c): undefined reference to `ASND_TestPointer'
mp3player.c:(.text.DataTransferCallback+0x2c8): undefined reference to `ASND_StatusVoice'
mp3player.c:(.text.DataTransferCallback+0x320): undefined reference to `ASND_AddVoice'

Even though I'm including -lmad to the makefile, do I need to include -lasnd as well?
Re: Playing Sounds
April 01, 2009 07:09AM
looks like it.

I'm using the December release of devkit which does not require asnd to be linked if you link lmad. Not sure why maybe someone can comment.
Re: Playing Sounds
April 01, 2009 10:28AM
Okay, I figured out what was causing the above errors. In my game.cpp file, my initialization of sound looked like this:
MP3Player_Init();
if (!MP3Player_IsPlaying()) MP3Player_PlayBuffer(menu_mp3,menu_mp3_size,NULL);
When it should have looked like this:
ASND_Init();
MP3Player_Init();
if (!MP3Player_IsPlaying()) MP3Player_PlayBuffer(menu_mp3,menu_mp3_size,NULL);

Also, I had to include -lasnd to makefile and #include "asndlib.h" to game.cpp (replace " with arrows). Everything compiled and linked perfectly and the MP3 played "almost" perfectly. It loops at the end of the file just fine, but it doesn't play the entire file...cuts off like the last 3-5 seconds of the file. I've read around on different forums, particularly the devkitpro forum, and this appears to be a bug in libogc v1.7.0 mp3player. If anyone has a fix for this, please let me know. I'd like to fix it without having to add a few seconds of silence at the end of the mp3 file.

EDIT: Now I've got all sound working correctly, except for the cutoff at the end of the file. Here's the final code I'm using:

MAKEFILE (put actual mp3 files in data folder):
TARGET	:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES	:=	source source/gfx source/GRRLIB source/libpng source/libpng/pngu
DATA		:=	data  
INCLUDES	:=	
LIBS	:= -lasnd -lpng -lz -lfat -lwiiuse -lmad -lbte -logc -lm
#---------------------------------------------------------------------------------
%.mp3.o	:	%.mp3
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)
GAME.CPP:
#include asndlib.h
#include mp3player.h

#include "menu_mp3.h"

// inside menu_loop()
ASND_Init();
MP3Player_Init();
if (!MP3Player_IsPlaying()) MP3Player_PlayBuffer(menu_mp3,menu_mp3_size,NULL);
I hope that helps you out, g_man.



Edited 2 time(s). Last edit at 04/01/2009 10:54AM by RazorChrist.
Re: Playing Sounds
April 01, 2009 08:33PM
ASND_Init();
MP3Player_Init();

These should not be inside a loop. You just need to call them once.

RazorChrist - What do you mean by Cutoff ?
Re: Playing Sounds
April 02, 2009 09:19AM
Quote
scanff
ASND_Init();
MP3Player_Init();

These should not be inside a loop. You just need to call them once.

RazorChrist - What do you mean by Cutoff ?

I have them in my menu_loop() cus I tried putting them outside of the while() and got memory dumps when I exited the game. Also because I have two separate loops, one for menu and one for game. It's probably not the best way to do it, but it works for me. However, that's just for playing background music. Getting sound fx working on different voices with ASND is a whole different level of entertaining. Can't seem to get the sound to sound right. I think it's the pitch or frequency that's jacking it up, but I spent all last night messing with it and didn't get anywhere.

As for the cutoff, what I meant was, in my background music for the menu....it would play the mp3 just fine, but when it got to the end of the song, it would cut off the last second or two of the mp3 file when it looped to the beginning of the song. I was able to fix it by adding 2 seconds of silence to the end of the mp3.

Also, I have a sound fx that is supposed to be an "engine" sound that is supposed to be a constant sound during the game. However, it's not constant. When it loops to the beginning of the file, it has a split-second silence in between. (kinda sounds like when an audio cd skips) Is there any way to make it a constant sound that doesn't have breaks in it?
Re: Playing Sounds
April 02, 2009 04:41PM
I have a question related to the last message. I'm now able to play MP3's in my game but I want to add sound fx, what's the best way to do that. Because from what I understand there is no way to play mp3 in different channel so I need to pick another format. So which is the best combination:
* mp3+ogg
* mp3+pcm
* ogg+pcm
* ?+?

And most importantly where could I find a code snippet.

Thanks ;)
Re: Playing Sounds
April 02, 2009 05:01PM
The problem is that all decoders uses channel 0. And you can't make them not do that with a simple setting, you would need to do some coding to hook them up to asnd properly.
Re: Playing Sounds
April 02, 2009 09:45PM
Quote
Crayon
I have a question related to the last message. I'm now able to play MP3's in my game but I want to add sound fx, what's the best way to do that. Because from what I understand there is no way to play mp3 in different channel so I need to pick another format. So which is the best combination:
* mp3+ogg
* mp3+pcm
* ogg+pcm
* ?+?

And most importantly where could I find a code snippet.

I've been trying to get sfx working myself. What I'm doing is using the converted mp3 to h files I was using for MP3Player, except when I call the sfx, I use ASND instead.

Example:
ASND_SetVoice(ASND_GetFirstUnusedVoice(), 3, 48000, 0, (char *) turn_mp3, turn_mp3_size, 255, 255, NULL);

The tricky thing about this, at least what I'm having a problem with, is that the sfx doesn't sound anything like it should. But I think the problem might either be in the format (maybe switch to ogg for sfx) or in the frequency. Problem is, I spent the last few days trying different combinations of frequencies and pitches, but can't get it to sound like it does on PC.

If anyone has any insight on how to get it right, much appreciated.
Re: Playing Sounds
April 02, 2009 09:51PM
I think ASND handles PCM sounds and does not decode for you. Any buffers you supply it must be decoded first ogg or mp3.

From my experience the mp3 library clips the end of the sound like you have said. I think this is a madlib problem as using madlib directly will chop off the end of the buffer due to decode/sync errors.

If you're playing small sound effects the best thing would be to use the uncompressed PCM format.
Re: Playing Sounds
April 03, 2009 08:39AM
Also do not forget to check the samplerate of the decoded data, libmad for one does not resample it for you. But I think that asnd can do that.
Re: Playing Sounds
April 17, 2009 09:35AM
Hi everyone.

So.. someone reached a right solution to play a "background music" and some Sfx simultaneously?
Someone could put (in this thread) the complete code of an explanatory examples (like: start a long music in background, then pressing "A" play a short Sfx.. like an Explosion... or a blackbird whistle..)

Sorry for the English...
Ciao Ragazzi.

______________
Leo
Re: Playing Sounds
April 17, 2009 05:32PM
Quote
JonesyLeo
Hi everyone.

So.. someone reached a right solution to play a "background music" and some Sfx simultaneously?
Someone could put (in this thread) the complete code of an explanatory examples (like: start a long music in background, then pressing "A" play a short Sfx.. like an Explosion... or a blackbird whistle..)

Sorry for the English...
Ciao Ragazzi.

______________
Leo

Check out libwiigui, I do it there. I use ogg for the music and PCM for the sound effects.
Re: Playing Sounds
April 18, 2009 04:53PM
Tantric, how do you generate the PCM files? I tried opening them (libwiigui-1.02\source\sounds) with Media Player Classic and it does not work. When I want to open the file in Audacity I need to do an "import raw". So now my question is, how do I save a file in a PCM format that could be read on the Wii with asndlib? Thanks!
Re: Playing Sounds
April 18, 2009 05:14PM
PCM files are just .wav files with the 44 bytes header removed...
check the WAVE format for more informations since you will also need some arguments to pass into ASND functions, such as samplerate, number of channels, bytesize of samples,... those informations can be retrieved from the header of the.wav file you want to use.

Be careful that 16bits samples are stored in little-endian in a wav file: the Wii processor is big endian so 16bits samples must be byteswapped first
Also, in the case of stereo samples, the order must be inverted (compared to what they are in the.wav file) for the Wii audiobuffer: right channel sample comes first, followed by the left channel one...

This shouldn't be hard to make a nice tool to automatize everything ;-)
Re: Playing Sounds
April 18, 2009 07:06PM
There's some good sound editing programs out there that will save your sound file in the correct format from whatever format it's in. Try GoldWave. I use signed 16 bit PCM (raw) big endian stereo.

As ekeeke mentions there's a difference between .wav and .pcm. GoldWave has a save type of "Raw" - that one has the big endian options. Other good audio programs have similar save options.
Re: Playing Sounds
April 19, 2009 08:21PM
Thanks guys for those informations that explain why my previous attempt to play pcm files failed. It ended up playing noise each time.
Re: Playing Sounds
April 21, 2009 12:05PM
I used ogg for bg music and raw data for simple sound effects (iirc) in my game (Piero's Wiicross).
I've used asndlib with previous release of libogc (asndlib wasn't included on libogc yet).
Works like a charm.
Re: Playing Sounds
June 19, 2009 08:24PM
Quote
RazorChrist
I've been trying to get sfx working myself. What I'm doing is using the converted mp3 to h files I was using for MP3Player, except when I call the sfx, I use ASND instead.

Example:
ASND_SetVoice(ASND_GetFirstUnusedVoice(), 3, 48000, 0, (char *) turn_mp3, turn_mp3_size, 255, 255, NULL);

The tricky thing about this, at least what I'm having a problem with, is that the sfx doesn't sound anything like it should. But I think the problem might either be in the format (maybe switch to ogg for sfx) or in the frequency. Problem is, I spent the last few days trying different combinations of frequencies and pitches, but can't get it to sound like it does on PC.

If anyone has any insight on how to get it right, much appreciated.

I know this post is fairly old, so you might have solved this yourself. Anyway, I had the same problem as you, but in the end I found that to get the samples to sound right (with everything else set correctly as far as I know), I had to give the "pitch" parameter as double the actual sample rate of the file. IE, 96000 where you have 48000. I don't know why this is.

Edit: weird, I only have to double if it the samples are 8-bit (not if they're 16)
vvv It is indeed probably my error, but the samples are definitely all mono and I'm using mono.



Edited 1 time(s). Last edit at 06/19/2009 09:22PM by seiken.
Re: Playing Sounds
June 19, 2009 08:58PM
If you have to double it, you are likely screwing up by treating stereo samples as mono samples.
Sorry, only registered users may post in this forum.

Click here to login