示例#1
0
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
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
def get_note_numbers(mag_list):
    if mag_list is not None:
        assert mag_list[:N/2][0] == mag_list[0]
        note_numbers = uniq(enumerate(mag_list[:N/2]))
        return [p for p in get_largest(note_numbers) if note_numbers[p] > MAG_THRESHOLD]
    else:
        return None

def get_largest(l):
    largest = heapq.nlargest(6, l, key=(lambda key: l[key]))
    return largest

#[((p+lowest_hearable)*float(SAMPLE_RATE)/N), mag) for (p, mag) in largest if mag > MAG_THRESHOLD]

def get_sound():
    mag_list = wonderful.munch()
    return get_note_numbers(mag_list)

try:
    while True:
        t = time.clock()
        s = get_sound()
        if s is not None:
            print s, "\t\tin", t-lasttime, "seconds"
        lasttime = t

except KeyboardInterrupt:
    pass

wonderful.terminate()