Newer
Older
Import / applications / RocketMan / Source Code / Music.mm
/*
 *  Music.mm
 *  iphone-gl-app
 *
 *  Created by John Ryland on 14/06/09.
 *  Copyright 2009 InvertedLogic. All rights reserved.
 *
 */

#include "Debug.h"
#include <AVFoundation/AVFoundation.h>
#include "Music.h"


Music::Music()
{
	dptr = 0;
}


void Music::playMusic(const char *file)
{
	/*
	// Using AVAudioPlayer
	NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"music" ofType: @"mp3"];
	NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
	AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
	//	dptr = (void *)newPlayer;
	[newPlayer prepareToPlay];
	// [player setDelegate: self];
	[newPlayer play];
	//[fileURL release];
	 */
}



/*	
 int channelGroups[1];
 channelGroups[0] = 8;
 soundEngine = [[CDSoundEngine alloc] init:channelGroups channelGroupTotal:1];
 
 int i=0;
 for(NSString *soundName in [NSArray arrayWithObjects:@"base1", @"snare1", @"hihat1", @"dit", @"snare", nil])
 {
 [soundEngine loadBuffer:i fileName:soundName fileType:@"wav"];
 i++;
 }
 
 [NSTimer scheduledTimerWithTimeInterval:0.14 target:self selector:@selector(drumLoop:) userInfo:nil repeats:YES];
 

 
 - (void)drumLoop:(NSTimer *)timer
 {
 for(int track=0; track<4; track++)
 {
 unsigned char note=pattern[track][step];
 if(note)
 [soundEngine playSound:note-1 channelGroupId:0 pitch:1.0f pan:.5 gain:1.0 loop:NO];
 }
 
 if(++step>=16)
 step=0;
 
 }
 */

/*

nextBeat=[[NSDate alloc] initWithTimeIntervalSinceNow:0.1];
[NSThread detachNewThreadSelector:@selector(drumLoop:) toTarget:self withObject:nil];



- (void)drumLoop:(id)info
{
	[NSThread setThreadPriority:1.0];
	
	while(1)
	{
		for(int track=0; track<4; track++)
		{
			unsigned char note=pattern[track][step];
			if(note)
				[soundEngine playSound:note-1 channelGroupId:0 pitch:1.0f pan:.5 gain:1.0 loop:NO];
		}
		
		if(++step>=16)
			step=0;     
			
			NSDate *newNextBeat=[[NSDate alloc] initWithTimeInterval:0.1 sinceDate:nextBeat];
			[nextBeat release];
		nextBeat=newNextBeat;
		[NSThread sleepUntilDate:nextBeat];
	}
}

 */