• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javasound + latency

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm experimenting with a little applet that makes the keyboard function as a musical keyboard. I'm wondering what is the most effective way to do this, so to keep the latency to a minimum (i.e., the time between pushing a key and hearing the sound).

Presently, I have a waveform stored in an int[] array, and when I want to hear it, I just cycle through it. When I want to change the pitch, I cycle through at some fixed number of steps. The waveform is pre-rendered to a very high resolution so that this skipping through it doesn't produce noticable distortion.

My dataline is opened with a buffer of 2/10ths of a second worth of bytes, and there is a loop that writes to the buffer a total of 1/10th-sec of bytes with each iteration, copying into the buffer my waveform in 1/10th sec blocks.

If you have worked with sound, probably you can guess that this technique causes a bit of latency. If I try to make the buffers any smaller, though, the sounds get chopped up.

Somehow there needs to be a balance between size of buffer, which gives more continuity in the sound, and immediacy of response, so that the user can feel like he's playing an instrument.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic