Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Digital SOund

Reply to topic
Author Message
LSJMDM
  • Guest
Reply with quote
Digital SOund
Post Posted: Sun Sep 19, 1999 6:47 pm
Hello :)

I´m now working hard on the new version of Calypso. I want to improve the sound quality, by using the digital
rather that Adlib. The question is:

¿How to produce a pure sinusoidal frequency whit the functions of the Allegro library?

I don´t know what a sample is. And i´ve tried to call functions like allocate_vocie(), set_voice_volumen() but
I can´t heard any sound :(

Could someboy help me.

Saludos,
Jose Manuel Delgado
 
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Calypso. Game Gear?
Post Posted: Sun Sep 19, 1999 9:42 pm
Sorry to ask here, but when do you expect to get to Game Gear emulation?
  View user's profile Send private message Visit poster's website
LSJMDM
  • Guest
Reply with quote
News about Calypso
Post Posted: Mon Sep 20, 1999 10:55 am
Calypso in fact can emulate a Game Gear. If you try to load a Game Gear ROM in Calypso Build 008
you will play the game, but in a special full screen mode (biggamegear) and with the colors corrupted ( this is the
main difference between SMS & GG, the pallette).

But the new version in developtment, 009, can run correctly Game Gear games almos perfectly, both emulator
and debbuger. It is still in test mode, because in Game Gear mode the savegame format is diferrent and a few
things more. The idea was to improve the sound and other important surprise in the build 009, but if you like
i can release in two or three days a new Calypso version with full Game Gear support (with full I refer both emulator
and debugger).

I think that the debugger is very incomplete. If you want a command that it is not present, tell to the forumt so
i can implement it.


Saludos,
Jose Manuel Delgado
 
Nyef
  • Guest
Reply with quote
Post Posted: Mon Sep 20, 1999 1:58 pm
Quote
> I´m now working hard on the new version of Calypso. I want to improve the sound quality, by using the digital
> rather that Adlib. The question is:

> ¿How to produce a pure sinusoidal frequency whit the functions of the Allegro library?

I hate having to say this to every emu author that asks questions like this, but look at the source code to other emulators.

Seriously, find an emu that has source code that does what you want, and learn from it. May I recommend DarcNES?

--Nyef


 
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Post Posted: Mon Sep 20, 1999 8:24 pm
First, you don't have to use samples at all.
You must allocate four "streamed" voices and create the sound values on the fly.
For exemple, in 8-bit 44 khz, there are about 44000 *byte* per second making the sound.
The three first channel are square wave, it means that the values must alternate between 0 and 255 (-128 and 128 if using signed mode).

If channel frequency is X, then you will have X times a bunch of 0 then of 255 per second.

Quote
> ¿How to produce a pure sinusoidal frequency whit the functions of the Allegro library?
> I don´t know what a sample is. And i´ve tried to call functions like allocate_vocie(), set_voice_volumen() but
> I can´t heard any sound :(

> Could someboy help me.

> Saludos,
> Jose Manuel Delgado
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Re: Calypso. Game Gear?
Post Posted: Mon Sep 20, 1999 8:25 pm
Quote
> Sorry to ask here, but when do you expect to get to Game Gear emulation?

Geez, are you talking for the debugger ? ^_^
Suppose I make a primitive (read: crap) debugger in Meka, would you be interested in working on it ?
  View user's profile Send private message Visit poster's website
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Re: News about Calypso
Post Posted: Mon Sep 20, 1999 10:06 pm
Quote
> But the new version in developtment, 009, can run correctly Game Gear games almos perfectly, both emulator
> and debbuger. It is still in test mode, because in Game Gear mode the savegame format is diferrent and a few
> things more. The idea was to improve the sound and other important surprise in the build 009, but if you like
> i can release in two or three days a new Calypso version with full Game Gear support (with full I refer both emulator
> and debugger).

I would definately like to see it. I've pretty much commited to porting my Defender of the Crown demo, when a decent Game Gear emulator (with a good debugger) shows up.

Quote
> I think that the debugger is very incomplete. If you want a command that it is not present, tell to the forumt so
> i can implement it.

What do you mean incomplete? Does it support breakpoints and examining memory?
  View user's profile Send private message Visit poster's website
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Re: News about Calypso
Post Posted: Mon Sep 20, 1999 10:09 pm
Quote
> I think that the debugger is very incomplete. If you want a command that it is not present, tell to the forumt so
> i can implement it.

Does it display or allow examing VDP registers and VRAM?
  View user's profile Send private message Visit poster's website
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Re: Calypso. Game Gear?
Post Posted: Tue Sep 21, 1999 7:02 am
Quote
> Geez, are you talking for the debugger ? ^_^
> Suppose I make a primitive (read: crap) debugger in Meka, would you be interested in working on it ?

Well BRSMS has a debugger, I would prefer something that would aid rather than hinder in development. But as long as I can set breakpoints, single step (using keys similar to VC++, I'm pushin', huh? :)), view VRAM, memory, VDP regs, and z80 regs, I'll be happy.
  View user's profile Send private message Visit poster's website
  • Joined: 24 Jun 1999
  • Posts: 1732
  • Location: Paris, France
Reply with quote
Re: Calypso. Game Gear?
Post Posted: Tue Sep 21, 1999 9:54 am
Quote
> > Geez, are you talking for the debugger ? ^_^
> > Suppose I make a primitive (read: crap) debugger in Meka, would you be interested in working on it ?
> Well BRSMS has a debugger, I would prefer something that would aid rather than hinder in development. But as long as I can set breakpoints, single step (using keys similar to VC++, I'm pushin', huh? :)), view VRAM, memory, VDP regs, and z80 regs, I'll be happy.

