コード例 #1
0
static PaError InitializeDeviceInfo(PaMacCoreDeviceInfo *macCoreDeviceInfo,  AudioDeviceID macCoreDeviceId, PaHostApiIndex hostApiIndex )
{
    PaDeviceInfo *deviceInfo = &macCoreDeviceInfo->inheritedDeviceInfo;
    deviceInfo->structVersion = 2;
    deviceInfo->hostApi = hostApiIndex;
    
    PaError err = paNoError;
    UInt32 propSize;

    err = conv_err(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL));
    // FIXME: this allocation should be part of the allocations group
    char *name = PaUtil_AllocateMemory(propSize);
    err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
    if (!err) {
        deviceInfo->name = name;
    }
    
    Float64 sampleRate;
    propSize = sizeof(Float64);
    err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyNominalSampleRate, &propSize, &sampleRate));
    if (!err) {
        deviceInfo->defaultSampleRate = sampleRate;
    }


    // Get channel info
    err = GetChannelInfo(deviceInfo, macCoreDeviceId, 1);
    err = GetChannelInfo(deviceInfo, macCoreDeviceId, 0);

    return err;
}
コード例 #2
0
ファイル: sqrUnixSoundMacOSX.c プロジェクト: bhatti/RoarVM
static int getVolume(int dir, double *left, double *right)
{
  UInt32	sz;
  AudioDeviceID	id;
  Float32	chan1, chan2;

  if (!getDefaultDevice(&id, dir))
    return 0;

  sz= sizeof(chan1);
  if (checkError(AudioDeviceGetProperty(id, 1, // left
					dir, kAudioDevicePropertyVolumeScalar,
					&sz, &chan1),
		 "GetProperty", "VolumeScalar"))
    return 0;
  sz= sizeof(chan2);
  if (checkError(AudioDeviceGetProperty(id, 2, // right
					dir, kAudioDevicePropertyVolumeScalar,
					&sz, &chan2),
		 "GetProperty", "VolumeScalar"))
    chan2= chan1;

  *left=  chan1;
  *right= chan2;

  return 1;
}
コード例 #3
0
CoreAudioDriver::CoreAudioDriver( audioProcessCallback processCallback )
		: H2Core::AudioOutput( __class_name )
		, m_bIsRunning( false )
		, mProcessCallback( processCallback )
		, m_pOut_L( NULL )
		, m_pOut_R( NULL )
{
	//INFOLOG( "INIT" );
	m_nSampleRate = Preferences::get_instance()->m_nSampleRate;
	//  m_nBufferSize = Preferences::get_instance()->m_nBufferSize;
	//  BufferSize is currently set to match the default audio device.

	OSStatus err;

	UInt32 size = sizeof( AudioDeviceID );
	err = AudioHardwareGetProperty(
			  kAudioHardwarePropertyDefaultOutputDevice,
			  &size,
			  &m_outputDevice
		  );
	if ( err != noErr ) {
		ERRORLOG( "Could not get Default Output Device" );
	}

	UInt32 dataSize = sizeof( m_nBufferSize );
	err = AudioDeviceGetProperty(
			  m_outputDevice,
			  0,
			  false,
			  kAudioDevicePropertyBufferFrameSize,
			  &dataSize,
			  ( void * )&m_nBufferSize
		  );

	if ( err != noErr ) {
		ERRORLOG( "get BufferSize error" );
	}
	INFOLOG( QString( "Buffersize: %1" ).arg( m_nBufferSize ) );


	// print some info
	AudioStreamBasicDescription outputStreamBasicDescription;
	UInt32 propertySize = sizeof( outputStreamBasicDescription );
	err = AudioDeviceGetProperty( m_outputDevice, 0, 0, kAudioDevicePropertyStreamFormat, &propertySize, &outputStreamBasicDescription );
	if ( err ) {
		printf( "AudioDeviceGetProperty: returned %d when getting kAudioDevicePropertyStreamFormat", err );
	}

	INFOLOG( QString("SampleRate: %1").arg( outputStreamBasicDescription.mSampleRate ) );
	INFOLOG( QString("BytesPerPacket: %1").arg( outputStreamBasicDescription.mBytesPerPacket ) );
	INFOLOG( QString("FramesPerPacket: %1").arg( outputStreamBasicDescription.mFramesPerPacket ) );
	INFOLOG( QString("BytesPerFrame: %1").arg( outputStreamBasicDescription.mBytesPerFrame ) );
	INFOLOG( QString("ChannelsPerFrame: %1").arg( outputStreamBasicDescription.mChannelsPerFrame ) );
	INFOLOG( QString("BitsPerChannel: %1").arg( outputStreamBasicDescription.mBitsPerChannel ) );
}
コード例 #4
0
ファイル: AudioOutput.c プロジェクト: lujianmei/Spark
OSStatus AudioOutputGetVolume(AudioDeviceID device, Float32 *left, Float32 *right) {
  UInt32 size = (UInt32)sizeof(Float32);
  OSStatus err = AudioObjectGetPropertyData(device, &kAudioOutputVolumeProperty, 0, NULL, &size, left);
  if (noErr == err) {
    *right = *left;
  } else if (kAudioHardwareUnknownPropertyError == err) {
    UInt32 channels[2];
    size = (UInt32)sizeof(Float32);
    err = AudioOutputGetStereoChannels(device, &channels[0], &channels[1]);
    if (noErr == err) err = AudioDeviceGetProperty(device, channels[0], FALSE, kAudioDevicePropertyVolumeScalar, &size, left);
    if (noErr == err) err = AudioDeviceGetProperty(device, channels[1], FALSE, kAudioDevicePropertyVolumeScalar, &size, right);
  }
  return err;
}
コード例 #5
0
ファイル: macsnd.c プロジェクト: flybird119/meetphone
static bool_t check_card_capability(AudioDeviceID id, bool_t is_input, char * devname, char *uidname, size_t name_len) {
    unsigned int slen=name_len;
    Boolean writable=0;
    CFStringRef dUID=NULL;
    bool_t ret=FALSE;

    int err =AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyDeviceName, &slen,devname);
    if (err != kAudioHardwareNoError) {
        ms_error("get kAudioDevicePropertyDeviceName error %ld", err);
        return FALSE;
    }
    err =AudioDeviceGetPropertyInfo(id, 0, is_input, kAudioDevicePropertyStreamConfiguration, &slen, &writable);
    if (err != kAudioHardwareNoError) {
        ms_error("get kAudioDevicePropertyDeviceName error %ld", err);
        return FALSE;
    }

    AudioBufferList *buflist = ms_malloc(slen);

    err =
        AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyStreamConfiguration, &slen, buflist);
    if (err != kAudioHardwareNoError) {
        ms_error("get kAudioDevicePropertyDeviceName error %ld", err);
        ms_free(buflist);
        return FALSE;
    }

    UInt32 j;
    for (j = 0; j < buflist->mNumberBuffers; j++) {
        if (buflist->mBuffers[j].mNumberChannels > 0) {
            ret=TRUE;
            break;
        }
    }
    ms_free(buflist);
    if (ret==FALSE) return FALSE;

    slen = sizeof(CFStringRef);
    err =AudioDeviceGetProperty(id, 0, is_input, kAudioDevicePropertyDeviceUID, &slen,&dUID);
    if (err != kAudioHardwareNoError) {
        ms_error("get kAudioHardwarePropertyDevices error %ld", err);
        return FALSE;
    }
    CFStringGetCString(dUID, uidname, sizeof(uidname),CFStringGetSystemEncoding());
    ms_message("CA: devname:%s uidname:%s", devname, uidname);


    return ret;
}
コード例 #6
0
ファイル: coreaudio.c プロジェクト: k4rtik/ultragrid
static void audio_cap_ca_help(const char *driver_name)
{
        UNUSED(driver_name);
        OSErr ret;
        AudioDeviceID *dev_ids;
        int dev_items;
        int i;
        UInt32 size;

        printf("\tcoreaudio : default CoreAudio input\n");
        ret = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL);
        if(ret) goto error;
        dev_ids = malloc(size);
        dev_items = size / sizeof(AudioDeviceID);
        ret = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, dev_ids);
        if(ret) goto error;

        for(i = 0; i < dev_items; ++i)
        {
                char name[128];
                
                size = sizeof(name);
                ret = AudioDeviceGetProperty(dev_ids[i], 0, 0, kAudioDevicePropertyDeviceName, &size, name);
                fprintf(stderr,"\tcoreaudio:%d : %s\n", (int) dev_ids[i], name);
        }
        free(dev_ids);

        return;

