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

Just noise...



Hi,

I'm having problems reading aiff-files from disk (a aiff-c file). I'm just getting noise when I play it. I'm playing it using a SndHandle and a SndChannel, I think the rest of code works because when I tried to fill the bytes "by hand" it sounded okey.

From what I've learned about the SoundManager I should be able to have almost any kind of aiff in the byte[] and SndChannel.play() should understand what it is and play it.

My source for getting the sound:

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]; // So I don't get a warning when I compile ("media may not have been initialized"), I know this is bad but this is just a test app

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

System.out.println("ava:"+stream.available());
media = new byte[stream.available()];
stream.read(media);
System.out.println("done reading");

}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 ///

System.out.println("sound loading completed");
}catch(QTException e){}

return sndHandle;
}

Regards Emil

ps.
Sorry for spamming the list with my newbie questions.
ds.
--
Emil Edeholt




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.