• 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
How Do I Use NSCoding with Core Audio Data Types?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How Do I Use NSCoding with Core Audio Data Types?


  • Subject: How Do I Use NSCoding with Core Audio Data Types?
  • From: n ketter <email@hidden>
  • Date: Fri, 21 Jun 2013 17:04:51 -0700

I've created a class that contains three properties that are Core Audio types:

    @interface AudioFilePlayer : NSObject <NSCoding>
    
    @property (assign) AudioUnit                        mAudioUnit;
    @property (assign) AUNode                           mNode;
    @property (assign) AudioStreamBasicDescription      mStreamFormat;
    
    @end

My app holds an array of objects of type AudioFilePlayer and I want to archive and unarchive them using NSCoding. I've written the encodeWithCoder: and initWithCoder: methods as follows:

    - (void)encodeWithCoder:(NSCoder *)aCoder
    {        
        [aCoder encodeBytes:(uint8_t*)&_mAudioUnit length:sizeof(AudioUnit) forKey:@"mAudioUnit"];
        [aCoder encodeBytes:(uint8_t*)&_mNode length:sizeof(AUNode) forKey:@"mNode"];
        [aCoder encodeBytes:(uint8_t*)&_mStreamFormat length:sizeof(AudioStreamBasicDescription) forKey:@"mStreamFormat"];
    }
    
    - (id)initWithCoder:(NSCoder *)aDecoder
    {        
        self = [super init];
        if (self) {
            [self setMAudioUnit:(AudioUnit)[aDecoder decodeBytesForKey:@"mAudioUnit" returnedLength:sizeof(AudioUnit)]];
            
            [self setMNode:(AUNode)[aDecoder decodeBytesForKey:@"mNode" returnedLength:sizeof(AUNode)]];
            [self setMStreamFormat:*(AudioStreamBasicDescription*)[aDecoder decodeBytesForKey:@"mStreamFormat" returnedLength:sizeof(AudioStreamBasicDescription)]];
        }
                
        return self;
    }

I'm able to encode/archive successfully (that is to say a file is written and no errors are returned...I'm not sure it's actually working) but when I launch the app and try to decode/unarchive the object, the app crashes with:

    Thread 1: EXC_BAD_ACCESS (code=2,address=0x4)

on this line in my `initWithCoder method`:

    [self setMAudioUnit:(AudioUnit)[aDecoder decodeBytesForKey:@"mAudioUnit" returnedLength:sizeof(AudioUnit)]];

This is my first time using NSCoding so I'm not at all confident I'm doing this even remotely correctly.

Thanks in advance!

p.s. I posted this question on SO, but saw no response: http://stackoverflow.com/questions/17238254/using-nscoding-with-core-audio-types
 _______________________________________________
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

  • Follow-Ups:
    • Re: How Do I Use NSCoding with Core Audio Data Types?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Tutorial for creating Audio Unit in XCode 4.6
  • Next by Date: Re: How Do I Use NSCoding with Core Audio Data Types?
  • Previous by thread: Re: Tutorial for creating Audio Unit in XCode 4.6
  • Next by thread: Re: How Do I Use NSCoding with Core Audio Data Types?
  • Index(es):
    • Date
    • Thread