示例#1
0
void initStereoFormatsWithoutPassthrough()
{
  AudioStreamBasicDescription streamFormat;
  FillOutASBDForLPCM(streamFormat, 96000, 2, 16, 16, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 0

  FillOutASBDForLPCM(streamFormat, 48000, 2, 16, 16, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 1

  FillOutASBDForLPCM(streamFormat, 44100, 2, 16, 16, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 2

  FillOutASBDForLPCM(streamFormat, 96000, 2, 20, 20, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 3

  FillOutASBDForLPCM(streamFormat, 48000, 2, 20, 20, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 4

  FillOutASBDForLPCM(streamFormat, 44100, 2, 20, 20, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 5

  FillOutASBDForLPCM(streamFormat, 96000, 2, 24, 24, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 6

  FillOutASBDForLPCM(streamFormat, 48000, 2, 24, 24, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 7

  FillOutASBDForLPCM(streamFormat, 44100, 2, 24, 24, false, false, false);
  stereoFormatsWithoutPassthrough.push_back(streamFormat); // 8
}
示例#2
0
void addLPCMFormats(std::vector<AudioStreamBasicDescription> &streamFormats)
{
  AudioStreamBasicDescription streamFormat;

  FillOutASBDForLPCM(streamFormat, 96000, 8, 16, 16, false, false, false);
  streamFormats.push_back(streamFormat); // + 0

  FillOutASBDForLPCM(streamFormat, 48000, 8, 16, 16, false, false, false);
  streamFormats.push_back(streamFormat); // + 1

  FillOutASBDForLPCM(streamFormat, 44100, 8, 16, 16, false, false, false);
  streamFormats.push_back(streamFormat); // + 2

  FillOutASBDForLPCM(streamFormat, 96000, 8, 20, 20, false, false, false);
  streamFormats.push_back(streamFormat); // + 3

  FillOutASBDForLPCM(streamFormat, 48000, 8, 20, 20, false, false, false);
  streamFormats.push_back(streamFormat); // + 4

  FillOutASBDForLPCM(streamFormat, 44100, 8, 20, 20, false, false, false);
  streamFormats.push_back(streamFormat); // + 5

  FillOutASBDForLPCM(streamFormat, 96000, 8, 24, 24, false, false, false);
  streamFormats.push_back(streamFormat); // + 6

  FillOutASBDForLPCM(streamFormat, 48000, 8, 24, 24, false, false, false);
  streamFormats.push_back(streamFormat); // + 7

  FillOutASBDForLPCM(streamFormat, 44100, 8, 24, 24, false, false, false);
  streamFormats.push_back(streamFormat); // + 8
}
示例#3
0
void addPassthroughFormats(std::vector<AudioStreamBasicDescription> &streamFormats)
{
  AudioStreamBasicDescription streamFormat;

  FillOutASBDForLPCM(streamFormat, 96000, 2, 16, 16, false, false, false);
  streamFormat.mFormatID = kAudioFormat60958AC3;
  streamFormats.push_back(streamFormat); // stereoFormtsWithoutPassthrough.size() + 0

  FillOutASBDForLPCM(streamFormat, 48000, 2, 16, 16, false, false, false);
  streamFormat.mFormatID = kAudioFormat60958AC3;
  streamFormats.push_back(streamFormat); // stereoFormtsWithoutPassthrough.size() + 1

  FillOutASBDForLPCM(streamFormat, 44100, 2, 16, 16, false, false, false);
  streamFormat.mFormatID = kAudioFormat60958AC3;
  streamFormats.push_back(streamFormat); // stereoFormtsWithoutPassthrough.size() + 2
}
bool ExtAudioFileAudioSource::init(const RString& path, bool loadIntoMemory)
{
	if(mLoadedInMemory && loadIntoMemory)
		return true;
	
    // FIXME: query the file to find out how many channels instead of hardcoding.
    
    CFURLRef path_url = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
                                                                 (const UInt8*)path.data(),
                                                                 path.length(),
                                                                 false
                                                                 );
    
    OSStatus err = ExtAudioFileOpenURL(path_url, &mAudioFile);
    if(err)
    {
        printCode("ExtAudioFileOpenURL: ", err);        
        return false;
    }
    
    UInt32 propSize = sizeof(mClientFormat);
    err = ExtAudioFileGetProperty(mAudioFile, kExtAudioFileProperty_FileDataFormat, &propSize, &mClientFormat);    

    propSize = sizeof(mTotalFrames);
    err = ExtAudioFileGetProperty(mAudioFile, kExtAudioFileProperty_FileLengthFrames, &propSize, &mTotalFrames);    
    
    // Setup output format
    FillOutASBDForLPCM(mFormat, getSampleRate(), getNumChannels(), 32, 32, true, false,true);
    
    err = ExtAudioFileSetProperty(mAudioFile, kExtAudioFileProperty_ClientDataFormat, sizeof(mFormat), &mFormat);
    if(err)
    {
        printCode("ExtAudioFileSetProperty: ", err);
        return false;
    }
    
    // Allocate our buffer list with NUM_CHANNELS buffers in it.
    mpBufferList = (AudioBufferList *)malloc(sizeof(AudioBufferList) + (getNumChannels() - 1) * sizeof(AudioBuffer));
    mpBufferList->mNumberBuffers = getNumChannels();    

    return BufferedAudioSource::init(path, loadIntoMemory);
}
示例#5
0
bool CoreAudioSound::Start()
{
	OSStatus err;
	AURenderCallbackStruct callback_struct;
	AudioStreamBasicDescription format;
	ComponentDescription desc;
	Component component;

	desc.componentType = kAudioUnitType_Output;
	desc.componentSubType = kAudioUnitSubType_DefaultOutput;
	desc.componentFlags = 0;
	desc.componentFlagsMask = 0;
	desc.componentManufacturer = kAudioUnitManufacturer_Apple;
	component = FindNextComponent(nullptr, &desc);
	if (component == nullptr) {
		ERROR_LOG(AUDIO, "error finding audio component");
		return false;
	}

	err = OpenAComponent(component, &audioUnit);
	if (err != noErr) {
		ERROR_LOG(AUDIO, "error opening audio component");
		return false;
	}

	FillOutASBDForLPCM(format, m_mixer->GetSampleRate(),
				2, 16, 16, false, false, false);
	err = AudioUnitSetProperty(audioUnit,
				kAudioUnitProperty_StreamFormat,
				kAudioUnitScope_Input, 0, &format,
				sizeof(AudioStreamBasicDescription));
	if (err != noErr) {
		ERROR_LOG(AUDIO, "error setting audio format");
		return false;
	}

	callback_struct.inputProc = callback;
	callback_struct.inputProcRefCon = this;
	err = AudioUnitSetProperty(audioUnit,
				kAudioUnitProperty_SetRenderCallback,
				kAudioUnitScope_Input, 0, &callback_struct,
				sizeof callback_struct);
	if (err != noErr) {
		ERROR_LOG(AUDIO, "error setting audio callback");
		return false;
	}

    err = AudioUnitSetParameter(audioUnit,
					kHALOutputParam_Volume,
					kAudioUnitParameterFlag_Output, 0,
					m_volume / 100., 0);
	if (err != noErr)
		ERROR_LOG(AUDIO, "error setting volume");

	err = AudioUnitInitialize(audioUnit);
	if (err != noErr) {
		ERROR_LOG(AUDIO, "error initializing audiounit");
		return false;
	}

	err = AudioOutputUnitStart(audioUnit);
	if (err != noErr) {
		ERROR_LOG(AUDIO, "error starting audiounit");
		return false;
	}

	return true;
}
示例#6
0
/*
 *Setup RemoteIO Audio Unit.
 * (TODO) provide dynamic configuration options here.
 */
int MUEAudioIO::setupIO()
{
    try {		
		// Open the output unit
		AudioComponentDescription desc;
		desc.componentType			= kAudioUnitType_Output;
		desc.componentSubType		= kAudioUnitSubType_RemoteIO;
		desc.componentManufacturer	= kAudioUnitManufacturer_Apple;
		desc.componentFlags			= 0;
		desc.componentFlagsMask		= 0;
		
		AudioComponent comp = AudioComponentFindNext(NULL, &desc);
		
		AudioComponentInstanceNew(comp, &rioUnit);
        
		UInt32 one = 1;
		AudioUnitSetProperty(rioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one));
        
        
        
        // Setup Callbacks--------------------------------------------------
        printf("setupIO: Initializing Callbacks\n");
        AURenderCallbackStruct inProc;
        
        inProc.inputProc = MUEinputCallback;
        inProc.inputProcRefCon = this;
        
		AudioUnitSetProperty(rioUnit, kAudioOutputUnitProperty_SetInputCallback,
							 kAudioUnitScope_Global, AUDIO_INPUT_BUS, &inProc, sizeof(inProc));
		
        inProc.inputProc = MUEoutputCallback;
        inProc.inputProcRefCon = this;
        
        AudioUnitSetProperty(rioUnit, kAudioUnitProperty_SetRenderCallback,
							 kAudioUnitScope_Global, AUDIO_OUTPUT_BUS, &inProc, sizeof(inProc));
        //-----------------------------------------------------------------
        
        
        // Enable Input and Output------------------------------------------
        // Enable Output....
        UInt32 flag = 1;
        OSStatus status = AudioUnitSetProperty(rioUnit, kAudioOutputUnitProperty_EnableIO, 
											   kAudioUnitScope_Output, AUDIO_OUTPUT_BUS, &flag, sizeof(flag));
        
        if (status != noErr)
        {
            printf("MUEAudioIO::setupIO: Enable Output failed: status = %d\n", status);
        }
        
        // Enable Input....
        status = AudioUnitSetProperty(rioUnit, kAudioOutputUnitProperty_EnableIO, 
									  kAudioUnitScope_Input, AUDIO_INPUT_BUS, &flag, sizeof(flag));
        
        if (status != noErr)
        {
            printf("MUEAudioIO::setupIO: Enable Input failed: status = %d\n", status);
        }
        //-----------------------------------------------------------------
        
        
		// Set up audio I/0 format, data type whatever. Describe the stream.
        // AudioStreamBasicDescription streamDesc;
        // This next function is built into Core Audio
        FillOutASBDForLPCM(m_streamDesc, AUDIO_SAMPLE_RATE, AUDIO_NUM_CHANNELS, AUDIO_BIT_DEPTH,
						   AUDIO_BIT_DEPTH, false, false, AUDIO_FORMAT_IS_NONINTERLEAVED);
        
        
		// XThrowIfError(AudioUnitGetProperty(rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &m_streamDesc, sizeof(m_streamDesc) ), "couldn't get the remote I/O unit's output client format");
        
        // TODO: why is scope input associated with output bus? and vice versa?
		AudioUnitSetProperty(rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, AUDIO_OUTPUT_BUS, &m_streamDesc, sizeof(m_streamDesc));
        AudioUnitSetProperty(rioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, AUDIO_INPUT_BUS, &m_streamDesc, sizeof(m_streamDesc));

/*		// Prints audio configuration settings, why wont this print?
		printf("  m_streamDesc initialized with AUDIO_SAMPLE_RATE  : %f", AUDIO_SAMPLE_RATE);
		printf("                                AUDIO_NUM_CHANNELS : %d", AUDIO_NUM_CHANNELS);
		printf("                                AUDIO_BIT_DEPTH    : %d", AUDIO_BIT_DEPTH);
*/		
		AudioUnitInitialize(rioUnit);

	}
	catch (...) {
		printf("An unknown error occurred\n");
		return 1;
	}	
	
	return 0;
	
	
}