jcdale
Posts: 1
Joined: Sat Jun 15, 2019 1:17 pm

Having Trouble Stopping Audio Capture with Java

Sat Jun 15, 2019 1:22 pm

I also posted this over at the Adafruit forums. They referred me here, where I hope to get a little help.

https://forums.adafruit.com/viewtopic.p ... 55#p754955

----- clip -----

Greetings;

So, I got the sound card and with no modification I could capture and process my audio stream!

Lovely.

However, I can't seem to stop the target data line in Java.

I read up on this a little and discovered some issues with little vs big endian, but in examining my code, I was in compliance.

Here's my target format .. when I call "drain" and "close" on the target data line, it doesn't stop .. just keeps on capturing:

final AudioFormat format = new AudioFormat(44100.0F, 16, 1, true, false);

Any ideas?

Again, just to note, I can capture the audio just fine and process .. just can't stop!

Sincerely,

John

----- /clip -----

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

Raspbian GNU/Linux 8 (jessie)

Thanks!

John

knute
Posts: 427
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Having Trouble Stopping Audio Capture with Java

Sat Jun 15, 2019 5:52 pm

You don't say what device the TargetDataLine is connected to. If connected to a device such as a microphone, drain() will never return because the mixer connected to the microphone will continue to send data to the TargetDataLine's buffer which drain() will attempt to empty but never succeed. Just call stop() and then close() and you should be good to go.

Return to “Java”