Memory and music

I have created my sound library, using openAL for sound effects and AVPlayer to play background music. All things are going swimmingly.

So far, I'm using m4a files, but each song in 'non-crunchy' mode takes up between 4 and 8 meg! I look at games like 'Edge' that have 16+ tracks of long, beautiful music and I wonder how the hell it all fits in memory.

Do I give up, and create music algorithmically? I have some background in this type of thing, so it could be done.

Madrayken Wrote:I have created my sound library, using openAL for sound effects and AVPlayer to play background music. All things are going swimmingly.

So far, I'm using m4a files, but each song in 'non-crunchy' mode takes up between 4 and 8 meg! I look at games like 'Edge' that have 16+ tracks of long, beautiful music and I wonder how the hell it all fits in memory.

Do I give up, and create music algorithmically? I have some background in this type of thing, so it could be done.

I'm relatively new to all this, so apologies if this is a silly question:

Would streaming from disk mean that the files would have to be separate from the .app bundle somehow? I've not yet got around to going through the whole packaging for release, and all my assets are part of my Xcode project at the moment, so I'm not sure how I'd do that.

Alternatively, you mean that streaming via AVPlayer should not load the entire file into memory at any point.

Hmm... sounds like I'm doing it already then. The reason this all came to my attention was that my app was crashing when music files were over 4meg. Perhaps the issue is elsewhere, since I'm using AVPlayer's:

Right, since that method name has "ContentsOf" in it, presumably that's to indicate that it slurps the entire file into memory. I don't see anything obvious in AV Foundation that would allow you to play streaming audio, so you may need to drop down to Core Audio or use OpenAL.

I've never run into a problem that made me need to look closer, but my understanding was that AVAudioPlayer loaded the entire compressed audio file into memory and streamed the decompressed audio data out of that.

128kbps AAC files are pretty high quality and not that large. If he's talking about 8MB of memory usage, I assume that he means of uncompressed audio data.

AVAudioPlayer does not load the entire files into memory that I've ever seen (unless it does it in some hidden system area that I can't measure). I'm guessing it just uses Audio Queues behind the scenes. Assuming that it does, then no, it definitely would not load the whole file into memory. If it's crashing on large files, then something else is up, which is why I was suggesting to try a different compressed format.

longjumper Wrote:Running it again, this time playing the AVAudioPlayer after its been loaded, the number of overall allocated bytes continually rises during playback.

[slightly Off-topic]: If it's a small, but continual increase over time, then it's likely a known memory leak associated with Audio Queues. It's definitely not enough to cause much concern though. I've traced a leak in AVAudioPlayer a long time ago and saw that it was from the same system call as the one in Audio Queues (which I reported to Apple and they improved but did not resolve, last I checked), so I think that was one of the things that suggested to me that they are just using Audio Queues for AVAudioPlayer.