As I am a little dyslexic I am attempting to write for myself a spelling tutor application. I can record and playback the words I need for a spelling list. The first two or three words record and playback ok, but after that the playback becomes very distorted and choppy. Can somebody please point me in the correct direction to resolve this issue? Thanks.
If stopCapture is never set to true, your while (!stopCapture) loop will never exit. Each time you captureAudio() you'll create a new thread. I'd expect that there's actually data coming in on targetDataLine even when you're not recording, it'll just be silence being recorded.
The first time you record, you have one recorder running.
The second time you hit record, you have two recorders running.
The third time you have three and so on.
As to the reason it's choppy, when you have only one recorder running that recorder gets all of the information. (sample rate 48000)
When you have two running they "fight" for the info. That is, each one quickly loops and grabs all the information (probably only a few bytes) off the audio line. So your sample rate is probably halved but you don't notice it much since it's still pretty good. (sample rate 24000)
As it continues though, there are more recorders fighting for the info, the sample rate is essentially split more ways. It's impossible to predict which recorder will get which bytes as it's completely dependent on what order your processor schedules the threads to run in. (16000, 12000, 9600, 8000, 6850... it's easy to see how quickly the sound will become choppy as the number of recorders increases.)
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
posted 8 years ago
Thank you so much for the help. You were spot on.
The problem was dummy error and not engaging brain when reading the code.
I called the stop audio capture boolean
in the stop buttons event
listener and created it again in error after coming back to coding the next day and