void log_all_audio_devices(const path_type& output_path) {
#if BUILD_OPENAL
		const auto all_audio_devices = list_audio_devices(alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER));

		LOG(all_audio_devices);
		LOG("Default device: %x", alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER));

		augs::save_as_text(
			output_path,
			all_audio_devices
		);
#else
		(void)output_path;
#endif
	}
示例#2
0
void AudioTest()
{
	int ch, sr, bps, wavsize;
	void *wavdata = LoadWav( "blowraspberry.wav", ch, sr, bps, wavsize );

	list_audio_devices(_alcGetString(NULL, ALC_DEVICE_SPECIFIER));

	const ALCchar *defaultDeviceName = _alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
	ALCdevice *device = _alcOpenDevice(defaultDeviceName);

	ALCcontext *context = _alcCreateContext(device, NULL);
	_alcMakeContextCurrent(context);

	_alListener3f(AL_POSITION, 0, 0, 1.0f);
   	_alListener3f(AL_VELOCITY, 0, 0, 0);
	
	ALfloat listenerOri[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
	ALuint buffer, source;
	
	_alListenerfv(AL_ORIENTATION, listenerOri);
	_alGenSources((ALuint)1, &source);
	_alSourcef(source, AL_PITCH, 1);
	_alSourcef(source, AL_GAIN, 1);
	_alSource3f(source, AL_POSITION, 0, 0, 0);
	_alSource3f(source, AL_VELOCITY, 0, 0, 0);
	_alSourcei(source, AL_LOOPING, AL_FALSE);
	_alGenBuffers(1, &buffer);
	_alBufferData(buffer, AL_FORMAT_MONO8, wavdata, wavsize, sr);

	ALint source_state;
	_alSourcei(source, AL_BUFFER, buffer);
	_alSourcePlay(source);
	_alGetSourcei(source, AL_SOURCE_STATE, &source_state);
	while (source_state == AL_PLAYING) {
		_alGetSourcei(source, AL_SOURCE_STATE, &source_state);
	}
}
示例#3
0
/* ------------------------------------------------------------ */
int main()
{
	list_audio_devices(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
	/* BBBIOlib init*/
	iolib_init();
	iolib_setdir(8,11, BBBIO_DIR_IN);	/* Button */
	iolib_setdir(8,12, BBBIO_DIR_OUT);	/* LED */


//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx | SYS_CAPABILITY_VIDEO_Rx | SYS_CAPABILITY_AUDIO_Tx | SYS_CAPABILITY_AUDIO_Rx;
//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx | SYS_CAPABILITY_AUDIO_Tx;
	sys_info.capability =SYS_CAPABILITY_AUDIO_Rx | SYS_CAPABILITY_VIDEO_Rx;
//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx;

	sys_info.status = SYS_STATUS_INIT;
	sys_info.cam.width = 320;
	sys_info.cam.height = 240;
//	sys_info.cam.pixel_fmt = V4L2_PIX_FMT_YUV420;
	sys_info.cam.pixel_fmt = V4L2_PIX_FMT_YUYV;

	/* alloc RGB565 buffer for frame buffer data store */
	RGB565_buffer = (unsigned char *)malloc(sys_info.cam.width * sys_info.cam.height *2);

	/* step Codec register  */
	avcodec_register_all();
	av_register_all();
	video_encoder_init(sys_info.cam.width, sys_info.cam.height, sys_info.cam.pixel_fmt);
	video_decoder_init(sys_info.cam.width, sys_info.cam.height, sys_info.cam.pixel_fmt);
	printf("Codec init finish\n");

	/* step Frame buffer initial*/
	if(FB_init() == 0) {
		fprintf(stderr, "Frame Buffer init error\n");
	}
	FB_clear(var_info.xres, var_info.yres);

	sys_set_status(SYS_STATUS_IDLE);

	/* Create Video thread */
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Rx) pthread_create(&Video_Rx_thread, NULL, Video_Rx_loop, NULL);
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Tx) pthread_create(&Video_Tx_thread, NULL, Video_Tx_loop, NULL);

	/* Create Audio thread*/
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Rx) pthread_create(&Audio_Rx_thread, NULL, Audio_Rx_loop, NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Tx) pthread_create(&Audio_Tx_thread, NULL, Audio_Tx_loop, NULL);

	/* Signale SIGINT */
	signal(SIGINT, SIGINT_release);

	/* Main loop */
	while(sys_get_status() != SYS_STATUS_RELEASE) {
		/* Button on */
		if (is_high(8,11)) {
			sys_set_status(SYS_STATUS_WORK);
			pin_high(8, 12);	/* LED on*/
		}
		else {
//			FB_clear(var_info.xres, var_info.yres);
//			sys_set_status(SYS_STATUS_IDLE);
			sys_set_status(SYS_STATUS_WORK);
			pin_low(8, 12);	/* LED off */
		}
		//usleep(100000);
		sleep(1);
	}
	pin_low(8, 12); /* LED off */

	/* *******************************************************
	 * Main thread for SIP server communication and HW process
	 *
	 *
	 * *******************************************************/

	/* release */
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Tx) pthread_join(Video_Tx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Rx) pthread_join(Video_Rx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Tx) pthread_join(Audio_Tx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Rx) pthread_join(Audio_Rx_thread,NULL);


	munmap(FB_ptr, FB_scerrn_size);
	close(FB);
	free(RGB565_buffer);

	video_encoder_release();
	video_decoder_release();
	printf("finish\n");
	return 0;
}
示例#4
-23
int main(int argc, char **argv)
{
	ALboolean enumeration;
	const ALCchar *devices;
	const ALCchar *defaultDeviceName = argv[1];
	int ret;
#ifdef LIBAUDIO
	WaveInfo *wave;
#endif
	char *bufferData;
	ALCdevice *device;
	ALvoid *data;
	ALCcontext *context;
	ALsizei size, freq;
	ALenum format;
	ALuint buffer, source;
	ALfloat listenerOri[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
	ALboolean loop = AL_FALSE;
	ALCenum error;
	ALint source_state;

	enumeration = alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT");
	if (enumeration == AL_FALSE)
		fprintf(stderr, "enumeration extension not available\n");

	list_audio_devices(alcGetString(NULL, ALC_DEVICE_SPECIFIER));

	if (!defaultDeviceName)
		defaultDeviceName = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);

	device = alcOpenDevice(defaultDeviceName);
	if (!device) {
		fprintf(stderr, "unable to open default device\n");
		return -1;
	}

	fprintf(stdout, "Device: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER));

	alGetError();

	context = alcCreateContext(device, NULL);
	if (!alcMakeContextCurrent(context)) {
		fprintf(stderr, "failed to make default context\n");
		return -1;
	}
	TEST_ERROR("make default context");

	/* set orientation */
	alListener3f(AL_POSITION, 0, 0, 1.0f);
	TEST_ERROR("listener position");
    	alListener3f(AL_VELOCITY, 0, 0, 0);
	TEST_ERROR("listener velocity");
	alListenerfv(AL_ORIENTATION, listenerOri);
	TEST_ERROR("listener orientation");

	alGenSources((ALuint)1, &source);
	TEST_ERROR("source generation");

	alSourcef(source, AL_PITCH, 1);
	TEST_ERROR("source pitch");
	alSourcef(source, AL_GAIN, 1);
	TEST_ERROR("source gain");
	alSource3f(source, AL_POSITION, 0, 0, 0);
	TEST_ERROR("source position");
	alSource3f(source, AL_VELOCITY, 0, 0, 0);
	TEST_ERROR("source velocity");
	alSourcei(source, AL_LOOPING, AL_FALSE);
	TEST_ERROR("source looping");

	alGenBuffers(1, &buffer);
	TEST_ERROR("buffer generation");

#ifdef LIBAUDIO
	/* load data */
	wave = WaveOpenFileForReading("test.wav");
	if (!wave) {
		fprintf(stderr, "failed to read wave file\n");
		return -1;
	}

	ret = WaveSeekFile(0, wave);
	if (ret) {
		fprintf(stderr, "failed to seek wave file\n");
		return -1;
	}

	bufferData = malloc(wave->dataSize);
	if (!bufferData) {
		perror("malloc");
		return -1;
	}

	ret = WaveReadFile(bufferData, wave->dataSize, wave);
	if (ret != wave->dataSize) {
		fprintf(stderr, "short read: %d, want: %d\n", ret, wave->dataSize);
		return -1;
	}

	alBufferData(buffer, to_al_format(wave->channels, wave->bitsPerSample),
			bufferData, wave->dataSize, wave->sampleRate);
	TEST_ERROR("failed to load buffer data");
#else
	alutLoadWAVFile("test.wav", &format, &data, &size, &freq, &loop);
	TEST_ERROR("loading wav file");

	alBufferData(buffer, format, data, size, freq);
	TEST_ERROR("buffer copy");
#endif

	alSourcei(source, AL_BUFFER, buffer);
	TEST_ERROR("buffer binding");

	alSourcePlay(source);
	TEST_ERROR("source playing");

	alGetSourcei(source, AL_SOURCE_STATE, &source_state);
	TEST_ERROR("source state get");
	while (source_state == AL_PLAYING) {
		alGetSourcei(source, AL_SOURCE_STATE, &source_state);
		TEST_ERROR("source state get");
	}

	/* exit context */
	alDeleteSources(1, &source);
	alDeleteBuffers(1, &buffer);
	device = alcGetContextsDevice(context);
	alcMakeContextCurrent(NULL);
	alcDestroyContext(context);
	alcCloseDevice(device);

	return 0;
}