Guest User

Untitled

a guest
Oct 19th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. //get input line:
  2. TargetDataLine line;
  3. DataLine.Info info = new DataLine.Info(TargetDataLine.class,
  4. format); // format is an AudioFormat object
  5. if (!AudioSystem.isLineSupported(info)) {
  6. // Handle the error.
  7. }
  8. // Obtain and open the line.
  9. try {
  10. line = (TargetDataLine) AudioSystem.getLine(info);
  11. line.open(format);
  12. } catch (LineUnavailableException ex) {
  13. // Handle the error.
  14. //...
  15. }
  16.  
  17. //capture sound:
  18. ByteArrayOutputStream out = new ByteArrayOutputStream();
  19. int numBytesRead;
  20. byte[] data = new byte[line.getBufferSize() / 5];
  21.  
  22. // Begin audio capture.
  23. line.start();
  24.  
  25. // Here, stopped is a global boolean set by another thread.
  26. while (!stopped) {
  27. // Read the next chunk of data from the TargetDataLine.
  28. numBytesRead = line.read(data, 0, data.length);
  29. // Save this chunk of data.
  30. out.write(data, 0, numBytesRead);
  31. }
  32.  
  33. // inversing incomming sound:
  34. for(int i = 0; i < readBytes; i+=2)
  35. {
  36. inverse = (short)(data[i+1] << 8 | data[i] & 0xff);
  37. System.out.println(inverse/100);
  38. data[i] = (byte) (inverse & 0xff);
  39. data[i+1] = (byte) ((inverse >> 8) & 0xff);
  40. }
  41.  
  42. sourceLine.write(data, 0, readBytes);
Add Comment
Please, Sign In to add comment