error:
        fprintf(stderr, "[CoreAudio] error obtaining device list.\n");
}
コード例 #7
0
static PaError SetFramesPerBuffer(AudioDeviceID device, unsigned long framesPerBuffer, int isInput)
{
    PaError result = paNoError;
    UInt32 preferredFramesPerBuffer = framesPerBuffer;
    //    while (preferredFramesPerBuffer > UINT32_MAX) {
    //        preferredFramesPerBuffer /= 2;
    //    }
    
    UInt32 actualFramesPerBuffer;
    UInt32 propSize = sizeof(UInt32);
    result = conv_err(AudioDeviceSetProperty(device, NULL, 0, isInput, kAudioDevicePropertyBufferFrameSize, propSize, &preferredFramesPerBuffer));
    
    result = conv_err(AudioDeviceGetProperty(device, 0, isInput, kAudioDevicePropertyBufferFrameSize, &propSize, &actualFramesPerBuffer));
    
    if (result != paNoError) {
        // do nothing
    }
    else if (actualFramesPerBuffer > framesPerBuffer) {
        result = paBufferTooSmall;
    }
    else if (actualFramesPerBuffer < framesPerBuffer) {
        result = paBufferTooBig;
    }
    
    return result;    
}
コード例 #8
0
std::vector<UInt32> CoreAudioUtilities::dataSourceList(AudioDeviceID id, bool isInput) {
	OSStatus status = noErr;
	std::vector<UInt32> result;
	Boolean input = (isInput ? TRUE : FALSE);
	UInt32 size = 0;

	status = AudioDeviceGetPropertyInfo(id, 0, input, kAudioDevicePropertyDataSources, &size, NULL);
	if (status) {
		LOG_ERROR("Can't get device property info: kAudioDevicePropertyDataSources");
		return result;
	}

	if (!size) {
		return result;
	}

	UInt32 * ids = (UInt32 *) malloc(size);
	status = AudioDeviceGetProperty(id, 0, input, kAudioDevicePropertyDataSources, &size, ids);
	if (status) {
		LOG_ERROR("Can't get device property: kAudioDevicePropertyDataSources");
	} else {
		for (unsigned i = 0; i < (size / sizeof(UInt32)); i++) {
			result.push_back(ids[i]);
		}
	}

	free(ids);

	return result;
}
コード例 #9
0
PlexAudioDevice::PlexAudioDevice(AudioDeviceID deviceID)
  : m_deviceID(deviceID)
  , m_isValid(false)
  , m_supportsDigital(false)
{
  UInt32   paramSize = 0;
  OSStatus err = noErr;

  // Retrieve the length of the device name.
  SAFELY(AudioDeviceGetPropertyInfo(deviceID, 0, false, kAudioDevicePropertyDeviceName, &paramSize, NULL));
  if (err == noErr)
  {
    // Retrieve the name of the device.
    char* pStrName = new char[paramSize];
    pStrName[0] = '\0';
    
    SAFELY(AudioDeviceGetProperty(deviceID, 0, false, kAudioDevicePropertyDeviceName, &paramSize, pStrName));
    if (err == noErr)
    {
      m_deviceName = pStrName;
      
      // See if the device is writable (can output).
      m_hasOutput = computeHasOutput();
      
      // If the device does have output, see if it supports digital.
      if (m_hasOutput)
        m_supportsDigital = computeDeviceSupportsDigital();
      
      m_isValid = true;
    }
    
    delete[] pStrName;
  }
}
コード例 #10
0
void CCoreAudioHardware::GetOutputDeviceName(std::string& name)
{
  AudioDeviceID deviceId = GetDefaultOutputDevice();

  if(deviceId)
  {
    UInt32 size = 0;
    // TODO: Change to kAudioObjectPropertyObjectName
    AudioDeviceGetPropertyInfo(deviceId,0, false,
      kAudioDevicePropertyDeviceName, &size, NULL);
    char *m_buffer = (char*)malloc(size);

    OSStatus ret = AudioDeviceGetProperty(deviceId, 0, false,
      kAudioDevicePropertyDeviceName, &size, m_buffer);
    if (ret && !m_buffer)
    {
      name ="Default";
    }
    else
    {
      name = m_buffer;
      free(m_buffer);
    }
  }
  else
  {
    name = "Default";
  }
}
コード例 #11
0
/* GstBaseSink vmethod implementations */
static GstCaps *
gst_osx_audio_sink_getcaps (GstBaseSink * sink)
{
  GstCaps *caps;
  GstOsxAudioSink *osxsink;
  OSStatus status;
  AudioValueRange rates[10];
  UInt32 propertySize;
  int i;

  propertySize = sizeof (AudioValueRange) * 9;
  osxsink = GST_OSX_AUDIO_SINK (sink);

  caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
          (sink)));


  status = AudioDeviceGetProperty (osxsink->ringbuffer->device_id, 0, FALSE,
      kAudioDevicePropertyAvailableNominalSampleRates, &propertySize, &rates);

  GST_DEBUG
      ("Getting available sample rates: Status: %ld number of ranges: %lu",
      status, propertySize / sizeof (AudioValueRange));

  for (i = 0; i < propertySize / sizeof (AudioValueRange); i++) {
    GST_LOG_OBJECT (osxsink, "Range from %f to %f", rates[i].mMinimum,
        rates[i].mMaximum);
  }

  return caps;
}
コード例 #12
0
QList<AudioDeviceID> UBAudioQueueRecorder::inputDeviceIDs()
{
    QList<AudioDeviceID> inputDeviceIDs;
    UInt32 deviceIDsArraySize(0);

    AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &deviceIDsArraySize, 0);

    AudioDeviceID deviceIDs[deviceIDsArraySize / sizeof(AudioDeviceID)];

    AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &deviceIDsArraySize, deviceIDs);

    int deviceIDsCount = deviceIDsArraySize / sizeof(AudioDeviceID);

    for (int i = 0; i < deviceIDsCount; i ++)
    {
        AudioStreamBasicDescription sf;
        UInt32 size = sizeof(AudioStreamBasicDescription);

        if (noErr == AudioDeviceGetProperty(deviceIDs[i], 0, true, kAudioDevicePropertyStreamFormat,  &size, &sf))
        {
                inputDeviceIDs << deviceIDs[i];
        }
    }

    /*
    foreach(AudioDeviceID id, inputDeviceIDs)
    {
            qDebug() << "Device" << id <<  deviceNameFromDeviceID(id) << deviceUIDFromDeviceID(id);
    }
    */

    return inputDeviceIDs;
}
コード例 #13
0
ファイル: sqUnixSoundMacOSX.c プロジェクト: lsehub/Handle
// setup conversion from Squeak to device frame format, or vice-versa.
// requires: stereo for output, stereo or mono for input.
//
static int Stream_setFormat(Stream *s, int frameCount, int sampleRate, int stereo)
{
  int nChannels=	1 + stereo;
  AudioStreamBasicDescription imgFmt, devFmt;
  UInt32 sz= sizeof(devFmt);

  if (0 == s->direction) nChannels= 2;	// insist

  if (checkError(AudioDeviceGetProperty(s->id, 0, s->direction,
					kAudioDevicePropertyStreamFormat,
					&sz, &devFmt),
		 "GetProperty", "StreamFormat"))
    return 0;

  debugf("stream %p[%d] device format:\n", s, s->direction);  dumpFormat(&devFmt);

  imgFmt.mSampleRate	   = sampleRate;
  imgFmt.mFormatID	   = kAudioFormatLinearPCM;
#if defined(WORDS_BIGENDIAN)
  imgFmt.mFormatFlags	   = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsBigEndian;
#else
  imgFmt.mFormatFlags	   = kLinearPCMFormatFlagIsSignedInteger;
#endif
  imgFmt.mBytesPerPacket   = SqueakFrameSize / (3 - nChannels);
  imgFmt.mFramesPerPacket  = 1;
  imgFmt.mBytesPerFrame    = SqueakFrameSize / (3 - nChannels);
  imgFmt.mChannelsPerFrame = nChannels;
  imgFmt.mBitsPerChannel   = 16;

  debugf("stream %p[%d] image format:\n", s, s->direction);  dumpFormat(&imgFmt);

  if (s->direction) // input
    {
      if (checkError(AudioConverterNew(&devFmt, &imgFmt, &s->converter), "AudioConverter", "New"))
	return 0;
      sz= sizeof(s->cvtBufSize);
      s->cvtBufSize= 512 * devFmt.mBytesPerFrame;
      if (checkError(AudioConverterGetProperty(s->converter, kAudioConverterPropertyCalculateOutputBufferSize,
					       &sz, &s->cvtBufSize), 
		     "GetProperty", "OutputBufferSize"))
	return 0;
    }
  else // output
    {
      if (checkError(AudioConverterNew(&imgFmt, &devFmt, &s->converter), "AudioConverter", "New"))
	return 0;
    }

  s->channels=   nChannels;
  s->sampleRate= sampleRate;
  s->imgBufSize= SqueakFrameSize * nChannels * frameCount;

  frameCount= max(frameCount, 512 * sampleRate / devFmt.mSampleRate);

  s->buffer= Buffer_new((s->direction ? DeviceFrameSize : SqueakFrameSize) * nChannels * frameCount * 2);

  debugf("stream %p[%d] sound buffer size %d/%d (%d)\n", s, s->direction, s->imgBufSize, s->buffer->size, frameCount);

  return 1;
}
コード例 #14
0
bool PlexAudioDevice::computeDeviceSupportsDigital()
{
  bool ret = false;
  
  OSStatus err = noErr;
  UInt32   paramSize = 0;
    
  // Retrieve all the output streams.
  SAFELY(AudioDeviceGetPropertyInfo(m_deviceID, 0, FALSE, kAudioDevicePropertyStreams, &paramSize, NULL));
  if (err == noErr)
  {
    int numStreams = paramSize / sizeof(AudioStreamID);
    AudioStreamID* pStreams = (AudioStreamID *)malloc(paramSize);

    SAFELY(AudioDeviceGetProperty(m_deviceID, 0, FALSE, kAudioDevicePropertyStreams, &paramSize, pStreams));
    if (err == noErr)
    {
      for (int i=0; i<numStreams && ret == false; i++)
      {
        if (computeStreamSupportsDigital(pStreams[i]))
            ret = true;
      }
    }

    free(pStreams);
  }
  
  return ret;
}
コード例 #15
0
bool CoreAudioUtilities::hasChannel(AudioDeviceID id, bool isInput) {
	OSStatus status = noErr;
	UInt32 size = 0;
	bool result = false;
	Boolean input = (isInput ? TRUE : FALSE);

	status = AudioDeviceGetPropertyInfo(id, 0, input, kAudioDevicePropertyStreamConfiguration, &size, NULL);
	if (status) {
		LOG_ERROR("Can't get device property info: kAudioDevicePropertyStreamConfiguration");
		return false;
	}

	AudioBufferList *list = (AudioBufferList *) malloc(size);
	status = AudioDeviceGetProperty(id, 0, input, kAudioDevicePropertyStreamConfiguration, &size, list);
	if (status) {
		LOG_INFO("Can't get device property: kAudioDevicePropertyStreamConfiguration."
			" The device has no " + (isInput ? std::string("input") : std::string("output")) + " device.");
		free(list);
		return false;
	}

	for (unsigned i = 0; i < list->mNumberBuffers; ++i) {
		if (list->mBuffers[i].mNumberChannels > 0) {
			result = true;
			break;
		}
	}

	free(list);

	return result;
}
コード例 #16
0
/*
==========
idAudioHardwareOSX::GetAvailableNominalSampleRates
==========
*/
void idAudioHardwareOSX::GetAvailableNominalSampleRates( void )
{
    UInt32				size;
    OSStatus			status;
    int			   		i, rangeCount;
    AudioValueRange		*rangeArray;

    status = AudioDeviceGetPropertyInfo( selectedDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates, &size, NULL );
    if ( status != kAudioHardwareNoError )
    {
        common->Warning( "AudioDeviceGetPropertyInfo %d kAudioDevicePropertyAvailableNominalSampleRates failed. status: %s", selectedDevice, ExtractStatus( status ) );
        return;
    }
    rangeCount = size / sizeof( AudioValueRange );
    rangeArray = (AudioValueRange *)malloc( size );

    common->Printf( "%d possible rate(s)\n", rangeCount );

    status = AudioDeviceGetProperty( selectedDevice, 0, false, kAudioDevicePropertyAvailableNominalSampleRates, &size, rangeArray );
    if ( status != kAudioHardwareNoError )
    {
        common->Warning( "AudioDeviceGetProperty %d kAudioDevicePropertyAvailableNominalSampleRates failed. status: %s", selectedDevice, ExtractStatus( status ) );
        free( rangeArray );
        return;
    }

    for( i = 0; i < rangeCount; i++ )
    {
        common->Printf( "  %d: min %g max %g\n", i, rangeArray[ i ].mMinimum, rangeArray[ i ].mMaximum );
    }

    free( rangeArray );
}
コード例 #17
0
bool CAUOutputDevice::GetPreferredChannelLayout(CCoreAudioChannelLayout& layout)
{
  if (!m_DeviceId)
    return false;

  UInt32 propertySize = 0;
  Boolean writable = false;
  OSStatus ret = AudioDeviceGetPropertyInfo(m_DeviceId, 0, false,
    kAudioDevicePropertyPreferredChannelLayout, &propertySize, &writable);
  if (ret)
    return false;

  void* pBuf = malloc(propertySize);
  ret = AudioDeviceGetProperty(m_DeviceId, 0, false,
    kAudioDevicePropertyPreferredChannelLayout, &propertySize, pBuf);
  if (ret)
    CLog::Log(LOGERROR, "CAUOutputDevice::GetPreferredChannelLayout: "
      "Unable to retrieve preferred channel layout. Error = %s", GetError(ret).c_str());
  else
  {
    // Copy the result into the caller's instance
    layout.CopyLayout(*((AudioChannelLayout*)pBuf));
  }
  free(pBuf);
  return (ret == noErr);
}
コード例 #18
0
ファイル: coreaudio_driver.c プロジェクト: Llefjord/jack1
static OSStatus display_device_names()
{
	UInt32 size;
	Boolean isWritable;
	int i, deviceNum;
	OSStatus err;
	CFStringRef UIname;
	
	err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &isWritable);
    if (err != noErr) 
		return err;
		
	deviceNum = size/sizeof(AudioDeviceID);
	AudioDeviceID devices[deviceNum];
	
	err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
    if (err != noErr) 
		return err;
	
	for (i = 0; i < deviceNum; i++) {
        char device_name[256];
		char internal_name[256];
		
		size = sizeof(CFStringRef);
		UIname = NULL;
		err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceUID, &size, &UIname);
		if (err == noErr) {
			CFStringGetCString(UIname, internal_name, 256, CFStringGetSystemEncoding());
		} else {
			goto error;
		}
		
		size = 256;
		err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &size, device_name);
		if (err != noErr) 
			return err; 
		jack_info("ICI");
		jack_info("Device name = \'%s\', internal_name = \'%s\' (to be used as -d parameter)", device_name, internal_name); 
	}
	
	return noErr;

