├── README ├── data ├── ids.txt ├── on.gif └── off.gif └── AudioBooth.pde /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/ids.txt: -------------------------------------------------------------------------------- 1 | 55 2 | -------------------------------------------------------------------------------- /data/on.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raster/AudioBooth/master/data/on.gif -------------------------------------------------------------------------------- /data/off.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raster/AudioBooth/master/data/off.gif -------------------------------------------------------------------------------- /AudioBooth.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * AudioBooth.pde 3 | */ 4 | 5 | import processing.video.*; 6 | import ddf.minim.*; 7 | 8 | BufferedReader textreader; 9 | String line; 10 | int id; 11 | PrintWriter textoutput; 12 | 13 | Capture cam; 14 | Boolean active = false; 15 | 16 | Minim minim; 17 | AudioInput input; 18 | AudioRecorder recorder; 19 | 20 | PImage on; 21 | PImage off; 22 | 23 | void clearitall() { 24 | 25 | // the AudioInput you got from Minim.getLineIn() 26 | if (input != null) { 27 | input.close(); 28 | } 29 | if (minim != null) { 30 | minim.stop(); 31 | } 32 | 33 | //Kill the variables 34 | background(0); 35 | textreader = null; 36 | line = null; 37 | id = 0; 38 | textoutput = null; 39 | active = false; 40 | minim = null; 41 | input = null; 42 | recorder = null; 43 | on = null; 44 | off = null; 45 | 46 | //Text File Stuff 47 | //Read ID from text file 48 | textreader = createReader(dataPath("ids.txt")); 49 | try { 50 | line = textreader.readLine(); 51 | //Make it an integer so we can do math & iterate 52 | id = Integer.parseInt(line); 53 | id++; 54 | println(id); 55 | } catch (IOException e) { 56 | e.printStackTrace(); 57 | line = null; 58 | } 59 | 60 | 61 | //Audio Stuff 62 | minim = new Minim(this); 63 | input = minim.getLineIn(Minim.STEREO, screen.width); 64 | String filename = "media/audio-" + id + ".wav"; 65 | recorder = minim.createRecorder(input, filename, true); 66 | 67 | //Other 68 | on = loadImage(dataPath("on.gif")); 69 | off = loadImage(dataPath("off.gif")); 70 | } 71 | 72 | void setup() { 73 | size(screen.width, screen.height); 74 | clearitall(); 75 | //Camera Stuff 76 | // If no device is specified, will just use the default. 77 | //cam = new Capture(this, 1280, 720); 78 | 79 | // To use another device (i.e. if the default device causes an error), 80 | // list all available capture devices to the console to find your camera. 81 | String[] devices = Capture.list(); 82 | //println(devices); 83 | 84 | // Change devices[0] to the proper index for your camera. 85 | cam = new Capture(this, 1280, 720, devices[3]); 86 | 87 | // Opens the settings page for this capture device. 88 | //cam.settings(); 89 | 90 | } 91 | 92 | void draw() { 93 | if (cam.available() == true && active == false) { 94 | //Camera Stuff 95 | cam.read(); 96 | imageMode(CENTER); 97 | image(cam, screen.width / 2, screen.height / 2); 98 | } 99 | 100 | //Recording status 101 | if ( recorder.isRecording() ) 102 | { 103 | //Sound Viz 104 | stroke(255,0,0); 105 | background(0); 106 | image(cam, screen.width / 2, screen.height / 2); 107 | image(on, screen.width / 2, 50); 108 | 109 | 110 | // draw the waveforms 111 | for(int i = 0; i < input.bufferSize() - 1; i++) 112 | { 113 | line(i, (screen.height / 3) + input.left.get(i)*150, i+1, (screen.height / 3) + input.left.get(i+1)*150); 114 | line(i, ((screen.height / 3) * 2) + input.right.get(i)*150, i+1, ((screen.height / 3) * 2) + input.right.get(i+1)*150); 115 | } 116 | 117 | } 118 | else 119 | { 120 | image(off, screen.width / 2, 50); 121 | } 122 | } 123 | 124 | void keyPressed() { 125 | if (key == ' ') { // space bar 126 | 127 | String filename = "media/photo-" + id + ".jpg"; 128 | cam.save(filename); 129 | 130 | //Audio Stuff 131 | if ( recorder.isRecording() ) 132 | { 133 | recorder.endRecord(); 134 | recorder.save(); 135 | active = false; 136 | clearitall(); 137 | draw(); 138 | } 139 | else 140 | { 141 | recorder.beginRecord(); 142 | active = true; 143 | } 144 | 145 | //Text File Stuff 146 | textoutput = createWriter(dataPath("ids.txt")); 147 | textoutput.println(id); 148 | textoutput.flush(); // Writes the remaining data to the file 149 | textoutput.close(); // Finishes the file 150 | } 151 | 152 | 153 | } 154 | 155 | void stop() 156 | { 157 | 158 | // the AudioInput you got from Minim.getLineIn() 159 | input.close(); 160 | minim.stop(); 161 | 162 | // this calls the stop method that 163 | // you are overriding by defining your own 164 | // it must be called so that your application 165 | // can do all the cleanup it would normally do 166 | super.stop(); 167 | } 168 | 169 | --------------------------------------------------------------------------------