Question

i have just created a drum app. The user taps on the individual buttons which triggers a short sound to play using the systemsound from AudioToolbox. I now would like to add a UIButton which says "record", and upon click, will record all Systemsounds being played, and then when the use presses the stop button; the program should then be able to playback the sound.

How do i go about doing this?! The whole process of the program being able to record the short sounds that the user triggers by tapping on the individual hit areas?!

Please let me know

Thanks

Pavan

Was it helpful?

Solution

I'm not familiar with the audio hardware within the iPhone itself, but since it does not expose any internal synthesization routines I wouldn't be surprised if its not possible to capture the outbound audio for reprocessing.

I suspect you will find it much easier, particularly if you're not familiar with programming audio hardware directly, to instead record the drum actions and time intervals and replay the the audio files in the same manner as originally played. This would also have the advantage that you could edit, slow down, speed up, and other tricks without altering the audio directly.

As the drums are hit, you'd need to append to an NSMutableArray. The sample below is based on a drumType (tag for the drum button being hit for example), and a drumNextDelay which is the delay (NSTimeInterval) to the next drum hit. There's obviously more ways of handling this, but its just an example.

A rough version of the playback could be implemented by calling performSelector repeatedly with the next time interval, something like the following:

- (void) startPerformance {
self.drumIndex = -1;
[self performSelector:@selector(playDrumBeat) withObject:nil afterDelay:0];
}

- (void) playDrumBeat {
self.drumIndex++;
[self playDrum:[[drumBeats objectAtIndex:self.drumIndex] drumType]];
[self performSelector:@selector(playDrumBeat) withObject:nil afterDelay:[[drumBeats objectAtIndex:self.drumIndex] drumNextDelay]];
}

This can be prone to timing issues with the OS, but I'd pursue something like this for a first cut and see if it works.

Barney

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top