Changeset 1102 for trunk/src/org/apollo/meldex
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- Location:
- trunk/src/org/apollo/meldex
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/meldex/PitchTracker.java
r315 r1102 3 3 import java.util.ArrayList; 4 4 5 @SuppressWarnings("unchecked") // code in java 1.46 5 public class PitchTracker 7 6 { … … 14 13 15 14 // The pitch data 16 ArrayList pitchData;15 ArrayList<PitchValue> pitchData; 17 16 18 17 // Our lovely Pitch Period Estimators … … 26 25 27 26 28 public ArrayList process(byte[] rawData, int rawLength, int rawSampleRate)27 public ArrayList<PitchValue> process(byte[] rawData, int rawLength, int rawSampleRate) 29 28 { 30 29 // Save the sample rate of the loaded sample … … 32 31 33 32 // Allocate a new pitch data array to store our pitch values 34 pitchData = new ArrayList ();33 pitchData = new ArrayList<PitchValue>(); 35 34 36 35 // Reset our 6 pitch period estimators -
trunk/src/org/apollo/meldex/PitchValue.java
r315 r1102 11 11 public PitchValue(double per, int pos) 12 12 { 13 period = per;14 position = pos;13 period = per; 14 position = pos; 15 15 } 16 16 } -
trunk/src/org/apollo/meldex/RogTrack.java
r315 r1102 1 1 package org.apollo.meldex; 2 3 2 4 3 import java.io.File; 5 4 import java.io.FileInputStream; 6 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 7 import java.util.ArrayList; 8 import javax.swing.JOptionPane; 9 10 @SuppressWarnings("unchecked") // code in java 1.4 8 9 import org.expeditee.gio.EcosystemManager; 10 11 11 public class RogTrack 12 12 { … … 20 20 21 21 // Data representing the track events 22 ArrayList trackData = new ArrayList();22 ArrayList<RogTrackEvent> trackData = new ArrayList<RogTrackEvent>(); 23 23 24 24 … … 217 217 int track_len = trackData.size(); 218 218 219 ArrayList filtered_td = new ArrayList();219 ArrayList<RogTrackEvent> filtered_td = new ArrayList<RogTrackEvent>(); 220 220 221 221 for (int i = 0; i < track_len; i++) { … … 235 235 } 236 236 237 ArrayList me_list = new ArrayList();237 ArrayList<MelodyEvent> me_list = new ArrayList<MelodyEvent>(); 238 238 239 239 for (int i = 0; i < filtered_track_len-1; i++) { … … 283 283 public boolean loadFromFile(File rogFile) 284 284 { 285 try { 286 // Open the file with a FileInputStream, ready for parsing 287 FileInputStream fileIn = new FileInputStream(rogFile); 288 289 // Get the number of bytes in the file 290 int rogLength = fileIn.available(); 291 292 // Create a buffer to store the file, and read the file into it 293 byte[] rogData = new byte[rogLength]; 294 fileIn.read(rogData, 0, rogLength); 295 296 // Parse the .rog file 297 parseFile(rogData, rogLength); 298 } 299 catch (Exception ex) { 300 JOptionPane.showMessageDialog(null, "Exception occurred reading file.\n\n" + ex); 301 return false; 302 } 303 304 // File loaded successfully 305 return true; 285 boolean success = true; 286 FileInputStream fileIn = null; 287 try { 288 // Open the file with a FileInputStream, ready for parsing 289 fileIn = new FileInputStream(rogFile); 290 291 // Get the number of bytes in the file 292 int rogLength = fileIn.available(); 293 294 // Create a buffer to store the file, and read the file into it 295 byte[] rogData = new byte[rogLength]; 296 fileIn.read(rogData, 0, rogLength); 297 298 // Parse the .rog file 299 parseFile(rogData, rogLength); 300 } catch (Exception ex) { 301 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred reading file.\n\n" + ex); 302 success = false; 303 } finally { 304 if (fileIn != null) { 305 try { 306 fileIn.close(); 307 } catch (IOException e) { 308 // If an IO exception occurs when closing the file, just sweep it under the rug 309 } 310 } 311 } 312 313 // File loaded successfully 314 return success; 306 315 } 307 316 … … 406 415 // Check that the noteName is valid 407 416 if (noteName < 'A' || noteName > 'G') { 408 JOptionPane.showMessageDialog(null, "Parsing error - check that the Rog file is valid.");417 EcosystemManager.getGraphicsManager().showDialog("Exception", "Parsing error - check that the Rog file is valid."); 409 418 return; 410 419 } … … 497 506 } 498 507 catch (Exception ex) { 499 JOptionPane.showMessageDialog(null, "Exception occurred writing to file.\n\n" + ex);508 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred writing to file.\n\n" + ex); 500 509 return false; 501 510 } -
trunk/src/org/apollo/meldex/StandardisedMelody.java
r315 r1102 93 93 94 94 // Read the melody from the melody file 95 return (StandardisedMelody) melodyFileStream.readObject(); 95 StandardisedMelody standardisedMelody = (StandardisedMelody) melodyFileStream.readObject(); 96 97 melodyFileStream.close(); 98 99 return standardisedMelody; 96 100 97 101 } -
trunk/src/org/apollo/meldex/Transcriber.java
r315 r1102 4 4 import java.util.ArrayList; 5 5 6 @SuppressWarnings("unchecked") // code in java 1.47 6 public class Transcriber 8 7 { … … 255 254 { 256 255 // Pitch track the note 257 ArrayList pitchData = pitchTracker.process(data, length, sampleRate);256 ArrayList<PitchValue> pitchData = pitchTracker.process(data, length, sampleRate); 258 257 259 258 // Average the pitch data … … 265 264 266 265 267 private int averagePitchData(ArrayList pitchData)266 private int averagePitchData(ArrayList<PitchValue> pitchData) 268 267 { 269 268 // Loop through the pitch values... 270 269 int i = 0, k = 0; 271 270 while (i < (pitchData.size() - 1)) { 272 int startPos = ((PitchValue) pitchData.get(i)).position;273 double period = ((PitchValue) pitchData.get(i)).period;271 int startPos = pitchData.get(i).position; 272 double period = pitchData.get(i).period; 274 273 double averagePeriod = period; 275 double runningPeriod = ((PitchValue) pitchData.get(i+1)).position - startPos;274 double runningPeriod = pitchData.get(i+1).position - startPos; 276 275 double numPeriods = runningPeriod / period; 277 276 … … 280 279 while ((i+j) < (pitchData.size() - 1)) { 281 280 // Get the next pitch estimate 282 period = ((PitchValue) pitchData.get(i+j)).period;283 int position = ((PitchValue) pitchData.get(i+j)).position;281 period = pitchData.get(i+j).period; 282 int position = pitchData.get(i+j).position; 284 283 285 284 // Make sure that this period is covered by the average so far … … 289 288 290 289 // Stop if we have covered more than 20 msec 291 int nextPos = ((PitchValue) pitchData.get(i+j+1)).position;290 int nextPos = pitchData.get(i+j+1).position; 292 291 // if ((nextPos - startPos) >= 445) { // !! PURE-ROG !! 293 292 if ((nextPos - startPos) >= (sampleRate * 0.02)) { … … 315 314 316 315 317 private int calculateHistogram(ArrayList data, int length)316 private int calculateHistogram(ArrayList<PitchValue> data, int length) 318 317 { 319 318 // This probably shouldn't be a constant … … 328 327 // Calculate the histogram data 329 328 for (int i = 0; i < (length - 1); i++) { 330 double period = ((PitchValue) data.get(i)).period;331 double position = ((PitchValue) data.get(i)).position;332 double periodLength = ((PitchValue) data.get(i+1)).position - position;329 double period = data.get(i).period; 330 double position = data.get(i).position; 331 double periodLength = data.get(i+1).position - position; 333 332 334 333 // We only need to do this if the pitch does not equal zero -
trunk/src/org/apollo/meldex/WavSample.java
r315 r1102 8 8 import javax.sound.sampled.AudioInputStream; 9 9 import javax.sound.sampled.AudioSystem; 10 import javax.swing.JOptionPane; 11 12 @SuppressWarnings("unchecked") // code in java 1.4 10 11 import org.expeditee.gio.EcosystemManager; 12 13 13 public class WavSample 14 14 { … … 68 68 } 69 69 catch (Exception ex) { 70 JOptionPane.showMessageDialog(null, "Exception occurred creating sample.\n\n" + ex);70 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred creating sample.\n\n" + ex); 71 71 return false; 72 72 } … … 90 90 } 91 91 catch (Exception ex) { 92 JOptionPane.showMessageDialog(null, "Exception occurred reloading sample.\n\n" + ex);92 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred reloading sample.\n\n" + ex); 93 93 return false; 94 94 } … … 101 101 } 102 102 catch (Exception ex) { 103 JOptionPane.showMessageDialog(null, "Exception occurred resetting audio stream.\n\n" + ex);103 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred resetting audio stream.\n\n" + ex); 104 104 return false; 105 105 } … … 172 172 if (format.getSampleSizeInBits() == 8) { 173 173 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { 174 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (signed 8-bit).");174 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (signed 8-bit)."); 175 175 return null; 176 176 } … … 178 178 if (format.getSampleSizeInBits() == 16) { 179 179 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) { 180 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (unsigned 16-bit).");180 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (unsigned 16-bit)."); 181 181 return null; 182 182 } … … 188 188 189 189 // Create a new list to store the standardised sample values 190 ArrayList stdTemp = new ArrayList();190 ArrayList<Integer> stdTemp = new ArrayList<Integer>(); 191 191 192 192 // Simply pick values from the sample at the frequency specified … … 218 218 219 219 220 private static ArrayList toStandardEndian(AudioFormat format, ArrayListinData)221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed223 if (format.getSampleSizeInBits() == 8) {224 return inData;225 }226 227 // Create a new list to store the results228 ArrayList outData = new ArrayList();229 230 // Simply convert each number in the sample to the endian form for the current system231 for (int i = 0; i < inData.size(); i += 2) {232 233 int MSB, LSB;234 if (format.isBigEndian()) {235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order)236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order)237 }238 else {239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order)240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order)241 }242 243 int val = (MSB << 8) + (LSB & 255);244 outData.add(new Integer(val));245 }246 247 return outData;248 } 249 250 251 private static ArrayList toUnsignedValues(AudioFormat format, ArrayListinData)220 private static ArrayList<Integer> toStandardEndian(AudioFormat format, ArrayList<Integer> inData) 221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed 223 if (format.getSampleSizeInBits() == 8) { 224 return inData; 225 } 226 227 // Create a new list to store the results 228 ArrayList<Integer> outData = new ArrayList<Integer>(); 229 230 // Simply convert each number in the sample to the endian form for the current system 231 for (int i = 0; i < inData.size(); i += 2) { 232 233 int MSB, LSB; 234 if (format.isBigEndian()) { 235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order) 236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order) 237 } 238 else { 239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order) 240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order) 241 } 242 243 int val = (MSB << 8) + (LSB & 255); 244 outData.add(new Integer(val)); 245 } 246 247 return outData; 248 } 249 250 251 private static ArrayList<Integer> toUnsignedValues(AudioFormat format, ArrayList<Integer> inData) 252 252 { 253 253 // PCM_UNSIGNED samples are what we want, so no conversion needed … … 257 257 258 258 // Create a new list to store the results 259 ArrayList outData = new ArrayList();259 ArrayList<Integer> outData = new ArrayList<Integer>(); 260 260 261 261 // Simply convert each signed number in the sample to an unsigned value … … 275 275 276 276 277 private static ArrayList to8bit(AudioFormat format, ArrayListinData)277 private static ArrayList<Integer> to8bit(AudioFormat format, ArrayList<Integer> inData) 278 278 { 279 279 // 8-bit data is what we want, so no conversion necessary … … 283 283 284 284 // Create a new list to store the results 285 ArrayList outData = new ArrayList();285 ArrayList<Integer> outData = new ArrayList<Integer>(); 286 286 287 287 // Simply reduce each value in the sample to an 8-bit value … … 298 298 299 299 300 private static ArrayList toMono(AudioFormat format, ArrayListinData)300 private static ArrayList<Integer> toMono(AudioFormat format, ArrayList<Integer> inData) 301 301 { 302 302 // Mono-channel data is what we want, so no conversion necessary … … 306 306 307 307 // Create a new list to store the results 308 ArrayList outData = new ArrayList();308 ArrayList<Integer> outData = new ArrayList<Integer>(); 309 309 310 310 // Simply average all of the channels for each frame … … 362 362 try { 363 363 if (AudioSystem.write(audioData, AudioFileFormat.Type.WAVE, outFile) == -1) { 364 JOptionPane.showMessageDialog(null, "Problem occurred writing to file.");364 EcosystemManager.getGraphicsManager().showDialog("Exception", "Problem occurred writing to file."); 365 365 return false; 366 366 } 367 367 } 368 368 catch (Exception ex) { 369 JOptionPane.showMessageDialog(null, "Exception occurred saving file.\n\n" + ex);369 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred saving file.\n\n" + ex); 370 370 return false; 371 371 }
Note:
See TracChangeset
for help on using the changeset viewer.