Esempio n. 1
0
VM::VM()
{
	// TODO: pass in vm flags at construction.
	mVMFlags.push_back( "--checked" );
	mVMFlags.push_back( "--no-profile" ); // currently dart's profiler seems to be blocking the main thread when debugging in xcode - this disables it for now
//	mVMFlags.push_back( "--print-flags" );

	auto vmCFlags = mallocScoped<const char *>( mVMFlags.size() );

	for( size_t i = 0; i < mVMFlags.size(); i++ )
		vmCFlags.get()[i] = mVMFlags[i].c_str();

	// setting VM startup options
	bool success = Dart_SetVMFlags( mVMFlags.size(), vmCFlags.get() );
	CI_VERIFY( success );

	success = Dart_Initialize(	Script::createIsolateCallback,
								interruptIsolateCallback,
								unhandledExceptionCallback,
								shutdownIsolateCallback,
								openFileCallback,
								readFileCallback,
								writeFileCallback,
								closeFileCallback,
								NULL,
								NULL );
	CI_VERIFY( success );
}
Esempio n. 2
0
TargetFileCoreAudio::TargetFileCoreAudio( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension )
    : TargetFile( dataTarget, sampleRate, numChannels, sampleType )
{
    ::CFURLRef targetUrl = ci::cocoa::createCfUrl( Url( dataTarget->getFilePath().string() ) );
    ::AudioFileTypeID fileType = getFileTypeIdFromExtension( extension );

    ::AudioStreamBasicDescription fileAsbd;
    switch( mSampleType ) {
    case SampleType::INT_16:
        fileAsbd = createInt16Asbd( mSampleRate, mNumChannels, true );
        break;
    case SampleType::FLOAT_32:
        fileAsbd = createFloatAsbd( mSampleRate, mNumChannels, true );
        break;
    default:
        CI_ASSERT_NOT_REACHABLE();
    }

    ::ExtAudioFileRef audioFile;
    OSStatus status = ::ExtAudioFileCreateWithURL( targetUrl, fileType, &fileAsbd, nullptr, kAudioFileFlags_EraseFile, &audioFile );
    if( status == kAudioFileUnsupportedDataFormatError )
        throw AudioFileExc( string( "Extended Audio File Services: Unsupported format error, target file: " ) + dataTarget->getFilePath().string(), (int32_t)status );
    else if( status != noErr )
        throw AudioFileExc( string( "Extended Audio File Services faild: target file: " ) + dataTarget->getFilePath().string(), (int32_t)status );

    ::CFRelease( targetUrl );
    mExtAudioFile = ExtAudioFilePtr( audioFile );

    ::AudioStreamBasicDescription clientAsbd = createFloatAsbd( mSampleRate, mNumChannels, false );

    status = ::ExtAudioFileSetProperty( mExtAudioFile.get(), kExtAudioFileProperty_ClientDataFormat, sizeof( clientAsbd ), &clientAsbd );
    CI_VERIFY( status == noErr );

    mBufferList = createNonInterleavedBufferListShallow( mNumChannels );
}
Esempio n. 3
0
void SourceFileOggVorbis::init()
{
	CI_ASSERT( mDataSource );
#if ! defined( CINDER_ANDROID )
	if( mDataSource->isFilePath() ) {
		int status = ov_fopen( mDataSource->getFilePath().string().c_str(), &mOggVorbisFile );
		if( status )
			throw AudioFileExc( string( "Failed to open Ogg Vorbis file with error: " ), (int32_t)status );
	}
	else {
#endif
		mStream = mDataSource->createStream();

		ov_callbacks callbacks;
		callbacks.read_func = readFn;
		callbacks.seek_func = seekFn;
		callbacks.close_func = closeFn;
		callbacks.tell_func = tellFn;

		int status = ov_open_callbacks( this, &mOggVorbisFile, NULL, 0, callbacks );
		CI_VERIFY( status == 0 );

#if ! defined( CINDER_ANDROID )
	}
#endif

	vorbis_info *info = ov_info( &mOggVorbisFile, -1 );
    mNumChannels = info->channels;
    mSampleRate = info->rate;

	ogg_int64_t totalFrames = ov_pcm_total( &mOggVorbisFile, -1 );
    mNumFrames = mFileNumFrames = static_cast<uint32_t>( totalFrames );
}
Esempio n. 4
0
void Context::removeAutoPulledNode( const NodeRef &node )
{
	size_t result = mAutoPulledNodes.erase( node );
	CI_VERIFY( result );

	mAutoPullCacheDirty = true;
	if( mAutoPulledNodes.empty() )
		mAutoPullRequired = false;
}
Esempio n. 5
0
void TargetFileCoreAudio::performWrite( const Buffer *buffer, size_t numFrames, size_t frameOffset )
{
    for( int ch = 0; ch < mNumChannels; ch++ ) {
        mBufferList->mBuffers[ch].mDataByteSize = (UInt32)numFrames * sizeof( float );
        mBufferList->mBuffers[ch].mData = (void *)( buffer->getChannel( ch ) + frameOffset );
    }

    OSStatus status = ::ExtAudioFileWrite( mExtAudioFile.get(), (UInt32)numFrames, mBufferList.get() );
    CI_VERIFY( status == noErr );
}
Esempio n. 6
0
size_t SourceFileCoreAudio::performRead( Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded )
{
    for( int ch = 0; ch < mNumChannels; ch++ ) {
        mBufferList->mBuffers[ch].mDataByteSize = UInt32( numFramesNeeded * sizeof( float ) );
        mBufferList->mBuffers[ch].mData = &buffer->getChannel( ch )[bufferFrameOffset];
    }

    UInt32 frameCount = (UInt32)numFramesNeeded;
    OSStatus status = ::ExtAudioFileRead( mExtAudioFile.get(), &frameCount, mBufferList.get() );
    CI_VERIFY( status == noErr );

    return (size_t)frameCount;
}
Esempio n. 7
0
void SourceFileCoreAudio::initImpl()
{
    ::CFURLRef fileUrl = ci::cocoa::createCfUrl( Url( mDataSource->getFilePath().string() ) );
    ::ExtAudioFileRef audioFile;
    OSStatus status = ::ExtAudioFileOpenURL( fileUrl, &audioFile );
    if( status != noErr ) {
        string urlString = ci::cocoa::convertCfString( CFURLGetString( fileUrl ) );
        throw AudioFileExc( string( "could not open audio source file: " ) + urlString, (int32_t)status );
    }

    mExtAudioFile = ExtAudioFilePtr( audioFile );

    ::AudioStreamBasicDescription fileFormat;
    UInt32 propSize = sizeof( fileFormat );
    status = ::ExtAudioFileGetProperty( audioFile, kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat );
    CI_VERIFY( status == noErr );

    mNumChannels = fileFormat.mChannelsPerFrame;
    mSampleRateNative = fileFormat.mSampleRate;

    size_t outputSampleRate = getSampleRate(); // may be 0 at init
    if( ! outputSampleRate )
        outputSampleRate = mSampleRateNative;

    SInt64 numFrames;
    propSize = sizeof( numFrames );
    status = ::ExtAudioFileGetProperty( audioFile, kExtAudioFileProperty_FileLengthFrames, &propSize, &numFrames );
    CI_VERIFY( status == noErr );
    mNumFrames = mFileNumFrames = static_cast<size_t>( numFrames );

    ::AudioStreamBasicDescription outputFormat = audio::cocoa::createFloatAsbd( outputSampleRate, mNumChannels );
    status = ::ExtAudioFileSetProperty( mExtAudioFile.get(), kExtAudioFileProperty_ClientDataFormat, sizeof( outputFormat ), &outputFormat );
    CI_VERIFY( status == noErr );

    // numFrames will be updated at read time
    mBufferList = createNonInterleavedBufferListShallow( mNumChannels );
}
Esempio n. 8
0
// static
vector<string> SourceFileCoreAudio::getSupportedExtensions()
{
    vector<string> result;

    ::CFArrayRef extensionsCF;
    UInt32 propSize = sizeof( extensionsCF );
    OSStatus status = ::AudioFileGetGlobalInfo( kAudioFileGlobalInfo_AllExtensions, 0, NULL, &propSize, &extensionsCF );
    CI_VERIFY( status == noErr );

    CFIndex extCount = ::CFArrayGetCount( extensionsCF );
    for( CFIndex index = 0; index < extCount; ++index ) {
        string ext = ci::cocoa::convertCfString( (CFStringRef)::CFArrayGetValueAtIndex( extensionsCF, index ) );
        result.push_back( ext );
    }

    ::CFRelease( extensionsCF );

    return result;
}
Esempio n. 9
0
void SourceFileOggVorbis::performSeek( size_t readPositionFrames )
{
	int status = ov_pcm_seek( &mOggVorbisFile, (ogg_int64_t)readPositionFrames );
	CI_VERIFY( status == 0 );
}
Esempio n. 10
0
void SourceFileCoreAudio::performSeek( size_t readPositionFrames )
{
    OSStatus status = ::ExtAudioFileSeek( mExtAudioFile.get(), readPositionFrames );
    CI_VERIFY( status == noErr );
}