The audio pad app “Guerrilla Sample Box” is written using the ios 5 sdk and AVAudioPlayer class from AVFoundation.
The app source code can be downloaded from the Pumpún github repository
The part of the code that deals with the audio pad interface and sound manipulation is located at PMPPlayViewController.m. The process of playing sounds is quite simple, and can be divided in 2:
First, a NSMutableArray is created, which holds several AVAudioPlayer objects, one per sound. They are initiated with a pathForResource.
Second, a playButtonPressed method is created, which is fired from buttons located at PlayView nib. Each time they are pressed all sounds are stopped, and the sound related to the tag property of the button starts playing.
#import "PMPPlayViewController.h" @interface PMPPlayViewController () @end @implementation PMPPlayViewController @synthesize statusText; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { sonsMutables = [NSMutableArray arrayWithCapacity:20]; NSError *error; nSons = 20; for (int i= 0; i<nSons; i++) { AVAudioPlayer *playerMutable; NSString *pathMutable = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Sound_%ld", i] ofType:@"mp3"]; playerMutable = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathMutable] error:&error]; playerMutable.volume = 1.0f; [playerMutable prepareToPlay]; [playerMutable setNumberOfLoops:0]; [sonsMutables addObject:playerMutable]; } } return self; } - (void)viewDidLoad{ [super viewDidLoad]; } - (void)viewDidUnload{ [super viewDidUnload]; } - (IBAction)playButtonPressed:(id)sender{ UIButton *button = (UIButton*) sender; int toneIndex = button.tag; for(int i=0; i<nSons; i++){ [[sonsMutables objectAtIndex:i] stop]; } AVAudioPlayer *playerFinal; playerFinal = [sonsMutables objectAtIndex:toneIndex]; [playerFinal setVolume:1.0f]; if([playerFinal isPlaying]){ [playerFinal stop]; } playerFinal.currentTime = 0; [playerFinal play]; NSString *title = [sender titleForState:UIControlStateNormal]; statusText.text = [NSString stringWithFormat:@"%@ ...", title]; } - (IBAction)stopSounds:(id)sender { for(int i=0; i<nSons; i++){ [[sonsMutables objectAtIndex:i] stop]; } } @end |
SoundBOX (Guerrilla Samples Box) is a sound machine that can be used as a citizen tool é unha máquina de son que pretende servir como ferramenta cidadá. Contains chants hymns and other standards that can be heard in public events in Spain.
Almost all sounds were taken from recordings of Pedro Jimenez, Kamen, Chinowski (Tesladream), Grupo Numax and Edu Comelles, all of them were released at Mediateletipos.net as part of the “sound archive #spanishrevolution Yes, we klang!).
, publicado o 25 Xuño, 2012 ás 15:47, gardado en