Re: AVAudioPlayer: Second instance of same sound...
Re: AVAudioPlayer: Second instance of same sound...
- Subject: Re: AVAudioPlayer: Second instance of same sound...
- From: uɐıʇəqɐz pnoqɥɒɯ <email@hidden>
- Date: Wed, 18 Nov 2009 04:21:09 -0800
Thank you. I spent a good 14 or more hours trying to see if this
would work but I couldn't get beyond playing even a single instance of
a 17MByte files. I might be stumbling on a bug in afconvert since
my .aif can be played by AVAudioPlayer without trouble and the .caf
versions that afconvert puts out does not. I filed a radar: 7404122
(The sounds play fine using QuickTime and the Finder's preview)
I'm glad that your responses indicate that I can likely accomplish my
goal. With respect to your second response, could you tell me: then
what does -prepareToPlay do? Does it load up a larger chunk of data
initially? I have never yet noticed a difference in the playing
latency of sounds with or without -prepareToPlay, and am not sure if I
even really need to call it. Can you tell me more about prepareToPlay?
Now, given that I want to play an arbitrary part of the sound file for
only a second or two, how should I stop the playback? I am currently
testing with -performSelector:AfterDelay or can use an NSTimer. Or do
you recommend other ways that are better?
Thank you,
mz
On Nov 17, 2009, at 1:14 PM, William Stewart wrote:
We don't do a couple of things here.
(1) There is no common code in AVAP that would look to see if we
already have that file loaded, and then load it again
(2) AVAP does NOT load the entire contents of the file into memory.
Rather it establishes a set of buffers (small) for reading data from
the disk, and as you play it back, it reads data just ahead of where
you are playing. This overhead is the same for every AVAP object you
create. You can seek around a file that you have opened, so you
could certainly do that (have a large file and play segments from it)
On Nov 16, 2009, at 10:54 PM, uɐıʇəqɐz pnoqɥɒɯ wrote:
Hi. This is an iPhone question. I am wondering if AVAudioPlayer
cache's sound files such that the loading of the second instance of
the same sound file doesn't take up additional memory.
In other words:
if fileURL points to a 15 megabyte sound file, and you call
newPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:
fileURL error: nil];
newPlayer2 = [[AVAudioPlayer alloc] initWithContentsOfURL:
fileURL error: nil];
would the second call consume the same amount of memory as the
first one? Or will the second call's memory usage be limited to
just a few dozen or less bytes?
What Am I Really Trying To Do?
I have many sound files, each about 500K that I play, sometimes
playing the same sound, two or more times in an overlapping
fashion. In order to play the same sound overlapped, I have to
load that sound twice in order to give each an independent -play.
This all works great.
In order to make the creation of these 400+ sounds a bit easier, I
would like to combine them and group them into single sound files
with 50 sounds in each (18-20MB per file), and then before I call -
play, I specify an offset to start playing at, and cut off the
playback after a delay. I am currently making the changes and
realized that I will have to handle the case that two sounds from
the same file will play concurrently, much more often. In fact, I
could easily have 4, 5 or more sounds from the same file playing
simultaneously. That means I would have to call -
initWithContentsOfURL multiple times in order to play a second,
third, fourth... sound from that file. If each instance of this
sound file takes up 18-20 MB, then my iPhone app is going have
serious problems after the second instance.
Alternatively, I can write a separate Mac application that opens up
each of my larger combined files, and reads out the sounds at each
offset and saves them to smaller files, as I am currently using,
except, of course, I am sure it is not as easy as just opening a
file, moving to a location x seconds times sample rate in, grab y
seconds of data, and write it out, and have a valid sound file. Is
there already a utility such as afconvert that can do this for me?
Thank you in advance for any thoughts and advice!
-mahboud
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@apple.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden