IGNORED

Sound effect not working

Recommended Posts

Hey!!

I am trying out the PSG Envelope tool that helps you create sound effects. It gave me the following code which I implemented in my game, but it doesn't work for me:

Here is the code it gave:

sound 4,\$0f,\$0007
sound 2,\$0BB8,\$30
sound 3,\$0800,\$0004

I am not sure if I am doing something wrong.. below is my code. Any help is appreciated

if throw_sound = 1 then
snd = snd + 1
if snd < 20 then
sound 4,\$0f,\$0007
sound 2,\$0BB8,\$30
sound 3,\$0800,\$0004
end if

if snd = 20 then
SOUND 4,,0
SOUND 2,,0
SOUND 3,,0
snd = 0
throw_sound = 0
end if
end if

Edited by Brian's Man Cave
Share on other sites

SOUND 2 (voice C) takes a 12-bit frequency value and a volume 0-15 while you feed it \$30 = 48. I think that might be one of your problems.

SOUND 4 takes a 5-bit noise value (0-31) and a mix register:

REM Mixer control (0 = Enable, 1 = Disable)
REM |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
REM | I/O A | I/O B | Noi C | Noi B | Noi A | Ton C | Ton B | Ton A |

\$0004 in this case means you enable noise on voices A, B, C and tone on voices A, B but not C, plus you set the noise frequency to \$0F which is medium high. Since you never set voices A and B (SOUND 0 and 1), I think we can ignore those.

Based on the documentation in psg.txt (see jzintv installation, folder doc/programming), it seems the 16-bit value (here \$0800) is the period and the type is \$04 which visually is illustrated as

/|_________________________________

which then should be played using only noise with the fixed frequency \$0F rather than the frequency \$0BB8 you have it above.

Try SOUND 4,1,\$38 and SOUND 2,\$0BB8,\$0F to see if it makes anything change. I suppose the routine is called by ON FRAME so it counts once per frame, rather than free running and counting to 20 as fast as possible?

Share on other sites

26 minutes ago, carlsson said:

SOUND 2 (voice C) takes a 12-bit frequency value and a volume 0-15 while you feed it \$30 = 48. I think that might be one of your problems.

SOUND 4 takes a 5-bit noise value (0-31) and a mix register:

REM Mixer control (0 = Enable, 1 = Disable)
REM |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
REM | I/O A | I/O B | Noi C | Noi B | Noi A | Ton C | Ton B | Ton A |

\$0004 in this case means you enable noise on voices A, B, C and tone on voices A, B but not C, plus you set the noise frequency to \$0F which is medium high. Since you never set voices A and B (SOUND 0 and 1), I think we can ignore those.

Based on the documentation in psg.txt (see jzintv installation, folder doc/programming), it seems the 16-bit value (here \$0800) is the period and the type is \$04 which visually is illustrated as

/|_________________________________

which then should be played using only noise with the fixed frequency \$0F rather than the frequency \$0BB8 you have it above.

Try SOUND 4,1,\$38 and SOUND 2,\$0BB8,\$0F to see if it makes anything change. I suppose the routine is called by ON FRAME so it counts once per frame, rather than free running and counting to 20 as fast as possible?

I tried the code and it did make a sound, a short buzz noise. The sound I am trying to make is one kind of like the snake sound in D&D Cloudy Mountain. Its the first time I am trying that software...

Edited by Brian's Man Cave
Share on other sites

I never tried the tool. I spent some time trying to figure out how the volume envelope works in regard to periods and how you set the sound volume - it seems \$30 is a decent value for a voice volume after all once you bring envelopes into play.

Since you'd visit the routine anyway on every frame, I think you get more freedom adjusting volume manually instead of letting the PSG do it. I have attached a skeleton that I'm using, which probably is somewhat similar to what you already use.

Share on other sites

I tried the software again and still no go... I wonder if there is something missing here or if the software has bugs??

Share on other sites

By the way, are you supposed to use it in a routine that sets the envelope on each frame?

Since the envelope contains a period, I'm thinking maybe the routine should be like this:

IF sound_state = 0 THEN
SOUND blah blah blah
END IF

sound_state = sound_state + 1

IF sound_state = 20 THEN
sound_effect = 0
END IF

meaning you count frames to determine when to turn off the effect, but the envelope handling the volume would be enabled once and then run its course.

However, I haven't tested my theory yet.

Edit: if that works out, you might not even need an ON FRAME based engine, since you could trigger sound from the main program and trigger a new sound effect when needed. Then again if you were to change the pitch etc at the same time the volume envelope runs, you still would need to call the engine per frame, just not trigger the envelope each time.

Edited by carlsson
Share on other sites

When envelopes are used, the "command code" for the envelope should be loaded a single time at the start. Otherwise the envelope is "resetted" continuously creating a "motor" noise.

if throw_sound = 1 then

IF SND = 0 THEN
sound 4,\$0f,\$0007
sound 2,\$0BB8,\$30
sound 3,\$0800,\$0004

END IF
snd = snd + 1

if snd = 20 then
SOUND 4,,0
SOUND 2,,0
SOUND 3,,0
snd = 0
throw_sound = 0
end if
end if

Share on other sites

1 hour ago, nanochess said:

When envelopes are used, the "command code" for the envelope should be loaded a single time at the start. Otherwise the envelope is "resetted" continuously creating a "motor" noise.

if throw_sound = 1 then

IF SND = 0 THEN
sound 4,\$0f,\$0007
sound 2,\$0BB8,\$30
sound 3,\$0800,\$0004

END IF
snd = snd + 1

if snd = 20 then
SOUND 4,,0
SOUND 2,,0
SOUND 3,,0
snd = 0
throw_sound = 0
end if
end if

Thanks @carlsson and @nanochess!!  That is what solved my problem.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.