Is there an approved way to acquire the data offset?
Â
Hi experts,
I’m constructing a few progresses on getting a compressed (mp3) sound and I am saving it as PCM.
Also, I tried to split the main file in the same process into chunks and it is 2 seconds long.
I look like to be successful; however I am a bit confused.
As I convert blocks of audio as well as write the files out, I make sure to make out if I am ready to write a chunk that would build my file go beyond my 2 second bound.
If thus, I write sufficient to acquire to 2 seconds, and then shut the file, and after that, open a fresh file and also write the rest into the fresh file, and next read extra data.
Like this:
framesInTimedSegment += numFrames;
if ((framesInTimedSegment  > (2.0 * sampleRate)) && (j < 5)) {
  UInt32 newNumFrames = numFrames;
  numFrames = framesInTimedSegment – (2.0 * sampleRate);
  newNumFrames -= numFrames;
// Question A
  UInt32 segmentOffset = newNumFrames * numChannels * 2;
  error = ExtAudioFileWrite(segmentFile, newNumFrames, &fillBufList);
// Question B
    // handle this error!  We might have an interruption
  if (segmentFile) ExtAudioFileDispose(segmentFile);
  XThrowIfError(ExtAudioFileCreateWithURL(urlArray[++j], kAudioFileCAFType, &dstFormat, NULL, kAudioFileFlags_EraseFile, &breakoutFile), "ExtAudioFileCreateWithURL failed! – segmentFile");
  size = sizeof(clientFormat);
  XThrowIfError(ExtAudioFileSetProperty(segmentFile, kExtAudioFileProperty_ClientDataFormat, size, &clientFormat), "couldn't set destination client format");
  fillBufList.mBuffers[0].mData = srcBuffer + segmentOffset;
  fillBufList.mBuffers[0].mDataByteSize = numFrames * fillBufList.mBuffers[0].mNumberChannels * 2;
  framesInTimedSegment = numFrames;
}
error = ExtAudioFileWrite(segmentFile, numFrames, &fillBufList);
Anyways, my question is:
A: Is there any improved technique to get the offset in my buffer by which, I don't hard code incorrectly a few value in there? I mean, is there an approved way to acquire the data offset?
B: ExtAudioFileWrite is performing the exchange from compressed to decompressed. After that, the information I am writing hasn't so far been decompressed (right?). Therefore, shouldn't I have to be anxious about playing with frame digits as well as offsets when I am contracting with compressed data? Should I convert the file first, and then divide that PCM?
I am not sure. Please help me.
Thanks a lot.