1

I have a situation where I can save a post-processing pass through the audio by taking some manipulated buffer from the end of the track and writing them to the beginning of my output file.

I originally thought I could do this by resetting the write pointer using ExtAudioFileSeek, and was about to implement it when I saw this line in the docs

Ensure that the file you are seeking in is open for reading only. This function’s behavior with files open for writing is undefined.

Now I know I could close the file for writing then reopen it, but the process is a little more complicated than that. Part of the manipulation I am doing is reading from buffers that are in the file I am writing to. The overall process looks like this:

  1. Read buffers from the end of the read file
  2. Read buffers from the beginning of the write file
  3. Process the buffers
  4. Write the buffers back to the beginning of the write file, overwriting the buffers I read in step 2

Logically, this can be done in 1 pass no problem. Programmatically, how can I achieve the same thing without corrupting my data, becoming less-efficient (opposite of my goal) or potentially imploding the universe?

coneybeare
  • 33,113
  • 21
  • 131
  • 183

1 Answers1

1

Yes, using a single audio file for both reading and writing may, as you put it, implode the universe, or at least lead to other nastiness. I think that the key to solving this problem is in step 4, where you should write the output to a new file instead of trying to "recycle" the initial write file. After your processing is complete, you can simply scrap the intermediate write file.

Or have I misunderstood the problem?

Oh, and also, you should use ExtAudioFileWriteAsync instead of ExtAudioFileWrite for your writes if you are doing this in realtime. Otherwise the I/O load will cause audio dropouts.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • Thanks for the help. Its not in realtime so it shouldn't be an issue. Want to take a stab at the implementation issues I am now seeing? http://stackoverflow.com/questions/4159653/mixing-down-two-files-together-using-extended-audio-file-services – coneybeare Nov 11 '10 at 21:56
  • 1
    Agreed, you should just write to a new file. Trying to be clever and save a step will likely bite you in the ass later on. – lucius Nov 22 '10 at 05:21