Shop OBEX P1 Docs P2 Docs Learn Events
sound_drv_001 question. — Parallax Forums

sound_drv_001 question.

TonyATonyA Posts: 226
edited 2007-07-06 00:05 in Propeller 1
I'm using the gamepad to make sound. I was wondering how I could adjust the parameters of the PlaySound function.


Repeat
· if(game_pad.button(game_pad#NES0_A))· ·'if press the A button make sound.
··· snd.PlaySoundFM(0, snd#SHAPE_SQUARE, freqVar, snd#SAMPLE_RATE, 255, $2457_9DEF)

I replaced the "arg_freq" with the variable "freqVar". I'm able to plug different values for freqVar and get different tones. I'd like to use the up button to increase the frequency, and the down button to decrease.

So, I'm thinking about something like this:

freqVar := 16..1976· 'assign a range to the freqVar variable, (I have no idea)

if(game_pad.button(game_pad#NES0_UP)) 'if press up button frequency increases
··· freqVar + 1

Or
·
if(game_pad.button(game_pad#NES0_DOWN)) 'if press down button frequency decreases
··· 'snd.SetFreq(0, (freqVar -1))

Would something like this work?

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-07-05 22:17
    Does this question belong in the Hydra forum? If so I'll move it there for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • TonyATonyA Posts: 226
    edited 2007-07-05 22:19
    Sorry, yes. I believe it would. (I often think "propeller" and hydra are synonymous)

    Thank you.
  • AndreLAndreL Posts: 1,004
    edited 2007-07-05 23:26
    snd_drv_010.spin is a simple PCM driver that has no function set. I think you are playing with the HYDRAs sound drivers by nick s. The best thing to do is use one of our demos to start with and then make changes to it. The HYDRA book covers using the driver as well.

    Andre'
  • TonyATonyA Posts: 226
    edited 2007-07-06 00:05
    yes, I am experimenting with the Nick S's NS_sound_drv_051_22khz_16bit.spin.

    I'm just beginning to learn the basics of Spin·and thought I was·starting to understand how to call methods, etc.

    (I'm not a programmer so please forgive the following).

    I was able to produce sound with the gamepad buttons like this:
    VAR
      long freqVar
      
    
    OBJ
      game_pad :  "gamepad_drv_001.spin"               'instantiate the gamepad driver object
      snd      :  "NS_sound_drv_051_22khz_16bit.spin"  'sound driver
    PUB main
      game_pad.start                  'gamepad driver's start method
      game_pad.read                   'gamepad driver's read method
      snd.start(7)                    'sound driver's start method
    
    Repeat
      if(game_pad.button(game_pad#NES0_A))
        snd.PlaySoundFM(0, snd#SHAPE_SQUARE, freqVar, snd#SAMPLE_RATE, 255, $2457_9DEF )
       
     
      if(game_pad.button(game_pad#NES0_B))
        snd.PlaySoundFM(1, snd#SHAPE_SINE, freqVar, snd#SAMPLE_RATE, 255, $2457_9DEF)
    
      if(game_pad.button(game_pad#NES0_START))
        snd.PlaySoundFM(2, snd#SHAPE_SAWTOOTH, freqVar, snd#SAMPLE_RATE, 255, $2457_9DEF)  
    
      snd.StopSound(0)
     
      snd.StopSound(1)
      
      snd.StopSound(2) 
        
      if(game_pad.button(game_pad#NES0_DOWN))
       snd.SetFreq(0, (freqVar -1)) 
    
       snd.SetFreq(1, (freqVar -1))
      
       snd.SetFreq(2, (freqVar -1))
     
        
    



    I am able to produce a note by pressing either the A, B, or START buttons,·and make·the note·go down a half step (or whole step?)by pressing the gamepad down button.

    I was just trying to figure out how to make·the note·go down continually (sweep down)·as I hold the down button, and go up continually (sweep up)·as I hold the up button.

    (And then apply that to change the other parameters like the SHAPE, volume, and envelope.)

    Do I need an Index? or Array, etc?

    *For instance; should I make some kind of "array" or list of all of the notes I would like to produce in my top object, and then "iterate" (my new programming word of the day!) through the array/list?

    If so, how would I iterate through the array/list using one of the gamepad buttons (preferably the up and down buttons)?

    Thanks.



    Post Edited (TonyA) : 7/6/2007 12:48:18 AM GMT
Sign In or Register to comment.