• 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: Simple audio file opening/reading/conversion?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple audio file opening/reading/conversion?


  • Subject: Re: Simple audio file opening/reading/conversion?
  • From: William Stewart <email@hidden>
  • Date: Wed, 13 Feb 2008 12:29:39 -0800

The easiest API to use to read files the way you are doing is the ExtendedAudioFile API - you can specify floats as the format to get from the file (regardless of what the file itself has)

Bill

On Feb 13, 2008, at 8:35 AM, Art Gillespie wrote:

The compiler won't let you use a C++ instance method where a C
function pointer is expected.

A common idiom is to declare the callback method static and create a
similar instance method (without the inUserData parameter).  Then just
be sure to pass 'this' to the inInputDataProcUserData parameter of
AudioConverterFillBuffer:

...

static void MyAudioClass::MyClassCallback(AudioConverterRef inAudioConverter,
UInt32* ioDataSize,
void** outData,
void* inUserData)
{
MyAudioClass *instance = static_cast<MyAudioClass*>(inUserData);
instance->MyInstanceCallback(inAudioConverter, ioDataSize, outData);
}


void MyAudioClass::MyInstanceCallback(AudioConverterRef inAudioConverter,
UInt32* ioDataSize,
void** outData)
{
//handle the callback here
}


void MyAudioClass::LoadSample(...)
{
 ...
 AudioConverterFillBuffer(theConverter, MyClassCallback, this,
&someInt, someData);
 ...
}

Best,

Art

On Feb 12, 2008 11:06 PM, Aaron Wishnick <email@hidden> wrote:
Thanks!
One more problem: I'm using this all from within a class. I can't seem to
define an appropriate callback to AudioConverterFillBuffer without the
compiler choking. The callback is defined as:
class sample{
...
...
private:
...
OSStatus dataProc( AudioConverterRef inAudioConverter,
UInt32* ioDataSize,
void** outData,
void* inUserData);
...
}


and AudioConverterFillBuffer is being called via:
AudioConverterFillBuffer( audioConv, &Sample::dataProc, NULL, &m_uLength,
&m_fFrames[0] );


The compiler says, "error: invalid static_cast from type 'OSStatus
(Sample::*)(OpaqueAudioConverter*, UInt32*, void**, void*)' to type
'OSStatus (*)(OpaqueAudioConverter*, UInt32*, void**, void*)'"

The compiler seems not to like the fact that my callback is part of a class.
Is there a better way to do this, or a way to circumvent the callback? As
I'm just converting from a buffer stored in memory, it seems a little
circuitous to have to use a callback.


Thanks again,
Aaron


On Feb 12, 2008, at 11:24 PM, Art Gillespie wrote:

It looks like you're reading in the raw bytes--you want to convert the
format to 32-bit float canonical at the current sample rate so that
you'll get the expected results in Render. Check out
AudioConverterNew, AudioConverterFillBuffer, etc. in
<AudioToolbox/AudioConverter.h>


Best,

Art


On Feb 12, 2008 8:59 PM, Aaron Wishnick <email@hidden> wrote:


I'm writing an audio unit which will need to load audio files into memory.
I'm confused by all the different interfaces available. Here's what I'm
using so far. When I play the sound back in Process(), I get static, so I'd
like to know if anybody sees anything glaring here:


OSStatus Sample::Open( std::string filename ) {
FSPathMakeRef((UInt8 *)filename.c_str(), &m_fsRef, NULL);
OSStatus retVal = AudioFileOpen ( &m_fsRef, fsRdPerm, 0, &m_fileID );


// should do error checking here


UInt32 uSize = sizeof( m_uLength ); AudioFileGetProperty( m_fileID, kAudioFilePropertyAudioDataByteCount, &uSize, &m_uLength);


m_fFrames.resize( m_uLength, 0.0f );


retVal = AudioFileReadBytes( m_fileID, false, 0, &m_uLength, &m_fFrames[0]
);



return retVal;


return 0; } _______________________________________________ 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

_______________________________________________ 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: 
 >Simple audio file opening/reading/conversion? (From: Aaron Wishnick <email@hidden>)
 >Re: Simple audio file opening/reading/conversion? (From: "Art Gillespie" <email@hidden>)
 >Re: Simple audio file opening/reading/conversion? (From: "Art Gillespie" <email@hidden>)

  • Prev by Date: Re: Simple audio file opening/reading/conversion?
  • Next by Date: Re: Simple audio file opening/reading/conversion?
  • Previous by thread: Re: Simple audio file opening/reading/conversion?
  • Next by thread: Re: Simple audio file opening/reading/conversion?
  • Index(es):
    • Date
    • Thread