コード例 #1
0
ファイル: fft_plot.py プロジェクト: jakbob/guitarlegend
def main():
    # Open the interface to the Mic
    wonderful.init(SAMPLE_RATE, N)

    # Make matplotlib interactive. It says "interactive", at least, but I don't see
    # any buttons. This makes a window appear without blocking the application
    # (which pylab.show() would have done).
    pylab.ion()

    # Set up the two subplots and make their scales fixed
    ax = pylab.subplot(111)
    ax.set_autoscale_on(False)
    ax.set_xlim(xmin=-10, xmax=MAX_FREQ+10)   # We pad the graph on the sides so we can
                                       # see better
    ax.set_ylim((0, 10*MAG_THRESHOLD))
    ax.set_xlabel("Hz")

    # Plot some bogus data, so that we may use set_ydata for animation later
    d = [0]*N
    n = pylab.arange(0, SAMPLE_RATE, step=float(SAMPLE_RATE)/N)
    line, = ax.plot(n, d) #http://www.scipy.org/Cookbook/Matplotlib/Animations

    while True:
        try:
            d = wonderful.munch()
            if d is not None:
                line.set_ydata(d)          # Update the plots
                pylab.draw()               # Draw it, and then repeat
            
        except KeyboardInterrupt:
            print "C-c was pressed. Exiting."
            break

    wonderful.terminate()
コード例 #2
0
ファイル: main.py プロジェクト: jakbob/guitarlegend
def main():
    # Parse the command line options
    parser = optparse.OptionParser()
    parser.add_option("--debug", 
                      action="store_true", 
                      dest="debug", 
                      default=False,
                      help="start game in debugging mode")
    parser.add_option("--show-fps", 
                      action="store_true", 
                      dest="show_fps",
                      default=False,
                      help="start game in debugging mode")
    
    (opts, args) = parser.parse_args()

    options.DEBUG = opts.debug
    options.SHOW_FRAMERATE = opts.show_fps

    # Setup a custom data directory
    pyglet.resource.path = ["data"]
    pyglet.resource.reindex()
	
    error.debug("Importing scene")
    import scene # Imported here, because it depends on the options used
    error.debug("Success!")
    error.debug("Importing menu")
    import menu
    error.debug("Success!")
	
    # Add two windows
    game_manager.add_window(MainWindow(width=options.window_width, height=options.window_height, 
                                       caption=options.__appname__, resizable=True), 
                            "game_draw")
    if options.DEBUG: game_manager.add_window(BasicWindow(caption="Debug"), "debug_draw")
    
    # Add one scene
    game_manager.push(menu.MainMenu())

    # Start sound recordning here. Something is wrong with wonderful,
    # leading to strange segfaults. I'm gonna see if this fixes it.
    import wonderful
    wonderful.init(options.SAMPLE_RATE, options.DFT_SIZE)
    
    # Hand control over to the Game manager
    error.debug("Hiya, I'm gonna hand control over to the game manager")
    game_manager.run()
    wonderful.terminate()
コード例 #3
0
ファイル: wondertest.py プロジェクト: jakbob/guitarlegend
import wonderful
import heapq
import time
import math

SAMPLE_RATE = 8000#44100
N = 2048
wonderful.init(SAMPLE_RATE, N)

THRESHOLD_K = 1000
MAG_THRESHOLD = float(N)/THRESHOLD_K # N samples, each between -1.0 and 1.0. The freqs[0] is the sum of all samples.
lasttime = time.clock()

lowest_hearable = int(20 * N/float(SAMPLE_RATE))

def midify(f):                       
    """                              
    Returns the midi keycode for given frequency.
    Could probably be more optimized but this will have to do
    for now.
    """
    n = round(69.0 + 12.0 * math.log(f / 440.0, 2))
    return int(n)

#index_to_midi = {}
#for num in xrange(N):
#    index_to_midi[num] = midify(num*float(SAMPLE_RATE)/N)

def uniq(iterable):
    rets = {}
    for (num, amp) in iterable: