Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get input line:
- TargetDataLine line;
- DataLine.Info info = new DataLine.Info(TargetDataLine.class,
- format); // format is an AudioFormat object
- if (!AudioSystem.isLineSupported(info)) {
- // Handle the error.
- }
- // Obtain and open the line.
- try {
- line = (TargetDataLine) AudioSystem.getLine(info);
- line.open(format);
- } catch (LineUnavailableException ex) {
- // Handle the error.
- //...
- }
- //capture sound:
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- int numBytesRead;
- byte[] data = new byte[line.getBufferSize() / 5];
- // Begin audio capture.
- line.start();
- // Here, stopped is a global boolean set by another thread.
- while (!stopped) {
- // Read the next chunk of data from the TargetDataLine.
- numBytesRead = line.read(data, 0, data.length);
- // Save this chunk of data.
- out.write(data, 0, numBytesRead);
- }
- // inversing incomming sound:
- for(int i = 0; i < readBytes; i+=2)
- {
- inverse = (short)(data[i+1] << 8 | data[i] & 0xff);
- System.out.println(inverse/100);
- data[i] = (byte) (inverse & 0xff);
- data[i+1] = (byte) ((inverse >> 8) & 0xff);
- }
- sourceLine.write(data, 0, readBytes);
Add Comment
Please, Sign In to add comment