コード例 #1
0
tbool CDeviceCoreAudio::Initialize(tint32 iSampleRate, tint iHWBufferSize)
{
	struct AudioTimeStamp timeStamp;
	timeStamp.mFlags = 0;

	Float64 fSampleRate = iSampleRate;

	OSErr err1 = AudioDeviceSetProperty(mAudioDeviceID, &timeStamp, 0, FALSE, kAudioDevicePropertyBufferFrameSize, sizeof(UInt32), &iHWBufferSize);
	OSErr err2 = AudioDeviceSetProperty(mAudioDeviceID, &timeStamp, 0, FALSE, kAudioDevicePropertyNominalSampleRate, sizeof(Float64), &fSampleRate);

	miHWBufferSize = iHWBufferSize;

	mfSampleRate = iSampleRate;


	tbool bIsRateAndBuffOK = ((err1 == 0) && (err2 == 0));

	if (GetInputChannels() <= 0) mbEnableInput = false;
	if (GetOutputChannels() <= 0) mbEnableOutput = false;

	return (bIsRateAndBuffOK && (mbEnableInput || mbEnableOutput));
} // Initialize
コード例 #2
0
tbool CDeviceWaveIO::Initialize(tint32 iSampleRate, tint iHWBufferSamples)
{
	tbool bIsRateAndBuffOK = false;

	AbortCloseAndRelease();

	if (mbDriverPseudoLoaded) {
		mppfOutputs = new float*[WAVE_IO_MAX_OUTPUT_CHANNELS];
		mppfInputs = new float*[WAVE_IO_MAX_INPUT_CHANNELS];

		// Calculate required number of running structs
		tint32 iRunningStructs = iHWBufferSamples / PRF_WAVE_PCM_SAMPLES;
		tint32 iPCMLen = PRF_WAVE_PCM_SAMPLES * sizeof(tfloat32);
		if (iRunningStructs < MIN_RUNNING_WAVE_STRUCTS) {
			iRunningStructs = MIN_RUNNING_WAVE_STRUCTS;
			iPCMLen = (iHWBufferSamples / iRunningStructs) * sizeof(tfloat32);
		}
		else if (iRunningStructs > MAX_RUNNING_WAVE_STRUCTS) {
			iRunningStructs = MAX_RUNNING_WAVE_STRUCTS;
			iPCMLen = (iHWBufferSamples / iRunningStructs) * sizeof(tfloat32);
			tint32 iMaxWavePCMBytes = MAX_WAVE_PCM_SAMPLES * sizeof(tfloat32);
			if (iPCMLen > iMaxWavePCMBytes)
				iPCMLen = iMaxWavePCMBytes;
		}

		// Ensure that PCM size has a number of samples that can be divided by MIN_WAVE_PCM_SAMPLES
		tint32 iMinWavePCMBytes = MIN_WAVE_PCM_SAMPLES * sizeof(tfloat32);
		iPCMLen += (iMinWavePCMBytes - 1);
		iPCMLen /= iMinWavePCMBytes;
		iPCMLen *= iMinWavePCMBytes;

		// Set member variables
		miRunningStructs = iRunningStructs;
		miPCMLen = iPCMLen;

		// Calculate actual number of samples in buffer (may vary from input)
		miHWBufferSize = miRunningStructs * (miPCMLen / sizeof(tfloat32));
		for (tint32 iStructIx = 0; iStructIx < miRunningStructs; iStructIx++) {
			mapcOutputPCM[iStructIx] = new tchar[miPCMLen];
			mapcInputPCM[iStructIx] = new tchar[miPCMLen];
		}
		miSamplesInPCM = miPCMLen / WAVE_IO_MAX_OUTPUT_CHANNELS / (16 / 8);
		mfSampleRate = iSampleRate;

		for (tint i = 0; i < WAVE_IO_MAX_OUTPUT_CHANNELS; i++) {
			mppfOutputs[i] = new tfloat[miSamplesInPCM];
		}
		for (tint i = 0; i < WAVE_IO_MAX_INPUT_CHANNELS; i++) {
			tfloat* pf = mppfInputs[i] = new tfloat[miSamplesInPCM];
			// Init in buffer with zeroes
			for (tint i2 = 0; i2 < miSamplesInPCM; i2++) {
				pf[i2] = 0.0f;
			}
		}

		// We don't do any testing of sample-rate capabilities here - leave that to Start() method
		bIsRateAndBuffOK = true;
	}

	if (GetInputChannels() <= 0) mbInput = false;
	if (GetOutputChannels() <= 0) mbOutput = false;

	return (bIsRateAndBuffOK && (mbInput || mbOutput));
} // Initialize
コード例 #3
0
ファイル: Concat.cpp プロジェクト: zeno40/convnet
	Concat::Concat(const Network* network, const std::wstring& name, const std::vector<Layer*>& inputs) :
		Layer(network, name, NLayerTypes::Concat, GetInputChannels(inputs) * inputs[0]->W * inputs[0]->H, 0, 0, GetInputChannels(inputs), inputs[0]->W, inputs[0]->H, 0, 0, inputs.size(), inputs)
	{
		assert(inputs.size() > 1);
	}