formatting - Recording Mono on iPhone in IMA4 format -


i'm using speakhear sample app on apple's developer site create audio recording app. i'm attempting record directly ima4 format using kaudioformatappleima4 system constant. listed 1 of usable formats, every time set audio format variable , pass , set it, 'fmt?' error. here code use set audio format variable:

#define kaudiorecordingformat kaudioformatappleima4 #define kaudiorecordingtype kaudiofilecaftype #define kaudiorecordingsamplerate 16000.00 #define kaudiorecordingchannelsperframe 1 #define kaudiorecordingframesperpacket 1 #define kaudiorecordingbitsperchannel 16 #define kaudiorecordingbytesperpacket 2 #define kaudiorecordingbytesperframe 2  - (void) setupaudioformat: (uint32) formatid {      // obtains hardware sample rate use in recording     // audio format. each time audio route changes, sample rate     // needs updated.     uint32 propertysize = sizeof (self.hardwaresamplerate);      osstatus err = audiosessiongetproperty (         kaudiosessionproperty_currenthardwaresamplerate,         &propertysize,         &hardwaresamplerate     );      if(err != 0){         nslog(@"audiorecorder::setupaudioformat - error getting audio session property");     }      audioformat.msamplerate = kaudiorecordingsamplerate;      nslog (@"hardware sample rate = %f", self.audioformat.msamplerate);      audioformat.mformatid           = formatid;     audioformat.mchannelsperframe   = kaudiorecordingchannelsperframe;     audioformat.mformatflags        = kaudioformatflagissignedinteger | kaudioformatflagispacked;     audioformat.mframesperpacket    = kaudiorecordingframesperpacket;     audioformat.mbitsperchannel     = kaudiorecordingbitsperchannel;     audioformat.mbytesperpacket     = kaudiorecordingbytesperpacket;     audioformat.mbytesperframe      = kaudiorecordingbytesperframe;  } 

and here use function:

- (id) initwithurl: fileurl {     nslog (@"initializing recorder object.");     self = [super init];      if (self != nil) {          // specify recording format. options are:         //         //      kaudioformatlinearpcm         //      kaudioformatapplelossless         //      kaudioformatappleima4         //      kaudioformatilbc         //      kaudioformatulaw         //      kaudioformatalaw         //         // when targeting simulator, speakhere uses linear pcm regardless of format         //  specified here. see setupaudioformat: method in file.         [self setupaudioformat: kaudiorecordingformat];          osstatus result =   audioqueuenewinput (                                 &audioformat,                                 recordingcallback,                                 self,                   // userdata                                 null,                   // run loop                                 null,                   // run loop mode                                 0,                      // flags                                 &queueobject                             );          nslog (@"attempted create new recording audio queue object. result: %f", result);          // recording format audio queue's audio converter --         //  file may require more specific stream description          //  necessary create encoder.         uint32 sizeofrecordingformatasbdstruct = sizeof (audioformat);          audioqueuegetproperty (             queueobject,             kaudioqueueproperty_streamdescription,  // constant available in iphone os             &audioformat,             &sizeofrecordingformatasbdstruct         );          audioqueueaddpropertylistener (             [self queueobject],             kaudioqueueproperty_isrunning,             audioqueuepropertylistenercallback,             self         );          [self setaudiofileurl: (cfurlref) fileurl];          [self enablelevelmetering];     }     return self; }  

thanks help! -matt

i'm not sure format flags you're passing correct; ima4 (which, iirc, stands ima adpcm 4:1) 4-bit (4:1 compression 16 bits) headers.

according docs audiostreambasicdescription:

  • mbytesperframe should 0, since format compressed.
  • mbitsperchannel should 0, since format compressed.
  • mformatflags should 0, since there nothing choose.

aaccording afconvert -f caff -t ima4 -c 1 blah.aiff blah.caf followed afinfo blah.caf:

  • mbytesperpacket should 34, and
  • mframesperpacket should 64. might able set these 0 instead.

the reference algorithm in original ima spec not helpful (it's ocr of scans, site has scans).


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -