Playback of large WAV files...

E

ew75

I'm writing an application to play a large WAV file (say a couple
hundred of megs), and allow the user to jump to / select a position in
the file (e.g. 120 seconds into it) to start playback. The "skip"
method of AudioInputStream always seems to return the value "4096",
meaning it skipped 4K, no matter how far I actually tell it to skip.
While a "Clip" would seem to be the ideal method, it doesn't support
large files (over 5 meg?).

Anybody else do something similar and want to share some advice? Or
have any idea why "skip" doesn't skip to where I want it?
 
A

Andrew Thompson

I'm writing an application to play a large WAV file (say a couple
hundred of megs),

That is *huge*. What compression are these files using?
If using an efficient form osf compression, the files will
become much larger still, in memory.
..and allow the user to jump to / select a position in
the file (e.g. 120 seconds into it) to start playback. The "skip"
method of AudioInputStream always seems to return the value "4096",
meaning it skipped 4K, no matter how far I actually tell it to skip.

While a "Clip" would seem to be the ideal method, it doesn't support
large files (over 5 meg?).

Perhaps you need to break the files into smaller parts.
Anybody else do something similar and want to share some advice? Or
have any idea why "skip" doesn't skip to where I want it?

The secret to that lies in the JavaDocs for the next-listed method.
<http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/sampled/AudioInputStream.html#available()>

Andrew T.
 
O

Oliver Wong

The "skip"
method of AudioInputStream always seems to return the value "4096",
meaning it skipped 4K, no matter how far I actually tell it to skip. [...]
Anybody else do something similar and want to share some advice? Or
have any idea why "skip" doesn't skip to where I want it?

Andrew Thompson said:

available() will only tell you how many bytes can be read without
blocking. You're free to request a read of more than that many bytes; it
simply means your request will (probably) cause some blocking.

To the OP, did you try values which are multiples of 4096? E.g. 8192 or
12288? Skip will "round" to the nearest frame. Maybe all your frames are
4096 bytes in size.

- Oliver
 
K

Knute Johnson

I'm writing an application to play a large WAV file (say a couple
hundred of megs), and allow the user to jump to / select a position in
the file (e.g. 120 seconds into it) to start playback. The "skip"
method of AudioInputStream always seems to return the value "4096",
meaning it skipped 4K, no matter how far I actually tell it to skip.
While a "Clip" would seem to be the ideal method, it doesn't support
large files (over 5 meg?).

Anybody else do something similar and want to share some advice? Or
have any idea why "skip" doesn't skip to where I want it?

My guess is that you can't skip beyond the limits of the buffer in the
AudioInputStream. I would try using a FileInputStream and see if that
allows you to skip to where you want. Then read the file and write the
data to a SourceDataLine.
 
M

Matt Humphrey

I'm writing an application to play a large WAV file (say a couple
hundred of megs), and allow the user to jump to / select a position in
the file (e.g. 120 seconds into it) to start playback. The "skip"
method of AudioInputStream always seems to return the value "4096",
meaning it skipped 4K, no matter how far I actually tell it to skip.
While a "Clip" would seem to be the ideal method, it doesn't support
large files (over 5 meg?).

Anybody else do something similar and want to share some advice? Or
have any idea why "skip" doesn't skip to where I want it?

If you're using JMF (or would like to), the book "Swing Hacks" by Marinacci
and Adamson show how to progressively load and play audio media. The code
samples there are excellent.

Matt Humphrey (e-mail address removed) http://www.iviz.com/
 
B

Brandon McCombs

Andrew said:
That is *huge*. What compression are these files using?
If using an efficient form osf compression, the files will
become much larger still, in memory.

Not really. A typical MP3 of a song is about 4 or 5 megs at 192kbps
(exact size dependent on song length of course). With MP3 you can expect
about a 5:1 compression ratio so the original WAV is approximately 50
megabytes. He is working with files then about 4 times the size of a
typical song (~4 minutes long). He may very well be working with a 20
minute file with average bitrate or a shorter file with high bitrate.
WAV is not usually compressed and contains data in PCM format which
explains why files can be, as you say, *huge*. In reality, they aren't
huge for that format because they aren't compressed. But are they huge
compared to their compressed MP3 cousin? You could make that argument.

Brandon
 
H

HMBA

Just wanted to follow up with a thank you for all of the feedback. The
heads-up re: buffer size and blocking, and the references to JMF
reading material were helpful and greatly appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top