Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Just noise...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Just noise...



>ok, I remember now.
>
>do you use a QTHandle or a QTPointer for the sample data? they're
>pretty easy to wrap for efficient byte access and you know they're
>contiguous blocks etc.

SndHandle (which extends QTHandle).

java.lang.Object
|
+--quicktime.QTObject
|
+--quicktime.util.QTHandleRef
|
+--quicktime.util.QTHandle
|
+--quicktime.sound.SndHandle


>maybe what you should do is make a test sound movie containing the
>audio you want, read the sample data in from the movie and try
>playing those sample using your routines - at least the format
>should be known good?

Mmm, but I have no idea of how to get the byte[] from the sound
movie, which I would need since that seems to be the only way
SndHandle can recive data, and SndHandle is the only thing SndChannel
seems to be able to play.

I've tried to fill the byte[] by hand, and that sounded as I
expected, so I think the error is the reading not the play back.

This is my source (I've commented away the code for creating the
byte[] sound "by hand"):

public SndHandle getSound(String fileName)
{
SndHandle sndHandle = null;

try
{
sndHandle = new SndHandle();

/*byte[] media = new byte[64000];
short val = -32768;

for (int i = 0; i < media.length; i+=2) {
if (val > 32750)
val = -32768;
val+=16;
media[i] = (byte)((val | 0xFF00) >>> 8);
media[i + 1] = (byte)val;
}*/
byte[] media = new byte[100];

try
{
URL url = new URL(fileName);
InputStream stream = url.openStream();

media = new byte[stream.available()];
stream.read(media);

}catch(IOException e)
{
System.out.println("IO Exception: "+e);
}


/// SETUP HANDLE ///
sndHandle.setupHeader (1, 11050, 16,
SoundConstants.k16BitBigEndianFormat, 0, media.length);

// allocates the extra memory for the sound
buffer in the SndHandle
sndHandle.appendSoundBuffer (media.length);
QTPointerRef qtpr=sndHandle.getSoundData();
qtpr.copyFromArray (0,media,0,media.length);
/// SETUP HANDLE ///
}catch(QTException e){}

return sndHandle;
}

Thanks for your help! =)

Regards Emil




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.