How to customize Snack sound generator freq. increment

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
Rhino
Posts: 263
Joined: Wed 04 May 2005, 13:28
Location: Cincinnati, OH, USA
Contact:

How to customize Snack sound generator freq. increment

#1 Post by Rhino »

I used the snack sound generator in Puppy today in class and it worked great to demonstrate changes in frequency and amplitude for waves on an oscilloscope. I just put the mic close to my pc speaker and a beautiful wave appeared on the oscilloscope..very nice.

I wanted to demonstrate beats due to consructive and destructive interference of the waves by having another adjacent pc producing a sound at a slightly different frequency. However, when I adjust the frequency it changes by about 12 Hz, I need it to be only 1-2 Hz to see and hear the beats well.

I had a look at the code for the application (sgenerator.tcl...I think), but I couldn't figure out how to change the frequency so that it is adjustable in 1Hz increments. If it is possible to do this, it could be a useful change to sgenerator in all future versions of Puppy.

Please let me know if it is possible to get it to produce 1 Hz intervals. Thanks!
Visit the Puppy Linux Video Tutorials @ http://rhinoweb.us

User avatar
Rhino
Posts: 263
Joined: Wed 04 May 2005, 13:28
Location: Cincinnati, OH, USA
Contact:

#2 Post by Rhino »

OK, I solved my own problem, but may be it will be useful for others.

Code: Select all

pack [frame .f] -expand yes -fill both -side top
pack [scale .f.s1 -label Frequency -from 1000 -to 50 -length 800\
        -variable v(freq) -command Config] -side left -expand yes -fill both
pack [scale .f.s2 -label Amplitude -from 32767 -to 0 -length 800\
        -variable v(ampl) -command Config] -side left -expand yes -fill both

To get the frequency to change in 1 Hz increments, I just decreased the maximum frequency to 1000Hz, but you could make it lower if you like to get a slightly smaller window. I also changed the length of the bar to 800 rather than the original so the box is much longer. I also changed the bar length to 800 to make it match as well.

If you have a different screen resolution, it may help to keep the bar length shorter, but to simply decrease the maximum frequency to something like 600 Hz.

I may attempt to figure out how to turn the whole box horizontally to maximize the screen space available to have a larger range of frequencies and 1Hz resolution.[/code]
Visit the Puppy Linux Video Tutorials @ http://rhinoweb.us

User avatar
Rhino
Posts: 263
Joined: Wed 04 May 2005, 13:28
Location: Cincinnati, OH, USA
Contact:

#3 Post by Rhino »

I changed the orientation of the slider bars in the tone generator so they will be horizontal to privide a little more space and resized the scale so that it would display and make 1Hz increments. I found that you can increase the maximum frequency, however, you might have to maximize the window to see it.

I know this is probably a little used application, but for me it is excellent for Physics class.

Code: Select all

#!/bin/sh
# the next line restarts using wish \
exec wish8.4 "$0" "$@"

package require -exact snack 2.2

set f [snack::filter generator 440.0]
snack::sound s
#snack::audio playLatency 200

tk_optionMenu .m v(type) sine rectangle triangle sawtooth noise
foreach i [list 0 1 2 3 4] {
  .m.menu entryconfigure $i -command Config
}
pack .m -side bottom

pack [frame .fb] -side bottom
pack [button .fb.a -bitmap snackPlay -command Play] -side left
pack [button .fb.b -bitmap snackStop -command "s stop"] -side left

set v(freq) 440.0
set v(ampl) 20000

pack [frame .f] -expand yes -fill both -side top
pack [scale .f#!/bin/sh
# the next line restarts using wish \
exec wish8.4 "$0" "$@"

package require -exact snack 2.2

set f [snack::filter generator 440.0]
snack::sound s
#snack::audio playLatency 200

tk_optionMenu .m v(type) sine rectangle triangle sawtooth noise
foreach i [list 0 1 2 3 4] {
  .m.menu entryconfigure $i -command Config
}
pack .m -side bottom

pack [frame .fb] -side bottom
pack [button .fb.a -bitmap snackPlay -command Play] -side left
pack [button .fb.b -bitmap snackStop -command "s stop"] -side left

set v(freq) 440.0
set v(ampl) 20000

pack [frame .f] -expand yes -fill both -side top
pack [scale .f.s1 -orient horizontal -label Frequency -from 100 -to 1500 -length 1200\
        -variable v(freq) -command Config] -side top -expand yes -fill both
pack [scale .f.s2 -orient horizontal -label Amplitude -from 0 -to 3267 -length 1200\
        -variable v(ampl) -command Config] -side top -expand yes -fill both

proc Config {args} {
  global f v
  set shape 0.0
  set type $v(type)
  switch $type {
    sine {
      set shape 0.0
    }
    rectangle {
      set shape 0.5
    }
    triangle {
      set shape 0.5
    }
    sawtooth {
      set shape 0.0
      set type triangle
    }
  }
  $f configure $v(freq) $v(ampl) $shape $type -1
}

proc Play {} {
  global f
  s stop
  s play -filter $f
}
.s1 -orient horizontal -label Frequency -from 100 -to 1500 -length 1200\
        -variable v(freq) -command Config] -side top -expand yes -fill both
pack [scale .f.s2 -orient horizontal -label Amplitude -from 0 -to 3267 -length 1200\
        -variable v(ampl) -command Config] -side top -expand yes -fill both

proc Config {args} {
  global f v
  set shape 0.0
  set type $v(type)
  switch $type {
    sine {
      set shape 0.0
    }
    rectangle {
      set shape 0.5
    }
    triangle {
      set shape 0.5
    }
    sawtooth {
      set shape 0.0
      set type triangle
    }
  }
  $f configure $v(freq) $v(ampl) $shape $type -1
}

proc Play {} {
  global f
  s stop
  s play -filter $f
}
Visit the Puppy Linux Video Tutorials @ http://rhinoweb.us

HaJo
Posts: 27
Joined: Wed 15 Mar 2006, 00:05
Location: DE

#4 Post by HaJo »

Rhino wrote:

Code: Select all

...
pack [frame .f] -expand yes -fill both -side top
pack [scale .f#!/bin/sh
--------------^^...
This looks like a cut+paste - accident
-HaJo

Post Reply