So basically I have two kinds of things to do:
- the debugger itself
- and various applet like the already present tile viewer
I'll try to work on that ASAP.
  View user's profile Send private message Visit poster's website
LSJMDM
  • Guest
Reply with quote
Re: News about Calypso
Post Posted: Tue Sep 21, 1999 2:25 pm
Quote
> What do you mean incomplete? Does it support breakpoints and examining memory?

Yes. The way you should establish abreakpoint is to execute indefinately until direction 0xXXXX. It´s primitive, but works.

I want to know if command like avance one scanline, avance until a specific por is read or written will be useful, to implement it.

Saludos,
Jose Manuel Delgado
 
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Re: News about Calypso
Post Posted: Tue Sep 21, 1999 2:38 pm
Quote
> I want to know if command like avance one scanline, avance until a specific por is read or written will be useful, to implement it.

It sounds like these would be more useful for rom hacking than development.
  View user's profile Send private message Visit poster's website
Benjamin C. W. Sittler
  • Guest
Reply with quote
Post Posted: Tue Sep 21, 1999 6:49 pm
Quote
> First, you don't have to use samples at all.
> You must allocate four "streamed" voices and create the sound values on the fly.
> For exemple, in 8-bit 44 khz, there are about 44000 *byte* per second making the sound.
> The three first channel are square wave, it means that the values must alternate between 0 and 255 (-128 and 128 if using signed mode).

This is almost right. -128 and 127, though, not -128 and 128 (since we use 8-bit two's-complement arithmetic.)

The values placed in the buffer actually correspond (indirectly) to the position of the diaphragm inside your
speaker. So, to make audible signals you need to have changing values in your sample. To make a pure
musical tone, you need values selected at regular intervals from a sine wave, so that the speaker diaphragm
will vibrate in a sinusoidal pattern and cause the surrounding air to due likewise (which will in turn induce
vibration in your ear, so you can hear the tone.)

The sample rate affects how quickly you can adjust the diaphragm position (there are physical limitations
as well,) and a faster sample rate permits faster-changing (higher-frequency) vibrations. Because the diaphragm
must be moved to produce a vibration, your sample must contain at least two samples for each vibration,
and so a sample with a rate of N can produce vibrations of frequency N/2 or lower.

Quote
> If channel frequency is X, then you will have X times a bunch of 0 then of 255 per second.

Actually, thet's period, not frequency. Period is the inverse of frequency:

period = 1 / frequency

period is the amount of time (or number of samples) in a single waveform cycle (before the next repetition.)
frequency is the number of waveform cycles in a given amount of time (for example, 1 Hz is one cycle each
second.) So if you're trying to put a sine wave into a sample buffer, the period is how many samples you
write before your phase gets back to 0 degrees/0 radians.

wavelength is period times speed of transmission. For sound waves, speed of transmission is the speed of sound
in air. wavelength is the amount of space the wave travels through during a single period. wavelength isn't
really important for building sound samples, but I thought I should mention it for completeness.

For a higher frequency, you use a lower period, and vice-versa. If you are generating 44100 samples per
second, and you wanted to generate a sine wave at 220 Hz (the "A" note below the middle "C" note,) you
would need to generate generate a complete sine cycle every 200.454545... samples per cycle:

(44100 samples per second) / (220 cycles per second) = 200.454545... samples per cycle

So if you want the note to be sound pure and be in perfect tune, you must use fixed-point or floating-point
fractions to compute the angle in the cycle of the sine wave. For example, if you want the note above to
start at sample #0, you can calculate how much to advance this angle for each successive sample (this
angle, by the way, is called the phase angle.) To do this,

360 degrees / 200.454545... samples per cycle = 1.79591836... degrees per sample

or, in radians (usually more useful)

2 * pi radians / 200.454545... samples per cycle = 0.0313446886... radians per sample

So you know to advance your phase angle that much for each sample. Of course, you can wrap around at
0 degrees / 0 radians. In fact, to make this "wrap-around" automatic, we often use an angle that has been
scaled up so that one full cycle exactly overflows the number back to zero. (This is useful for fixed-point and
integer angles only!) For example, if you use an unsigned 8-bit integer angle (an unsigned char, in C,) you
might decide that 256 == one cycle, so that when an angle wraps from 255 to 0, it's still in the right place.
A similar technique is used by the Allegro fixed-point math routines, but they have the advantage of tracking
the fractional parts of angles as well.

So, to fill a piece of your buffer, you can do something like this (this code is meant to be readable, not
efficient:)

fillwithsine(char buffer[], int length)
{
static float angle = 0.0; /* phase angle */
int i; /* sample index */

for (i = 0; i < length; i ++)
{
buffer[i] = 127 * sin(angle);
angle = angle + 0.0313446886; /* advance to next phase angle */
if (angle > 2 * 3.141592653) /* wrap around at the end of a cycle */
{
angle = angle - 2 * 3.141592653;
}
}
}

(If we had used an integer or fixed-point angle instead, we wouldn't need to handle the
wrap-around, instead we would need a sin() function which accepted fixed-point angles
in the right range. Allegro's fsin() does this.)

You can use a square wave function instead of a sine wave function if you like, since that's more realistic
for emulating some older sound hardware. The same techniques are used then, but the function is much
simpler, and the code runs a lot faster, since sin() and fsin() are somewhat time-consuming functions.

This should hopefully be enough to get you started, should you decide to write sampling synthesis code.
 
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Re: Calypso. Game Gear?
Post Posted: Tue Sep 28, 1999 4:49 am
Quote
> So basically I have two kinds of things to do:
> - the debugger itself
> - and various applet like the already present tile viewer

Yep, your GUI should work well for the applet stuff.
  View user's profile Send private message Visit poster's website
Reply to topic



Back to the top of this page

Back to SMS Power!