Objective-c – Member reference base type ‘void’ is not a structure or union (OBJ-C)

ccore-audioobjective cpointers

I'm working with Apple Audio Queue Services guide example.https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQRecord/RecordingAudio.html#//apple_ref/doc/uid/TP40005343-CH4-SW1
Going through the example I got couple of unseen errors

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>

const static int kNumberBuffers=3;  //Sets the number of audio queue buffers to use

typedef struct AQRecorderState{
    AudioStreamPacketDescription * mDataFormat;  // An AudioStreamBasicDescription structure (from CoreAudioTypes.h) representing the audio data format to write to disk. This format gets used by the audio queue specified in the mQueue field.
    AudioQueueRef mQueue;   // The recording audio queue created by your application.
    AudioQueueBufferRef mBuffers[kNumberBuffers]; //An array holding pointers to the audio queue buffers managed by the audio queue.
    AudioFileID mAudioFile; // An audio file object representing the file into which your program records audio data.
    UInt32 bufferByteSize;  // The size, in bytes, for each audio queue buffer
    SInt64 mCurrentPacket;  // The packet index for the first packet to be written from the current audio queue buffer.
    bool mIsRunning;        // Indicates whether queue is running.
}AQRecorderState;


static void HandleInputBuffer(
                              void *AQData, // Typically, aqData is a custom structure that contains state data for the audio queue

                              AudioQueueRef inAQ,   // The audio queue that owns this callback.

                              AudioQueueBufferRef inBuffer, //The audio queue buffer containing the incoming audio data to record.

                              const AudioTimeStamp *inStartTime, //The sample time of the first sample in the audio queue buffer (not needed for simple recording).

                              UInt32 inNumPackets, //The number of packet descriptions in the inPacketDesc parameter. A value of 0 indicates CBR data.

                              const AudioStreamPacketDescription  *inPacketDesc // For compressed audio data formats that require packet descriptions, the packet descriptions produced by the encoder for the packets in the buffer.
){

    AudioFileWritePackets(AQData->mAudioFile, // Member reference base type 'void' is not a structure or union
                          false,
                          inBuffer->mAudioDataByteSize,
                          inPacketDesc,
                          AQData->mCurrentPacket, // same here
                          &inNumPackets,
                          inBuffer->mAudioData);


};

The Build Failed and I don't know where the error is because it says nothing about it in the docs. Thanks for any help

Best Answer

You cannot access fields on void *, you have to cast it to a specific type first.

Probably:

((AQRecorderState *) AQData)->mAudioFile
Related Topic