This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int gx = 1, gy = 2; // global variable | |
int func(int a ,int b) { | |
int lx, ly; | |
gx = a; | |
gy = b; | |
lx = 9; | |
ly = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const union | |
{ | |
uint8 data[ 88370 ]; | |
uint32 align_me; | |
} audio_buffer_data_data = | |
{ | |
0x52, 0x49, 0x46, 0x46, 0x2A, 0x59, 0x01, 0x00, 0x57, 0x41, 0x56, 0x45, | |
0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, | |
0x22, 0x56, 0x00, 0x00, 0x88, 0x58, 0x01, 0x00, 0x04, 0x00, 0x10, 0x00, | |
0x64, 0x61, 0x74, 0x61, 0xBC, 0x58, 0x01, 0x00, 0xCA, 0x00, 0xCA, 0x00, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)playBeepAudio { | |
// Step 1: Dispose & Stop the last queue | |
if (_queue) { | |
[self stopAudio]; | |
[self disposeAudioQueue]; | |
_queue = nil; | |
} | |
// Step 2: Prepare the description of audio buffer | |
AudioStreamBasicDescription dataformat; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (_queue) { | |
AudioFileClose(_audioFile); | |
[self freeMemory]; | |
AudioQueueStop(_queue, true); | |
AudioQueueDispose(_queue, true); | |
_queue = nil; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 4: fill the buffer to AudioQueue | |
status = AudioQueueEnqueueBuffer( | |
audioQueue, | |
audioQueueBuffer, | |
ioNumPackets, | |
packetDescs | |
); | |
if (status != noErr) NSLog(@"AudioQueueEnqueueBuffer failed %d", status); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1: load audio data | |
// If the packetIndex is out of range, the ioNumPackets will be 0 | |
UInt32 ioNumBytes = outBufferSize; | |
UInt32 ioNumPackets = numPacketsToRead; | |
status = AudioFileReadPacketData( | |
_audioFile, | |
NO, | |
&ioNumBytes, | |
packetDescs, | |
packetIndex, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 6: Allocate buffer | |
for (int i = 0; i < maxBufferNum; i++) { | |
// Step 6.1: allock the buffer | |
status = AudioQueueAllocateBuffer( | |
_queue, | |
outBufferSize, | |
&buffers[i] | |
); | |
if (status != noErr) NSLog(@"AudioQueueAllocateBuffer failed %d", status); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 2: Calculate the buffer size | |
UInt32 size = sizeof(maxPacketSize); | |
AudioFileGetProperty( | |
audioFileID, | |
kAudioFilePropertyPacketSizeUpperBound, | |
&size, | |
&maxPacketSize); | |
if (status != noErr) NSLog(@"kAudioFilePropertyPacketSizeUpperBound failed %d", status); | |
if (dataFormat.mFramesPerPacket != 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void BufferCallback(void *inUserData,AudioQueueRef inAQ, | |
AudioQueueBufferRef buffer) { | |
AudioPlayerManager *manager = (__bridge AudioPlayerManager *)inUserData; | |
[manager audioQueueOutputWithQueue:inAQ queueBuffer:buffer]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1: Register callback | |
// Callback function will fill buffer. Then add to buffer queue. | |
status = AudioQueueNewOutput( | |
&dataFormat, | |
BufferCallback, | |
(__bridge void * _Nullable)(self), | |
CFRunLoopGetCurrent(), // nil | |
kCFRunLoopCommonModes, // nil | |
0, | |
&_queue |