Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Gameboy sound is getting shut off! | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2282/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-04-04 02:10 PM Link | Quote
Here's the code I'm using to play a sound (on both channels 1 and 2):

ldi a,(hl) ;Get frequency 1
and a
jr z, .nofreq1 ;Skip this if zero
push af
ldh a,(soundchannels) ;FF25
or $11 ;Enable channel 1 on both speakers
ldh (soundchannels),a
ld a,$FF ;Set sound length
ldh (sound1+1),a ;FF10
pop af
ldh (sound1+3),a ;Set frequency
ld a, $C7 ;High freq byte, endless, start
ldh (sound1+4),a
.nofreq1:

ldi a,(hl) ;Get frequency #2
and a
jr z, .nofreq2 ;Skip if zero
push af
ldh a,(soundchannels)
or $22 ;Enable channel 2 on both speakers
ldh (soundchannels),a
ld a,$FF ;Set length
ldh (sound2+1),a ;FF15
pop af
ldh (sound2+3),a
ld a,$C7 ;High byte, endless, start
ldh (sound2+4),a
.nofreq2:

ld a,%01110111 ;Max volume, vin off
ld (soundvolume),a

;Delay loop
push bc
ldi a,(hl) ;Get delay time
ld b,a
ldi a,(hl)
ld c,a

.delay: dec c
jr nz, .delay
dec b
jr nz, .delay

pop bc


When it goes into the delay loop, all the sound registers are fine, but by the time it gets to 'dec b', they've all been wiped to zero and no sound actually plays. Interrupts are disabled during this code, and envelopes are off. (And for those who ask why I bother to set lengths when I also set the 'endless' flag, I was just trying to get the damn thing to work. I'll make it less hacky later.) What exactly is going on here?
Dish

Spiny
Level: 38

Posts: 210/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 12-05-04 12:21 AM Link | Quote
I'm assuming 'sound1' is $10, no?

> ld a,$FF ;Set sound length
> ldh (sound1+1),a ;FF10

Your ";FF10" comment threw me off here at first... since you're really writing to $FF11 (assuming 'sound1' is $10 and not $0F).


> ld a, $C7 ;High freq byte, endless, start
> ldh (sound1+4),a

if you're looking for 'endless' sound you want the length counter disabled (not enabled), so turn that bit off, not on (a write of $87 would do).

You never seem to write to $FF12 (never giving the channel an output volume). Write to this with your volume (range: 0-F) as the high 4 bits, and keep the low 3 bits off (unless you want envelope enabled).

You're writing to $FF25, which is good... but I don't see you writing to $FF26. You have to flip the high bit of $FF26 on to turn on the pAPU. If you don't... the pAPU doesn't get power and no sound is produced (this may very well be your main problem -- unless you did it elsewhere and didn't paste that portion).

> (And for those who ask why I bother to set lengths when I also set the 'endless' flag

It's important to write a nonzero value to the length anyway. I'm not 100% sure on the GB, but if it's anything like the NES (which it seems to be), a length count of zero would silence the channel even if length is disabled.

I'm not as confident on GB Sound as I should be... I may be wrong on a few areas but it's worth a look anyway ^^.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 2292/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 12-05-04 03:45 AM Link | Quote
I was using 87 as well (though come to think of it, yeah, I should be doing that ). Yes, sound1 is $FF10 and sound2 is $FF15. (And in case any of you couldn't guess, a percent sign indicates Binary. Should have mentioned that.)

...Oops, always make sure your speakers are ON when testing sound. Although that wasn't the only problem. Apparently it was the volume at $FF12/$FF17. Heh, I thought that was only for envelopes... Thanks!
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Gameboy sound is getting shut off! | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.004 seconds.