• 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: stop a sound file after playing once?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stop a sound file after playing once?


  • Subject: Re: stop a sound file after playing once?
  • From: Bob Sabiston <email@hidden>
  • Date: Fri, 22 Jul 2011 11:53:58 -0500


Hasty typing. This sentence: "Audio, at a low level, is now different." should read: "Audio, at a low level, is NO different."

On Thu, Jul 21, 2011 at 5:56 PM, Gregory Wieber <email@hidden> wrote:
In order to achieve the lowest latency possible, it wouldn't make sense to have to 'turn the hose on and off' all the time. Monitors and display refreshes work the same way. If a screen is drawn as black (on most modern displays) it's because the frame buffers are being passed values of 0. Audio, at a low level, is now different.

But, again, I'd say if you're just starting out with this stuff, concentrate on avoiding memory allocation, use of objective-c in callbacks, etc, and don't get caught up in optimizing something that doesn't need optimizing.

It isn't that big a deal, and I don't really care as long as it works.

And it does work, except that my sounds are all clipped off around the halfway mark.  Anyone know why that would happen?  I think these are all mono sounds and are being treated as such, from what I can tell.  

I started with the MixerHost sample code, and it uses this function to read in its guitar and beats loops.  I just use the same function for my 'aiff', 'wave' and 'aif' files.  Because it sounds pretty much like exactly half the sound is playing, I stuck in a line to double the 'totalFramesInFile' received by ExtAudioFileGetProperty w/ kExtAudioFileProperty_FileLengthFrames. 

And it works!  Sounds like the whole sound is being played.  But why?  In this case I do care, because I should not have to artificially double my frame count.
Thanks for any suggestions
Bob


- (void) readAudioFilesIntoMemory {

    

    for (int audioFile = 0; audioFile < NUM_FILES; ++audioFile)  {

        

        NSLog (@"readAudioFilesIntoMemory - file %i", audioFile);

        

        // Instantiate an extended audio file object.
        ExtAudioFileRef audioFileObject = 0;

        

        // Open an audio file and associate it with the extended audio file object.
        OSStatus result = ExtAudioFileOpenURL (sourceURLArray[audioFile], &audioFileObject);

        

        if (noErr != result || NULL == audioFileObject) {[self printErrorMessage: @"ExtAudioFileOpenURL" withStatus: result]; return;}

        

        // Get the audio file's length in frames.
        UInt64 totalFramesInFile = 0;
        UInt32 frameLengthPropertySize = sizeof (totalFramesInFile);

        

        result =    ExtAudioFileGetProperty (
                                             audioFileObject,
                                             kExtAudioFileProperty_FileLengthFrames,
                                             &frameLengthPropertySize,
                                             &totalFramesInFile
                                             );

        

        if (noErr != result) {[self printErrorMessage: @"ExtAudioFileGetProperty (audio file length in frames)" withStatus: result]; return;}

        

        if (audioFile >= 2)   // << Here is where I double the framecount
            totalFramesInFile *= 2;

        

        // Assign the frame count to the soundStructArray instance variable
        soundStructArray[audioFile].frameCount = totalFramesInFile;
        printf("file has %lld frames\n",totalFramesInFile);

        

        // Get the audio file's number of channels.
        AudioStreamBasicDescription fileAudioFormat = {0};
        UInt32 formatPropertySize = sizeof (fileAudioFormat);

        

        result =    ExtAudioFileGetProperty (
                                             audioFileObject,
                                             kExtAudioFileProperty_FileDataFormat,
                                             &formatPropertySize,
                                             &fileAudioFormat
                                             );

        

        if (noErr != result) {[self printErrorMessage: @"ExtAudioFileGetProperty (file audio format)" withStatus: result]; return;}

        

        UInt32 channelCount = fileAudioFormat.mChannelsPerFrame;

 _______________________________________________
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

References: 
 >stop a sound file after playing once? (From: Bob Sabiston <email@hidden>)
 >Re: stop a sound file after playing once? (From: Aran Mulholland <email@hidden>)
 >Re: stop a sound file after playing once? (From: Bob Sabiston <email@hidden>)
 >Re: stop a sound file after playing once? (From: Gregory Wieber <email@hidden>)
 >Re: stop a sound file after playing once? (From: Bob Sabiston <email@hidden>)
 >Re: stop a sound file after playing once? (From: Gregory Wieber <email@hidden>)
 >Re: stop a sound file after playing once? (From: Aran Mulholland <email@hidden>)
 >Re: stop a sound file after playing once? (From: Bob Sabiston <email@hidden>)
 >Re: stop a sound file after playing once? (From: Aran Mulholland <email@hidden>)
 >Re: stop a sound file after playing once? (From: Gregory Wieber <email@hidden>)
 >Re: stop a sound file after playing once? (From: Gregory Wieber <email@hidden>)

  • Prev by Date: Re: stop a sound file after playing once?
  • Next by Date: Lion changes to audio processing
  • Previous by thread: Re: stop a sound file after playing once?
  • Next by thread: Re: stop a sound file after playing once?
  • Index(es):
    • Date
    • Thread