PCEngineFans.com - The PC Engine and TurboGrafx-16 Community Forum
Tech and Homebrew => Turbo/PCE Game/Tool Development => Topic started by: Lochlan on July 19, 2013, 01:49:18 AM
-
Recently I've been playing around with the sound hardware (under emulation). For some reason I can't get white noise to work in my huc project. I'm calling this function on a button press:
whitenoise() {
#asm
lda #4 ; Select channel 4
sta $800
lda #%000_11111 ; Stop playing waveform
sta $804 ; and set volume to $1F
lda #$FF ; Balance settings
sta $805
lda #$80+2 ; Noise ON and set frequency
sta $807
#endasm
}
...but nothing is happening. I ripped this directly from the huc documentation (doc/pce/psg.txt) so I don't understand why this isn't working. I've used the button to do other things in other contexts, so I know that the function call should be fine. I've tried playing with various values in the lower 5 bits written to $807 but nothing seems to be working. I'm running my .pce ROM in Mednafen (after having various issues with Magic Engine).
What is going on here? Does anybody have an idea? Any advice is greatly appreciated.
-
I dunno what else you have in your code, but that doesn't look sufficient on its own. Without testing it myself, I can only think of the following addition:
lda #$FF
sta $801
at the end of your sound code. Also, I do believe that you have to put *something* in $807 ("note" data) on each frame.
-
$804 value is $9F if you want to set voice on, and volume at his maximum(ie #31 or #$1F ) .
Of course for psg mode, not for DDA output .
bit 7 must be 1(voice ON) and bits 0->4 is for voices volume setting
Also for noice frequencies, their range is #$80 -> #$FF, and if you put a value, less than #$80, you will hear nothing..
-
$804 value is $9F if you want to set voice on, and volume at his maximum(ie #31 or #$1F ) .
Agreed. You turn the channel off at the start, but never turn it back on in white noise mode.
Also, do you load the waveform buffer? It is used to generate the white noise, I believe.
And finally, did you turn the main volume on? I often forget that one.....
-
This looks like a job for Squirrel!
:D
But yes, if you don't init the main volume and the channel volumes, it may be working.
Very quietly.
-
Also, do you load the waveform buffer? It is used to generate the white noise, I believe.
And finally, did you turn the main volume on? I often forget that one.....
Yes i agree with that too ;-)
You don't need any waveform (it's auto generated) for this kind of sound .
And of course you should put the general volume ($801) at his max (#$FF) .
White noise is the easiest part on pce sound for me .
-
I thought there were EQUs for the addresses so you don't have to remember them. If you use the EQUs its a bit easier to see what is going on, also.
-
Thanks for the help, guys. As touko said, you don't need to set a waveform because the white noise generates a random waveform.
I needed to do two things to fix it:
1) Set bit 7 of $804 to re-enable the channel
2) Set the global volume on $801
Here is a working version of the code:
whitenoise() {
#asm
lda #4 ; Select channel 4
sta $800
lda #%000_11111 ; Stop playing waveform
sta $804 ; and set volume to $1F
lda #$FF ; Balance settings
sta $805
lda #%100_11111 ; Set bit 7 to turn the channel, set the volume to max
sta $804
lda #$FF ; Max volume both outputs
sta $801
lda #$80+2 ; Noise ON and set frequency
sta $807
#endasm
}
I thought there were EQUs for the addresses so you don't have to remember them. If you use the EQUs its a bit easier to see what is going on, also.
Those are in sndDefs.h (part of the sound libraries you guys seem to be using for all your code, including in Squirrel) which is not part of the default HuC libraries AFAIK. Honestly I was just having a lot of trouble getting the compiled Squirrel .pces to work in Magic Engine (although they were fine in Mednafen) so I didn't want to rely on the sound libraries.
-
Glad to know its working now.
As touko said, you don't need to set a waveform
kk. I thought the waveform was used as a sort of seed for the random noise. Though I don't know how you would tell any difference.
It's worth it to include sndDefs.h, just for readablility. I think the sound support in HuC is broken, or incomplete.
And we won't even get into using magic engine to test things....
Fwiw, we use mednafen and ootake to test things. If it works on both, it usually works on real hardware :)
-
Yeah, Magic Engine's audio likes to be special sometimes.
but, nothings stopping you from stealing those EQUs are redefining them yourself.
-
@Lochlan: if you want to make music, use squirrel rather than huc sound driver, even if you want only make sfx, huc driver is not good at all,it will be better to make your own .
And if you want to mix the two, i think squirrel is also designed for, with arkhan and TheOldMan if you have any problem with it .
-
Yeah it does sound effects. See: Pyramid Plunder
(or the Atlantean demo videos)