-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioOutput.mm
More file actions
597 lines (554 loc) · 20.9 KB
/
AudioOutput.mm
File metadata and controls
597 lines (554 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
//
// AudioOutput.m
// Miso Music InstrumentView Test
//
// Created by Ryan Hiroaki Tsukamoto on 2/28/11.
// Copyright 2011 Miso Media Inc. All rights reserved.
//
#import "AudioOutput.h"
ALvoid alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq)
{
static alBufferDataStaticProcPtr proc = NULL;
if (proc == NULL) proc = (alBufferDataStaticProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alBufferData");
// if (proc == NULL) proc = (alBufferDataStaticProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alBufferDataStatic");
if (proc) proc(bid, format, data, size, freq);
}
void* MyGetOpenALAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate)
{
OSStatus err = noErr;
SInt64 theFileLengthInFrames = 0;
AudioStreamBasicDescription theFileFormat;
UInt32 thePropertySize = sizeof(theFileFormat);
ExtAudioFileRef extRef = NULL;
void* theData = NULL;
AudioStreamBasicDescription theOutputFormat;
UInt32 dataSize;
err = ExtAudioFileOpenURL(inFileURL, &extRef);
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileOpenURL FAILED, Error = %ld\n", err); goto Exit; }
err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileDataFormat, &thePropertySize, &theFileFormat);
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileDataFormat) FAILED, Error = %ld\n", err); goto Exit; }
if (theFileFormat.mChannelsPerFrame > 2) { printf("MyGetOpenALAudioData - Unsupported Format, channel count is greater than stereo\n"); goto Exit;}
theOutputFormat.mSampleRate = theFileFormat.mSampleRate;
theOutputFormat.mChannelsPerFrame = theFileFormat.mChannelsPerFrame;
theOutputFormat.mFormatID = kAudioFormatLinearPCM;
theOutputFormat.mBytesPerPacket = 2 * theOutputFormat.mChannelsPerFrame;
theOutputFormat.mFramesPerPacket = 1;
theOutputFormat.mBytesPerFrame = 2 * theOutputFormat.mChannelsPerFrame;
theOutputFormat.mBitsPerChannel = 16;
theOutputFormat.mFormatFlags = kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
err = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat);
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileSetProperty(kExtAudioFileProperty_ClientDataFormat) FAILED, Error = %ld\n", err); goto Exit; }
thePropertySize = sizeof(theFileLengthInFrames);
err = ExtAudioFileGetProperty(extRef, kExtAudioFileProperty_FileLengthFrames, &thePropertySize, &theFileLengthInFrames);
if(err) { printf("MyGetOpenALAudioData: ExtAudioFileGetProperty(kExtAudioFileProperty_FileLengthFrames) FAILED, Error = %ld\n", err); goto Exit; }
dataSize = theFileLengthInFrames * theOutputFormat.mBytesPerFrame;
//UInt32 dataSize = theFileLengthInFrames * theOutputFormat.mBytesPerFrame;
theData = malloc(dataSize);
if (theData)
{
AudioBufferList theDataBuffer;
theDataBuffer.mNumberBuffers = 1;
theDataBuffer.mBuffers[0].mDataByteSize = dataSize;
theDataBuffer.mBuffers[0].mNumberChannels = theOutputFormat.mChannelsPerFrame;
theDataBuffer.mBuffers[0].mData = theData;
err = ExtAudioFileRead(extRef, (UInt32*)&theFileLengthInFrames, &theDataBuffer);
if(err == noErr)
{
*outDataSize = (ALsizei)dataSize;
*outDataFormat = (theOutputFormat.mChannelsPerFrame > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16;
*outSampleRate = (ALsizei)theOutputFormat.mSampleRate;
}
else
{
free (theData);
theData = NULL;
printf("MyGetOpenALAudioData: ExtAudioFileRead FAILED, Error = %ld\n", err); goto Exit;
}
}
Exit:
if (extRef) ExtAudioFileDispose(extRef);
return theData;
}
@implementation AudioOutput
@synthesize isPlaying = _isPlaying;
@synthesize wasInterrupted = _wasInterrupted;
@synthesize listenerRotation = _listenerRotation;
@synthesize _sources;
@synthesize _sourcePos;
void interruptionListener(void* inClientData, UInt32 inInterruptionState)
{
AudioOutput *THIS = (AudioOutput*)inClientData;
if (inInterruptionState == kAudioSessionBeginInterruption)
{
[THIS destroy_OpenAL];
if ([THIS isPlaying]) {
THIS->_wasInterrupted = YES;
THIS->_isPlaying = NO;
}
}
else if (inInterruptionState == kAudioSessionEndInterruption)
{
OSStatus result = AudioSessionSetActive(true);
if (result) printf("Error setting audio session active! %ld\n", result);
[THIS init_OpenAL];
if (THIS->_wasInterrupted)
{
THIS->_wasInterrupted = NO;
}
}
}
-(id)init_with_instrument:(MM_INSTRUMENT*)p_i
{
if(self = [super init])
{
p_instrument = p_i;
num_strings = mm_instrument_type(p_i->instrument_type_idx).num_courses;
_buffers = (ALuint*)malloc(sizeof(ALuint) * num_strings);
_sources = (ALuint*)malloc(sizeof(ALuint) * num_strings * 2);
_sourcePos = CGPointMake(0., 0.);
_listenerPos = CGPointMake(0., 0.);
_listenerRotation = 0.;
_wasInterrupted = NO;
[self init_OpenAL];
}
return self;
}
-(void)dealloc
{
[self destroy_OpenAL];
[super dealloc];
}
-(void)initBuffer
{
//ALenum error = AL_NO_ERROR;
ALenum format;
ALsizei size;
ALsizei freq;
for(int i = 0; i < num_strings; i++)
{
NSString* file_path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@_%@_open_string_%d", p_instrument->instrument_maker, p_instrument->instrument_name, i] ofType:@"wav"];
if(!file_path) file_path = [NSString stringWithFormat:@"%@/%@_%@_open_string_%d.wav", p_instrument->instrument_sound_path, p_instrument->instrument_maker, p_instrument->instrument_name, i];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(!fileURL)
{
}
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_buffers[i], format, _data, size, freq);
if(_data) free(_data);
}
}
-(void)initSource
{
ALenum error = AL_NO_ERROR;
alGetError(); // Clear the error
float sourcePosAL[] = {_sourcePos.x, _sourcePos.y, kDefaultDistance};
for(int i = 0; i < num_strings * 2; i++)
{
alSourcefv(_sources[i], AL_POSITION, sourcePosAL);
alSourcef(_sources[i], AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_sources[i], AL_BUFFER, _buffers[1]);
alSourcef(_sources[i], AL_GAIN, 1.0f);
alSourcef(_sources[i], AL_MAX_DISTANCE, 4096.0f);
}
if((error = alGetError()) != AL_NO_ERROR)
{
printf("Error attaching buffer to source: %x\n", error);
exit(1);
}
alListenerf(AL_GAIN, 1.0);
}
-(void)init_OpenAL
{
ALenum error;
ALCcontext *newContext = NULL;
ALCdevice *newDevice = NULL;
newDevice = alcOpenDevice(NULL);
if (newDevice != NULL)
{
newContext = alcCreateContext(newDevice, 0);
if (newContext != NULL)
{
alcMakeContextCurrent(newContext);
alGenBuffers(num_strings, &(_buffers[0]));
if((error = alGetError()) != AL_NO_ERROR)
{
printf("Error Generating Buffers: %x", error);
exit(1);
}
alGenSources(num_strings * 2, &(_sources[0]));
if(alGetError() != AL_NO_ERROR)
{
printf("Error generating sources! %x\n", error);
exit(1);
}
alGenBuffers(1, &_tutorial_buffer);
if((error = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((error = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
}
}
alGetError();
[self initBuffer];
[self initSource];
}
-(void)destroy_OpenAL
{
//NSLog(@"tearing down OpenAL");
ALCcontext *context = NULL;
ALCdevice *device = NULL;
int error_num = alGetError();
if(error_num != AL_NO_ERROR) NSLog(@"we were doomed anyway...");
alDeleteSources(2 * num_strings, &(_sources[0]));
error_num = alGetError();
if(error_num == AL_NO_ERROR) NSLog(@"Deleted sources without any errors!");
else NSLog(@"AAAAAH IT'S THE END OF THE WORLD!!");
alDeleteBuffers(num_strings, &(_buffers[0]));
error_num = alGetError();
if(error_num == AL_NO_ERROR) NSLog(@"Deleted buffers without any errors!");
else NSLog(@"AAAAAH IT'S THE END OF THE WORLD!!");
context = alcGetCurrentContext();
device = alcGetContextsDevice(context);
alcDestroyContext(context);
alcCloseDevice(device);
}
-(CGPoint)sourcePos
{
return _sourcePos;
}
-(void)setSourcePos:(CGPoint)SOURCEPOS
{
_sourcePos = SOURCEPOS;
float sourcePosAL[] = {_sourcePos.x, _sourcePos.y, kDefaultDistance};
alSourcefv(_sources[0], AL_POSITION, sourcePosAL);
}
-(CGPoint)listenerPos
{
return _listenerPos;
}
-(void)setListenerPos:(CGPoint)LISTENERPOS
{
_listenerPos = LISTENERPOS;
float listenerPosAL[] = {_listenerPos.x, _listenerPos.y, 0.};
alListenerfv(AL_POSITION, listenerPosAL);
}
-(CGFloat)listenerRotation
{
return _listenerRotation;
}
-(void)setListenerRotation:(CGFloat)radians
{
_listenerRotation = radians;
float ori[] = {cos(radians + M_PI_2), sin(radians + M_PI_2), 0., 0., 0., 1.};
alListenerfv(AL_ORIENTATION, ori);
}
-(void)playString:(int)s andFret:(int)f
{
ALint state;
alGetSourcei(_sources[s], AL_SOURCE_STATE, &state);
if(state == AL_PLAYING)
{
alSourceStop(_sources[s]);
}
alSourcei(_sources[s], AL_BUFFER, _buffers[s % num_strings]);
float qx, qy, qz;
alGetSource3f(_sources[s], AL_POSITION, &qx, &qy, &qz);
//-(void)play_string:(int)s fret:(int)f harmonic:(int)h
//{
// [self play_string:s fret:f];
// float mag = sqrtf(oal_playback._sourcePos.x * oal_playback._sourcePos.x + oal_playback._sourcePos.y * oal_playback._sourcePos.y + kDefaultDistance * kDefaultDistance);
// float v = 343.3 * (1.0 - 1.0 / h);
// alSource3f(oal_playback._sources[s], AL_VELOCITY, -v * oal_playback._sourcePos.x / mag, -v * oal_playback._sourcePos.y / mag, -v * kDefaultDistance / mag);
//}
float h = pow(2.0, f / 12.0);
float mag = sqrtf(qx * qx + qy * qy + qz * qz);
float v = 343.3 * (1.0 - 1.0 / h);
alSource3f(_sources[s], AL_VELOCITY, -v * qx / mag, -v * qy / mag, -v * qz / mag);
alSourcePlay(_sources[s]);
}
-(bool)isStringPlaying:(int)s
{
ALint state;
alGetSourcei(_sources[s], AL_SOURCE_STATE, &state);
return state == AL_PLAYING;
}
-(bool)tutorial_playing //is the tutorial playing?
{
ALint s;
alGetSourcei(_tutorial_source, AL_SOURCE_STATE, &s);
return s == AL_PLAYING;
}
-(void)play_tutorial //do this to play the sound we want.
{
ALint s;
alGetSourcei(_tutorial_source, AL_SOURCE_STATE, &s);
if(s == AL_PLAYING)
{
alSourceStop(_tutorial_source);
}
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcePlay(_tutorial_source);
}
-(void)stop_tutorial
{
alSourceStop(_tutorial_source);
}
-(void)play_intro_tutorial:(int)n
{
ALenum e;
if([self tutorial_playing]) [self stop_tutorial];
alDeleteSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial source");
alDeleteBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial buffer");
alGenBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
ALenum format;
ALsizei size;
ALsizei freq;
NSString* file_path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"tutorial_intro_%d", n] ofType:@"wav"];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(!fileURL) NSLog(@"WTF!!!");
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_tutorial_buffer, format, _data, size, freq);
if(_data) free(_data);
float sourcePosAL[] = {0, 0, 0};
alSourcefv(_tutorial_source, AL_POSITION, sourcePosAL);
alSourcef(_tutorial_source, AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcef(_tutorial_source, AL_GAIN, 1.0f);
alSourcef(_tutorial_source, AL_MAX_DISTANCE, 4096.0f);
if((e = alGetError()) != AL_NO_ERROR)
{
}
alListenerf(AL_GAIN, 1.0);
[self play_tutorial];
}
-(void)play_virtual_instrument_tutorial:(int)n //(safely) loads and plays the nth sound byte for the virtual instrument tutorial
{
ALenum e;
if([self tutorial_playing]) [self stop_tutorial];
alDeleteSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial source");
alDeleteBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial buffer");
alGenBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
ALenum format;
ALsizei size;
ALsizei freq;
NSString* file_path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"vi_tutorial_%d", n] ofType:@"wav"];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(fileURL)
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_tutorial_buffer, format, _data, size, freq);
if(_data) free(_data);
float sourcePosAL[] = {0, 0, 0};
alSourcefv(_tutorial_source, AL_POSITION, sourcePosAL);
alSourcef(_tutorial_source, AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcef(_tutorial_source, AL_GAIN, 1.0f);
alSourcef(_tutorial_source, AL_MAX_DISTANCE, 4096.0f);
if((e = alGetError()) != AL_NO_ERROR)
{
}
alListenerf(AL_GAIN, 1.0);
[self play_tutorial];
}
-(void)play_real_instrument_tutorial:(int)n
{
ALenum e;
if([self tutorial_playing]) [self stop_tutorial];
alDeleteSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial source");
alDeleteBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial buffer");
alGenBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
ALenum format;
ALsizei size;
ALsizei freq;
NSString* file_path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"ri_tutorial_%d", n] ofType:@"wav"];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(fileURL)
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_tutorial_buffer, format, _data, size, freq);
if(_data) free(_data);
float sourcePosAL[] = {0, 0, 0};
alSourcefv(_tutorial_source, AL_POSITION, sourcePosAL);
alSourcef(_tutorial_source, AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcef(_tutorial_source, AL_GAIN, 1.0f);
alSourcef(_tutorial_source, AL_MAX_DISTANCE, 4096.0f);
if((e = alGetError()) != AL_NO_ERROR)
{
}
alListenerf(AL_GAIN, 1.0);
[self play_tutorial];
}
-(void)play_virtual_instrument_tutorial_step:(VI_TUTORIAL_STEP)vi_t_s
{
ALenum e;
if([self tutorial_playing]) [self stop_tutorial];
alDeleteSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial source");
alDeleteBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial buffer");
alGenBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
ALenum format;
ALsizei size;
ALsizei freq;
NSString* step_string;
switch(vi_t_s)
{
case VI_TUTORIAL_DECIDE_HANDEDNESS: { step_string = @"VI_TUTORIAL_DECIDE_HANDEDNESS"; break; }
case VI_TUTORIAL_WELCOME_VIDEO: { step_string = @"VI_TUTORIAL_WELCOME_VIDEO"; break; }
case VI_TUTORIAL_WELCOME_IMAGES: { step_string = @"VI_TUTORIAL_WELCOME_IMAGES"; break; }
case VI_TUTORIAL_STRUM_OPEN_STRINGS: { step_string = @"VI_TUTORIAL_STRUM_OPEN_STRINGS"; break; }
case VI_TUTORIAL_FRET: { step_string = @"VI_TUTORIAL_FRET"; break; }
case VI_TUTORIAL_NOTE: { step_string = @"VI_TUTORIAL_NOTE"; break; }
case VI_TUTORIAL_BARRE: { step_string = @"VI_TUTORIAL_BARRE"; break; }
case VI_TUTORIAL_SCROLLING_TABS: { step_string = @"VI_TUTORIAL_SCROLLING_TABS"; break; }
case VI_TUTORIAL_TAB_0: { step_string = @"VI_TUTORIAL_TAB_0"; break; }
case VI_TUTORIAL_TAB_1: { step_string = @"VI_TUTORIAL_TAB_1"; break; }
case VI_TUTORIAL_TAB_2: { step_string = @"VI_TUTORIAL_TAB_2"; break; }
case VI_TUTORIAL_SHIFT_UP_ipad: { step_string = @"VI_TUTORIAL_SHIFT_UP_ipad"; break; }
case VI_TUTORIAL_SHIFT_UP_iphone: { step_string = @"VI_TUTORIAL_SHIFT_UP_iphone"; break; }
case VI_TUTORIAL_TAB_3: { step_string = @"VI_TUTORIAL_TAB_3"; break; }
case VI_TUTORIAL_SHIFT_DOWN_ipad: { step_string = @"VI_TUTORIAL_SHIFT_DOWN_ipad"; break; }
case VI_TUTORIAL_SHIFT_DOWN_iphone: { step_string = @"VI_TUTORIAL_SHIFT_DOWN_iphone"; break; }
case VI_TUTORIAL_TAB_4: { step_string = @"VI_TUTORIAL_TAB_4"; break; }
case VI_TUTORIAL_TAB_5: { step_string = @"VI_TUTORIAL_TAB_5"; break; }
case VI_TUTORIAL_TAB_REMAINDER: { step_string = @"VI_TUTORIAL_TAB_REMAINDER"; break; }
case VI_TUTORIAL_PAUSE: { step_string = @"VI_TUTORIAL_PAUSE"; break; }
case VI_TUTORIAL_REWIND: { step_string = @"VI_TUTORIAL_REWIND"; break; }
case VI_TUTORIAL_PLAY: { step_string = @"VI_TUTORIAL_PLAY"; break; }
case VI_TUTORIAL_OPEN_SETTINGS: { step_string = @"VI_TUTORIAL_OPEN_SETTINGS"; break; }
case VI_TUTORIAL_SETTINGS: { step_string = @"VI_TUTORIAL_SETTINGS"; break; }
case VI_TUTORIAL_QUIT: { step_string = @"VI_TUTORIAL_QUIT"; break; }
case VI_TUTORIAL_DONE: { step_string = @"VI_TUTORIAL_DONE"; break; }
}
NSString* file_path = [[NSBundle mainBundle] pathForResource:step_string ofType:@"wav"];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(fileURL)
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_tutorial_buffer, format, _data, size, freq);
if(_data) free(_data);
float sourcePosAL[] = {0, 0, 0};
alSourcefv(_tutorial_source, AL_POSITION, sourcePosAL);
alSourcef(_tutorial_source, AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcef(_tutorial_source, AL_GAIN, 1.0f);
alSourcef(_tutorial_source, AL_MAX_DISTANCE, 4096.0f);
if((e = alGetError()) != AL_NO_ERROR)
{
}
alListenerf(AL_GAIN, 1.0);
[self play_tutorial];
}
-(void)play_real_instrument_tutorial_step:(RI_TUTORIAL_STEP)ri_t_s
{
ALenum e;
if([self tutorial_playing]) [self stop_tutorial];
alDeleteSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial source");
alDeleteBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR) NSLog(@"error deleting tutorial buffer");
alGenBuffers(1, &_tutorial_buffer);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
alGenSources(1, &_tutorial_source);
if((e = alGetError()) != AL_NO_ERROR)
{
exit(1);
}
ALenum format;
ALsizei size;
ALsizei freq;
NSString* step_string;
switch(ri_t_s)
{
case RI_TUTORIAL_OPEN_TUNER: { step_string = @"RI_TUTORIAL_OPEN_TUNER"; break; }
case RI_TUTORIAL_TUNER_DISABLED: { step_string = @"RI_TUTORIAL_TUNER_DISABLED"; break; }
case RI_TUTORIAL_TUNER: { step_string = @"RI_TUTORIAL_TUNER"; break; }
case RI_TUTORIAL_SETTINGS: { step_string = @"RI_TUTORIAL_SETTINGS"; break; }
case RI_TUTORIAL_CLOSE_SETTINGS: { step_string = @"RI_TUTORIAL_CLOSE_SETTINGS"; break; }
case RI_TUTORIAL_FINGERING_CHARTS: { step_string = @"RI_TUTORIAL_FINGERING_CHARTS"; break; }
case RI_TUTORIAL_SCROLLING_TABS: { step_string = @"VI_TUTORIAL_SCROLLING_TABS"; break; }
case RI_TUTORIAL_TAB_0: { step_string = @"RI_TUTORIAL_TAB_0"; break; }
case RI_TUTORIAL_TAB_1: { step_string = @"VI_TUTORIAL_TAB_1"; break; }
case RI_TUTORIAL_TAB_2: { step_string = @"VI_TUTORIAL_TAB_2"; break; }
case RI_TUTORIAL_TAB_3: { step_string = @"VI_TUTORIAL_TAB_4"; break; }
case RI_TUTORIAL_TAB_REMAINDER: { step_string = @"VI_TUTORIAL_TAB_REMAINDER"; break; }
case RI_TUTORIAL_PAUSE: { step_string = @"VI_TUTORIAL_PAUSE"; break; }
case RI_TUTORIAL_REWIND: { step_string = @"VI_TUTORIAL_REWIND"; break; }
case RI_TUTORIAL_PLAY: { step_string = @"VI_TUTORIAL_PLAY"; break; }
case RI_TUTORIAL_OPEN_SETTINGS: { step_string = @"VI_TUTORIAL_OPEN_SETTINGS"; break; }
case RI_TUTORIAL_QUIT: { step_string = @"VI_TUTORIAL_QUIT"; break; }
case RI_TUTORIAL_DONE: { step_string = @"RI_TUTORIAL_DONE"; break; }
}
NSString* file_path = [[NSBundle mainBundle] pathForResource:step_string ofType:@"wav"];
CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:file_path] retain];
if(fileURL)
_data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
CFRelease(fileURL);
alBufferDataStaticProc(_tutorial_buffer, format, _data, size, freq);
if(_data) free(_data);
float sourcePosAL[] = {0, 0, 0};
alSourcefv(_tutorial_source, AL_POSITION, sourcePosAL);
alSourcef(_tutorial_source, AL_REFERENCE_DISTANCE, 1024.0f);
alSourcei(_tutorial_source, AL_BUFFER, _tutorial_buffer);
alSourcef(_tutorial_source, AL_GAIN, 1.0f);
alSourcef(_tutorial_source, AL_MAX_DISTANCE, 4096.0f);
if((e = alGetError()) != AL_NO_ERROR)
{
}
alListenerf(AL_GAIN, 1.0);
[self play_tutorial];
}
@end