Skip to content

Instantly share code, notes, and snippets.

int gx = 1, gy = 2; // global variable
int func(int a ,int b) {
int lx, ly;
gx = a;
gy = b;
lx = 9;
ly = 3;
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,
- (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;
if (_queue) {
AudioFileClose(_audioFile);
[self freeMemory];
AudioQueueStop(_queue, true);
AudioQueueDispose(_queue, true);
_queue = nil;
}
// Step 4: fill the buffer to AudioQueue
status = AudioQueueEnqueueBuffer(
audioQueue,
audioQueueBuffer,
ioNumPackets,
packetDescs
);
if (status != noErr) NSLog(@"AudioQueueEnqueueBuffer failed %d", status);
// 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,
// 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);
// 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) {
static void BufferCallback(void *inUserData,AudioQueueRef inAQ,
AudioQueueBufferRef buffer) {
AudioPlayerManager *manager = (__bridge AudioPlayerManager *)inUserData;
[manager audioQueueOutputWithQueue:inAQ queueBuffer:buffer];
}
// 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