• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Java Sound distorted/choppy/repeating on playback

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is stopCapture set to true?

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.)
 
john merritt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

stopAudioCapture

in the stop buttons event
listener and created it again in error after coming back to coding the next day and
called it

stopCapture

when using it in the while loop.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!