• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AudioFileWriteBytes() fails with error code -40
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AudioFileWriteBytes() fails with error code -40


  • Subject: Re: AudioFileWriteBytes() fails with error code -40
  • From: Alex Wiltschko <email@hidden>
  • Date: Tue, 6 Apr 2010 00:03:40 -0400

I've gotten this fixed. Problem was, I wasn't casting to the proper endianness.

On Mar 26, 2010, at 10:15 PM, Hamilton Feltman wrote:

> status = AudioFileWriteBytes(audioFileID, NO, 0, &numBytesToWrite, &holdingBuffer);
>
> This line looks suspect. holdingbufer is already a pointer and this code is taking the address of it.
>
> HTH,
> Hamilton
>
> On Mar 20, 2010, at 9:34 PM, Alex Wiltschko wrote:
>
>> I'm trying to write raw audio bytes to a file using AudioFileWriteBytes(). I get an error of "-40".
>>
>> This is a function I'm calling from an NSTimer, after properly initializing the audio file. Here's what I'm doing:
>>
>> void writeSingleChannelRingBufferDataToFileAsSInt16(AudioFileID audioFileID, AudioConverterRef audioConverter, ringBuffer *rb, SInt16 *holdingBuffer) {
>> // First, figure out which bits of audio we'll be
>> // writing to file from the ring buffer
>>
>>   UInt32 lastFreshSample = rb->lastWrittenIndex;
>>   OSStatus status;
>>   int numSamplesToWrite;
>>   UInt32 numBytesToWrite;
>>
>>
>>   if (lastFreshSample < rb->lastReadIndex) {
>>       numSamplesToWrite = kNumPointsInWave + lastFreshSample - rb->lastReadIndex - 1;
>>   }
>>   else {
>>       numSamplesToWrite = lastFreshSample - rb->lastReadIndex;
>>   }
>>   numBytesToWrite = numSamplesToWrite*sizeof(SInt16);
>>
>>
>> // Then I copy the audio data (stored as floats) to a holding buffer (SInt16)
>> // that will be written directly to the file.
>> // The copying looks funky because it's from a ring buffer.
>>
>>   UInt32 buffLen = rb->sizeOfBuffer - 1;
>>   for (int i=0; i < numSamplesToWrite; ++i) {
>>       holdingBuffer[i] = rb->data[(i + rb->lastReadIndex) & buffLen];
>>   }
>> // Okay, now we actually try to write the audio from the SInt16 buffer "holdingBuffer"
>> // to the audio file. The NSLog will spit out an error -40,
>> // but also claims that it's writing bytes. No data is written to file.
>>
>>   status = AudioFileWriteBytes(audioFileID, NO, 0, &numBytesToWrite, &holdingBuffer);
>>   rb->lastReadIndex = lastFreshSample;
>>
>>   NSLog(@"Error = %d, wrote %d bytes", status, numBytesToWrite);
>>
>>   return;
>>
>>
>>
>> What is this error -40? By the way, everything works fine if I write straight from the ringBuffer to the file. Of course, when I play the AIF file, it sounds like junk, because I'm writing floats, not SInt16s, but AudioFileWriteBytes doesn't complain. _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Coreaudio-api mailing list      (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: building for 64-bit Logic
  • Next by Date: Re: Ableton Live 8: play button, what does it do?
  • Previous by thread: Re: Sound Prefs on OS X 10.6.3
  • Next by thread: CoreMIDI connect to instrument help
  • Index(es):
    • Date
    • Thread