Not sure how to use sfxmgr.h, and libtremor troubles

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Not sure how to use sfxmgr.h, and libtremor troubles

Post by Silent Marauder »

Sorry for starting another topic, but I've searched and I can't find the answer to a new set of problems I'm having. I've tried to follow the hello-ogg example and I wrote a quick little test program that plays an Ogg Vorbis file, but it keeps crashing at the same point in the music (about 20 seconds in). It's an odd crash in that instead of locking up the system, it drops me back to DCHakker instead.

Also, the music runs slower than normal during the first few seconds while the DC is loading the file -- can the music be preloaded to avoid this?

Code: Select all

snd_stream_init();
sndoggvorbis_init();
sndoggvorbis_start("/cd/music.ogg", 0);

while(1)
{
     //display some text on the screen here
}

sndoggvorbis_stop();
sndoggvorbis_shutdown();
snd_stream_shutdown();
Are there any limitations on how the .ogg must be encoded? Any particular bitrates or settings that libtremor doesn't like? Or would a sched_yield() - if it has a KOS equivalent - in the while loop do the trick?

I'm also having problems getting sound effects to work. I can't even get my test program for that to compile, because gcc keeps throwing "'sfx_hnd_t' undeclared" and other such errors, even when I try #include <dc/sound/sfxmgr.h>. I probably have to add something to my makefile, I would guess.

The sfxmgr.h comments don't really explain too much about how the functions work. I'm assuming multiple sound effects can play simultaneously (up to some limit). I also wonder how the volume and panning parameters for snd_sfx_play() work -- what the maximum and minimum values are. I'm guessing volume would go from 0 to 255. I'm not sure about panning, though.

Please bear with me; I haven't worked with sound in my programming before, even on the PC. Thank you for your time!
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Not sure how to use sfxmgr.h, and libtremor troubles

Post by OneThirty8 »

Silent Marauder wrote: I'm also having problems getting sound effects to work. I can't even get my test program for that to compile, because gcc keeps throwing "'sfx_hnd_t' undeclared" and other such errors, even when I try #include <dc/sound/sfxmgr.h>. I probably have to add something to my makefile, I would guess.

The sfxmgr.h comments don't really explain too much about how the functions work. I'm assuming multiple sound effects can play simultaneously (up to some limit). I also wonder how the volume and panning parameters for snd_sfx_play() work -- what the maximum and minimum values are. I'm guessing volume would go from 0 to 255. I'm not sure about panning, though.

Please bear with me; I haven't worked with sound in my programming before, even on the PC. Thank you for your time!
I'm not sure what's wrong with your Ogg playing. My guess is you used a program to create the file that this particular lib doesn't like. There are two Ogg Vorbis libraries. Tremor is an integer decoder, I believe, which should be faster, but you might try the other (change -ltremor to -loggvorbisplay in your makefile) and see if it likes the file any better. Another thing would be to simply try encoding the file again with a different program. I've used audacity to export stuff as ogg, and it works just fine.

Your sound effects code is wrong, it appears from looking at what you wrote. You said "sfx_hnd_t," but it should be "sfxhnd_t" instead. That might get that part to work.

Volume goes from 0 to 255 as you said. Panning also goes from 0 to 255, with 0 being full left, 128 centered, and 255 full right (or I might have that backwards). You have 64 channels total for sound, two of which are typically reserved for streaming (chans 0 and 1), so you could have up to 62 mono sound effects or 31 stereo sound effects going at once, assuming they're all small enough to fit into the sound memory (only 2MB there -- if you have lots of sounds, convert them to ADPCM with wav2adpcm and they'll be 1/4 the original size).
Silent Marauder
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 24
Joined: Wed Jul 21, 2004 8:06 pm
Has thanked: 0
Been thanked: 0

Post by Silent Marauder »

Thanks! I can't believe I missed that typo. It compiles now, at least.

I'll try using audacity to encode the .ogg and try it again.

EDIT: Now I'm having makefile trouble as well! I didn't change the makefile, not a single character, but now Make is acting strange. Exiting and restarting cygwin doesn't fix it.

Sometimes I type 'make' and it won't produce a 1ST_READ.bin. It happened five minutes ago, so I did my usual fix of typing 'make clean'

Now every time I compile, Make insists on recompiling files that haven't changed. Why this suddenly happened when I didn't touch the Makefile is beyond me.
User avatar
JS Lemming
Insane DCEmu
Insane DCEmu
Posts: 202
Joined: Mon Apr 04, 2005 8:08 am
Location: C:\CON\CON
Has thanked: 0
Been thanked: 0
Contact:

Post by JS Lemming »

Yeah, that makefile behavior you speak of happened to me too. It baffles my mind. So now I use 'make clean' everytime and just wait it out. It sucks, but it's predictable at least.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

There are probably some bugs in the makefile somewhere - the ones that come with KOS aren't particularly good. The makefile I use is pretty much bulletproof by now - it even has automatic dependency checking, so if you change a header file it'll automatically recompile everything that refers to it.

The real neat part is that a makefile to build all C and C++ files in the current directory looks something like:

Code: Select all

TARGET=myprogram
LIBS=tremor parallax kosutils jpeg png z
ROMDISK=romdisk

include Makefile.rules
It's never been tested on Cygwin, only Linux, so I don't know if it'd work. I could post a copy of it if you like.
User avatar
JS Lemming
Insane DCEmu
Insane DCEmu
Posts: 202
Joined: Mon Apr 04, 2005 8:08 am
Location: C:\CON\CON
Has thanked: 0
Been thanked: 0
Contact:

Post by JS Lemming »

I would!
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

Here ya go.

Basically, you just have to modify Makefile to fit. All the rules are tucked away in Makefile.rules, and you shouldn't have to edit those at all.

For example, if you want to compile a program called "example", linked to zlib and libpng, with "NDEBUG" defined, "SYSTEM" defined as "dreamcast", a romdisk compiled from the data in the "romdisk" subdirectory, CD data contained in the "cdroot" subdirectory, and ISO redirection for dc-load/ip turned on, your makefile would look like this:

Code: Select all

TARGET=example
LIBS=png z
DEFINES=NDEBUG SYSTEM=dreamcast
ROMDISK=romdisk
REDIRECTION=yes
ISO_DATA=cdroot
-include Makefile.rules
The idea behind the ISO_DATA directory is that it contains all the files (except for the binary) that will end up on a CD when you burn it. It also gets included with a binary distribution ("make dist" will make one for you). I was going to add some image creation and burning targets, but never got around to it.

The only extra program you need is Marcus Comstedt's scramble program, which should be compiled as "dcscramble" and placed somewhere in your path.
User avatar
JS Lemming
Insane DCEmu
Insane DCEmu
Posts: 202
Joined: Mon Apr 04, 2005 8:08 am
Location: C:\CON\CON
Has thanked: 0
Been thanked: 0
Contact:

Post by JS Lemming »

Hey thanks! Finally, a half-way decent makefile setup.

I would try to get it going right now but I pretty much have to wipe out my computer. My sister unknowingly download about 50 billion virus's and trojans and such that my computer is barely functioning. But I think a wipe-out will be a good thing. A chance to reorganize.

Once I get my life reinstalled... I'll be back. Thanks again.
Post Reply