Author Topic: White Noise not Working?  (Read 469 times)

Lochlan

  • Sr. Member
  • ****
  • Posts: 408
White Noise not Working?
« 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:

Code: [Select]
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'm not sorry about this, as I'm not sorry about ANY attack by the goverrats.

nodtveidt

  • Guest
Re: White Noise not Working?
« Reply #1 on: July 19, 2013, 02:28:10 AM »
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:

Code: [Select]
    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.

touko

  • Hero Member
  • *****
  • Posts: 953
Re: White Noise not Working?
« Reply #2 on: July 19, 2013, 02:38:58 AM »
$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..
« Last Edit: July 19, 2013, 07:49:27 AM by touko »

TheOldMan

  • Hero Member
  • *****
  • Posts: 958
Re: White Noise not Working?
« Reply #3 on: July 19, 2013, 06:48:38 AM »
Quote
$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.....

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: White Noise not Working?
« Reply #4 on: July 19, 2013, 06:59:08 AM »
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. 
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

touko

  • Hero Member
  • *****
  • Posts: 953
Re: White Noise not Working?
« Reply #5 on: July 19, 2013, 07:48:13 AM »

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 .
« Last Edit: July 19, 2013, 07:54:19 AM by touko »

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: White Noise not Working?
« Reply #6 on: July 19, 2013, 08:04:13 AM »
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.
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

Lochlan

  • Sr. Member
  • ****
  • Posts: 408
Re: White Noise not Working?
« Reply #7 on: July 19, 2013, 01:43:52 PM »
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:

Code: [Select]
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.
I'm not sorry about this, as I'm not sorry about ANY attack by the goverrats.

TheOldMan

  • Hero Member
  • *****
  • Posts: 958
Re: White Noise not Working?
« Reply #8 on: July 19, 2013, 02:23:30 PM »
Glad to know its working now.

Quote
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 :)

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: White Noise not Working?
« Reply #9 on: July 19, 2013, 02:29:30 PM »
Yeah, Magic Engine's audio likes to be special sometimes.

but, nothings stopping you from stealing those EQUs are redefining them yourself.   
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.

touko

  • Hero Member
  • *****
  • Posts: 953
Re: White Noise not Working?
« Reply #10 on: July 19, 2013, 11:14:16 PM »
@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 .
« Last Edit: July 19, 2013, 11:19:56 PM by touko »

Arkhan

  • Hero Member
  • *****
  • Posts: 14142
  • Fuck Elmer.
    • Incessant Negativity Software
Re: White Noise not Working?
« Reply #11 on: July 20, 2013, 06:46:25 AM »
Yeah it does sound effects.  See: Pyramid Plunder

(or the Atlantean demo videos)
[Fri 19:34]<nectarsis> been wanting to try that one for awhile now Ope
[Fri 19:33]<Opethian> l;ol huge dong

I'm a max level Forum Warrior.  I'm immortal.
If you're not ready to defend your claims, don't post em.