houbysoft
houbysoft

Reputation: 33402

Using AVAudioPlayer for piano samples -- memory management

I am writing a simple iOS app that will include a piano.

I only need something very basic, and I'm probably going with this approach:

My understanding is that one AVAudioPlayer instance can only be used with one sound. Therefore, I'd have to create many AVAudioPlayers (88 to be precise), one for every piano key.

My question is, how memory-intensive is AVAudioPlayer? Can I just initialize the program by creating 88 AVAudioPlayers, keeping them in memory, and using them as appropriate? Or is the memory footprint of an AVAudioPlayer too big, and should I only alloc/release the AVAudioPlayers as necessary? If so, will allocating/releasing the players be quick enough so that the user doesn't notice any lag?

Upvotes: 0

Views: 382

Answers (1)

spring
spring

Reputation: 18497

This project uses OpenAL SoundBankPlayer as a solution for that functionality. Another approach is to use a soundFont and a Sampler AudioUnit. Very optimized for music creation type apps. Good details and source code: AudioGraph

Upvotes: 1

Related Questions