error:
	if (UIname != NULL)
		CFRelease(UIname);
	return err;
}
コード例 #19
0
ファイル: gvOSXAudio.c プロジェクト: AntonioModer/xray-16
static GVBool gviHardwareInitCapture(GVIDevice * device)
{
	GVIHardwareData * data = (GVIHardwareData *)device->m_data;
	UInt32 size;
	OSStatus result;
	GVICapturedFrame * frame;
	int numCaptureBufferBytes;
	int numCaptureBufferFrames;
	int i;

	// get the capture format
	size = sizeof(AudioStreamBasicDescription);
	result = AudioDeviceGetProperty(device->m_deviceID, 0, true, kAudioDevicePropertyStreamFormat, &size, &data->m_captureStreamDescriptor);
	if(result != noErr)
		return GVFalse;

	// create a converter from the capture format to the GV format
	result = AudioConverterNew(&data->m_captureStreamDescriptor, &GVIVoiceFormat, &data->m_captureConverter);
	if(result != noErr)
		return GVFalse;

	// allocate a capture buffer
	data->m_captureBuffer = (GVSample *)gsimalloc(GVIBytesPerFrame);
	if(!data->m_captureBuffer)
	{
		AudioConverterDispose(data->m_captureConverter);
		return GVFalse;		
	}

	// allocate space for holding captured frames
	numCaptureBufferBytes = gviMultiplyByBytesPerMillisecond(GVI_CAPTURE_BUFFER_MILLISECONDS);
	numCaptureBufferBytes = gviRoundUpToNearestMultiple(numCaptureBufferBytes, GVIBytesPerFrame);
	numCaptureBufferFrames = (numCaptureBufferBytes / GVIBytesPerFrame);
	for(i = 0 ; i < numCaptureBufferFrames ; i++)
	{
		frame = (GVICapturedFrame *)gsimalloc(sizeof(GVICapturedFrame) + GVIBytesPerFrame - sizeof(GVSample));
		if(!frame)
		{
			gviFreeCapturedFrames(&data->m_captureAvailableFrames);
			gsifree(data->m_captureBuffer);
			AudioConverterDispose(data->m_captureConverter);
			return GVFalse;
		}
		gviPushFirstFrame(&data->m_captureAvailableFrames, frame);
	}

	// init the last crossed time
	data->m_captureLastCrossedThresholdTime = (data->m_captureClock - GVI_HOLD_THRESHOLD_FRAMES - 1);

	// add property listener
	AudioDeviceAddPropertyListener(device->m_deviceID, 0, true, kAudioDevicePropertyDeviceIsAlive, gviPropertyListener, device);

#if GVI_VOLUME_IN_SOFTWARE
	// init volume
	data->m_captureVolume = (GVScalar)1.0;
#endif

	return GVTrue;
}
コード例 #20
0
ファイル: AudioDevice.cpp プロジェクト: swbiggart/xwaxMac
void    AudioDevice::SetBufferSize(UInt32 size)
{
    UInt32 propsize = sizeof(UInt32);
    verify_noerr(AudioDeviceSetProperty(mID, NULL, 0, mIsInput, kAudioDevicePropertyBufferFrameSize, propsize, &size));

    propsize = sizeof(UInt32);
    verify_noerr(AudioDeviceGetProperty(mID, 0, mIsInput, kAudioDevicePropertyBufferFrameSize, &propsize, &mBufferSizeFrames));
}
コード例 #21
0
ファイル: sound-meter.c プロジェクト: denrusio/vak-opensource
void audio_list_devices ()
{
	unsigned long size, devid [10], ndev, n, alive;
	char devname [100], manuf [100];

	size = sizeof (devid);
	if (AudioHardwareGetProperty (kAudioHardwarePropertyDevices,
	    &size, &devid) != 0) {
		fprintf (stderr, "audio: cannot get audio devices\n");
		exit (-1);
	}
	ndev = size / sizeof (devid[0]);
	printf ("Found %ld audio device%s.\n", ndev, ndev==1 ? "" : "s");

	for (n=0; n<ndev; ++n) {
		printf ("\nDevice %ld: id %08lx\n", n, devid [n]);

		size = sizeof (devname);
		if (AudioDeviceGetProperty (devid [n], 0, false,
		    kAudioDevicePropertyDeviceName, &size, &devname) != 0) {
			fprintf (stderr, "audio: cannot get device name\n");
			continue;
		}
		printf ("Name: %s\n", devname);

		size = sizeof (manuf);
		if (AudioDeviceGetProperty (devid [n], 0, false,
		    kAudioDevicePropertyDeviceManufacturer, &size, &manuf) != 0) {
			fprintf (stderr, "audio: cannot get device manufacturer\n");
			continue;
		}
		printf ("Manufacturer: %s\n", manuf);

		size = sizeof (alive);
		if (AudioDeviceGetProperty (devid [n], 0, false,
		    kAudioDevicePropertyDeviceIsAlive, &size, &alive) != 0) {
			fprintf (stderr, "audio: cannot get device activity\n");
			continue;
		}
		printf ("Alive: %s\n", alive ? "Yes" : "No");

		audio_list_streams (devid [n], 0);
		audio_list_streams (devid [n], 1);
	}
}
コード例 #22
0
ファイル: AudioOutput.c プロジェクト: lujianmei/Spark
OSStatus AudioOutputIsMuted(AudioDeviceID device, Boolean *mute) {
  UInt32 value = 0;
  UInt32 size = (UInt32)sizeof(UInt32);
  OSStatus err = AudioDeviceGetProperty(device, 0, FALSE, kAudioDevicePropertyMute, &size, &value);
  if (noErr == err) {
    *mute = value ? TRUE : FALSE;
  }
  return err;  
}
コード例 #23
0
ファイル: portaudio_driver.c プロジェクト: Llefjord/jack1
static OSStatus get_device_name_from_id(AudioDeviceID id, char name[60])
{
    UInt32 size = sizeof(char) * 60;
	OSStatus stat = AudioDeviceGetProperty(id, 0, false,
					   kAudioDevicePropertyDeviceName,
					   &size,
					   &name[0]);
    return stat;
}
コード例 #24
0
ファイル: coreaudio_driver.c プロジェクト: Llefjord/jack1
static OSStatus get_device_name_from_id(AudioDeviceID id, char name[256])
{
    UInt32 size = sizeof(char) * 256;
    OSStatus res = AudioDeviceGetProperty(id, 0, false,
					   kAudioDevicePropertyDeviceName,
					   &size,
					   &name[0]);
    return res;
}
コード例 #25
0
tuint32 CDeviceCoreAudio::GetMaxBufferSize()
{
	UInt32 outSize = sizeof(AudioValueRange);
	struct AudioValueRange AVR;

	AudioDeviceGetProperty(mAudioDeviceID, 0, FALSE, kAudioDevicePropertyBufferFrameSizeRange, &outSize, &AVR);

	return AVR.mMaximum;
}
コード例 #26
0
tuint32 CDeviceCoreAudio::GetPreferredBufferSize()
{
	UInt32 outSize = sizeof(UInt32);
	UInt32 retVal = 0;

	AudioDeviceGetProperty(mAudioDeviceID, 0, FALSE, kAudioDevicePropertyBufferFrameSize, &outSize, &retVal);

	return retVal;
}
コード例 #27
0
ファイル: CoreAudio.cpp プロジェクト: flyingtime/boxee
bool CCoreAudioDevice::IsRunning()
{
  UInt32 isRunning = false;
  UInt32 size = sizeof(isRunning);
  OSStatus ret = AudioDeviceGetProperty(m_DeviceId, 0, false, kAudioDevicePropertyDeviceIsRunning, &size, &isRunning);
  if (ret)
    return false;
  return (isRunning != 0);
}
コード例 #28
0
ファイル: AudioDevice.cpp プロジェクト: swbiggart/xwaxMac
void    AudioDevice::Init(AudioDeviceID devid, bool isInput)
{
    mID = devid;
    mIsInput = isInput;
    if (mID == kAudioDeviceUnknown) return;
    
    UInt32 propsize;
    
    propsize = sizeof(UInt32);
    verify_noerr(AudioDeviceGetProperty(mID, 0, mIsInput, kAudioDevicePropertySafetyOffset, &propsize, &mSafetyOffset));
    
    propsize = sizeof(UInt32);
    verify_noerr(AudioDeviceGetProperty(mID, 0, mIsInput, kAudioDevicePropertyBufferFrameSize, &propsize, &mBufferSizeFrames));
    
    propsize = sizeof(AudioStreamBasicDescription);
    verify_noerr(AudioDeviceGetProperty(mID, 0, mIsInput, kAudioDevicePropertyStreamFormat, &propsize, &mFormat));

}
コード例 #29
0
ファイル: coreaudio.c プロジェクト: Gardenya/deadbeef
static int
ca_init (void) {
    UInt32 sz;
    char device_name[128];

    sz = sizeof(device_id);
    if (AudioHardwareGetProperty (kAudioHardwarePropertyDefaultOutputDevice, &sz, &device_id)) {
        return -1;
    }

    sz = sizeof (device_name);
    if (AudioDeviceGetProperty (device_id, 1, 0, kAudioDevicePropertyDeviceName, &sz, device_name)) {
           return -1;
    }
    
    sz = sizeof (default_format);
    if (AudioDeviceGetProperty (device_id, 0, 0, kAudioDevicePropertyStreamFormat, &sz, &default_format)) {
        return -1;
    }

    UInt32 bufsize = 4096;
    sz = sizeof (bufsize);
    if (AudioDeviceSetProperty(device_id, NULL, 0, 0, kAudioDevicePropertyBufferFrameSize, sz, &bufsize)) {
        fprintf (stderr, "Failed to set buffer size\n");
    }

    if (ca_apply_format ()) {
        return -1;
    }

    if (AudioDeviceAddIOProc (device_id, ca_buffer_callback, NULL)) {
        return -1;
    }
    
    if (AudioDeviceAddPropertyListener (device_id, 0, 0, kAudioDevicePropertyStreamFormat, ca_fmtchanged, NULL)) {
        return -1;
    }
    
    ca_fmtchanged(0, 0, 0, kAudioDevicePropertyStreamFormat, NULL);

    state = OUTPUT_STATE_STOPPED;

    return 0;
}
コード例 #30
0
ファイル: AudioOutput.c プロジェクト: lujianmei/Spark
OSStatus AudioOutputGetStereoChannels(AudioDeviceID device, UInt32 *left, UInt32 *right) {
  UInt32 channels[2];
  UInt32 size = (UInt32)sizeof(channels);
  OSStatus err = AudioDeviceGetProperty(device, 0, FALSE, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
  if (noErr == err) {
    if (left) *left = channels[0];
    if (right) *right = channels[1];
  }
  return err;
}