Lab3 - tune-o-rama

From Inforail
Jump to: navigation, search

Keywords

client, server, UDP, BSD sockets, protocol, music, sound, synthesizer, broadcast

Objectives

Familiarize yourself with UDP, learn how to send and receive datagrams. Understand the difference between TCP and UDP. Use UDP's broadcasting feature.

Overview

  • Create a collaborative music creation application
  • Every person who runs the program plays a certain instrument. The sound is generated by pressing a button on the keyboard
  • The pitch of the sound depends on the key that was pressed (ex: low to high from A to L on a qwerty-keyboard)
  • A server receives the notes from the clients and plays them simultaneously


Generic requirements

  • The program must rely on the BSD sockets API, not some other library which is an abstraction on top of BSD sockets.
  • You are free to use whatever audio processing library you prefer. To facilitate the development process, check out the references and the samples included in the assignment.


Grading policy

Assuming that everything works right,

  • 7 - for creating and documenting the protocol that provides the features below (i.e. you don't need to implement any feature, just write the specs)
  • 8 - the server successfully plays the notes received from the clients
  • 9 - for implementing 2 bonus features
  • 10 - for implementing 3 bonus features:
  • Bonus features
    • change instrument - a client can choose a different instrument
    • upload instrument - if a client uses an instrument (a WAV sample) the server does not have, the server will retrieve it from the client
    • TODO


A partially implemented feature that does not work 100% right may still be accepted as fully implemented, provided that your report describes the nature of the problem and provides some guesses about what the solution is supposed to be.

Implementation recommendations

  • Perhaps it is a good idea to use UDP for some functionality, while other features can be based on TCP


References

  • Pygame.Mixer - An easy way to load sound samples and play them.

Audio primitives

Here are some things to play with.


Pitch Perfect
PygSoundTestTest
PySynth
  • http://home.arcor.de/mdoege/pysynth/
  • The sounds are written to a WAV file, not played directly by the sound card. This is not suitable for interactive and real-time music generation, but can be handy if you wish to implement a "Save song to file" feature; or if you wish to derive something from it.
Winsound

Simple application that uses the Winsound module to generate beeps on Windows. Note that the module does not mix the sounds; they are not played in parallel, but sequentially - so there's no real orchestra here. The example is posted just so you can use it as a stub or for alpha-prototypes.


import threading
import winsound
import time
import random

def worker(freq, duration, id):
	for i in range(30):
		#print the id of the thread, note how threads are executed in different
		#order, depending on the position of Saturn's rings with respect to
		#Jupiter's red spot
		print id,
		#winsound.Beep(random.randint(800, 2000), random.randint(50, 80) ) #R2D2 mode
		winsound.Beep(freq, duration)
		time.sleep( random.randint(1, 2) )

if __name__ == "__main__":
	for i in range(1, 6):
		#start several threads, init them with different frequencies
		t = threading.Thread(target = worker, args=(800+(i*100), 70, i) )
		t.start()
		time.sleep(1)