Exemple #1
0
void MFSound_UpdateInternal()
{
	const int NumSamples = 4096;
	float buffer[NumSamples];

	size_t numCaptureDevices = MFDevice_GetNumDevices(MFDT_AudioCapture);
	for(size_t i=0; i<numCaptureDevices; ++i)
	{
		MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_AudioCapture, i);
		AudioDevice &device = *(AudioDevice*)pDevice->pInternal;

		if(device.pDevice && device.bActive)
		{
			// get samples, and feed to callback
			ALint numSamples;
			alcGetIntegerv(device.pDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &numSamples);

			MFDebug_Assert(false, "TODO: check if numSamples is in samples or bytes...");

			while(numSamples > 0)
			{
				ALint samples = MFMin(1024, numSamples);
				alcCaptureSamples(device.pDevice, (ALCvoid *)buffer, samples);
				numSamples -= samples;

				// feed samples to the callback
				device.pSampleCallback((float*)buffer, samples, 1, device.pUserData);
			}
		}
	}
}
Exemple #2
0
void MFMidi_UpdateInternal()
{
	// copy notes into lastNotes
	size_t numInputDevices = MFDevice_GetNumDevices(MFDT_MidiInput);
	for (int i = 0; i < numInputDevices; ++i)
	{
		MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_MidiInput, i);
		if (pDevice->state == MFDevState_Active)
		{
			MFMidiPC_MidiInputDevice *pMidi = (MFMidiPC_MidiInputDevice*)pDevice->pInternal;
			for (int j = 0; j < 16; ++j)
				MFCopyMemory(pMidi->channels[j].lastNotes, pMidi->channels[j].notes, sizeof(pMidi->channels[j].lastNotes));
		}
	}
}
Exemple #3
0
void MFSound_InitModulePlatformSpecific(int *pSoundDataSize, int *pVoiceDataSize)
{
	MFCALLSTACK;

	gDevices.Init(sizeof(AudioDevice), 8, 8);

	ALCint minor, major;
	alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &major);
	alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &minor);
	gAPIVersion = major*100 + minor;

	bool bCanEnumerate, bHasCapture;
	if(gAPIVersion >= 101)
	{
		bCanEnumerate = true;
		bHasCapture = true;
	}
	else
	{
		bCanEnumerate = alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") == AL_TRUE;
		bHasCapture = alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE") == AL_TRUE;
	}

	if(bCanEnumerate)
	{
		const char *pDevices = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
		const char *pDefault = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
		while(pDevices && *pDevices)
		{
			bool bIsDefault = !MFString_Compare(pDevices, pDefault);
			MFDebug_Log(2, MFStr("OpenAL: found output device '%s'%s", pDevices, bIsDefault ? " (default)" : ""));

			MFDevice *pDevice = MFDevice_AllocDevice(MFDT_AudioRender, &DestroyDevice);
			pDevice->pInternal = gDevices.AllocAndZero();
			pDevice->state = MFDevState_Ready;

			AudioDevice &device = *(AudioDevice*)pDevice->pInternal;
			MFString_CopyN(pDevice->strings[MFDS_ID], pDevices, sizeof(pDevice->strings[MFDS_ID])-1);
			pDevice->strings[MFDS_ID][sizeof(pDevice->strings[MFDS_ID])-1] = 0;
			device.pDevice = NULL;

			if(bIsDefault)
					MFDevice_SetDefaultDevice(MFDT_AudioRender, MFDDT_All, pDevice);

			pDevices += MFString_Length(pDevices) + 1;
		}

		if(!MFDevice_GetDefaultDevice(MFDT_AudioRender, MFDDT_Default))
		{
			MFDebug_Warn(2, "OpenAL: No default output device?");

			// HACK: set it to the first one...
			MFDevice *pDevice = MFDevice_GetDeviceByIndex(MFDT_AudioRender, 0);
			MFDevice_SetDefaultDevice(MFDT_AudioRender, MFDDT_All, pDevice);
		}

		if(bHasCapture)
		{
			pDevices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
			pDefault = alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
			while(pDevices && *pDevices)
			{
				bool bIsDefault = !MFString_Compare(pDevices, pDefault);
				MFDebug_Log(2, MFStr("OpenAL: found capture device '%s'%s", pDevices, bIsDefault ? " (default)" : ""));

				MFDevice *pDevice = MFDevice_AllocDevice(MFDT_AudioCapture, &DestroyDevice);
				pDevice->pInternal = gDevices.AllocAndZero();
				pDevice->state = MFDevState_Ready;

				AudioDevice &device = *(AudioDevice*)pDevice->pInternal;
				MFString_CopyN(pDevice->strings[MFDS_ID], pDevices, sizeof(pDevice->strings[MFDS_ID])-1);
				pDevice->strings[MFDS_ID][sizeof(pDevice->strings[MFDS_ID])-1] = 0;
				device.pDevice = NULL;

				if(bIsDefault)
					MFDevice_SetDefaultDevice(MFDT_AudioCapture, MFDDT_All, pDevice);

				pDevices += MFString_Length(pDevices) + 1;
			}

			if(!MFDevice_GetDefaultDevice(MFDT_AudioCapture, MFDDT_Default))
				MFDebug_Warn(2, "OpenAL: No default capture device?");
		}
	}

	// create a context
	Context *pContext = CreateContext(MFDevice_GetDefaultDevice(MFDT_AudioRender, MFDDT_Default));
	MakeCurrent(pContext);

	// we need to return the size of the internal structures so the platform independant
	// code can make the correct allocations..
	*pSoundDataSize = sizeof(MFSoundDataInternal);
	*pVoiceDataSize = sizeof(MFVoiceDataInternal);
}