⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorbars.c

📁 Sample code for use on smp 863x processor.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * * Copyright (c) Sigma Designs, Inc. 2002. All rights reserved. * *//**	@file colorbars.c	@brief sample application to test output		@author Julien Soulier, Christian Wolff*/#include "sample_os.h"#include <math.h>#define ALLOW_OS_CODE 1#include "../dcc/include/dcc.h"#include "common.h"RMuint32 chip_num = 0;RMuint32 intensity = 0;enum EMhwlibColorBarsStandard standard = 0;RMbool audio_generate = FALSE;enum audio_gen_type {	audio_gen_tri, 	audio_gen_sin, 	audio_gen_cos, } audio_gen_type = audio_gen_cos;RMuint32 audio_freq = 1000; // Hz of test toneRMuint32 dB = 20;  // default: -20 dB#define GETBUFFER_TIMEOUT_US (TIMEOUT_10MS * 10)#define SENDDATA_TIMEOUT_US  (TIMEOUT_10MS * 10)#define DMA_BUFFER_SIZE_LOG2 15#define DMA_BUFFER_COUNT     32#define AUDIO_FIFO_SIZE ((1<<DMA_BUFFER_SIZE_LOG2)*DMA_BUFFER_COUNT) // 1Mb, matches dma_buffer_count * 2^dma_buffer_size_log2 which is a requirement in standalone#define XFER_FIFO_COUNT (32)#define KEYFLAGS (SET_KEY_DISPLAY | SET_KEY_DEBUG)static RMint32 tri_last = 0, tri_dir = 1;static RMstatus CreateTriangle(RMuint8 *pbuffer, RMuint32 size, RMuint32 *preadSize){	RMuint32 i;		RMDBGLOG((DISABLE, "Filling %lu bytes at %p\n", size, pbuffer));	for (i = 0; i < size / 2; i++) {		tri_last += tri_dir;		if (tri_last >= 32767) {			tri_last = 32767;			tri_dir = -tri_dir;		} else if (tri_last <= -32768) {			tri_last = -32768;			tri_dir = -tri_dir;		}		*pbuffer++ = (tri_last >> 8) & 0xFF;		*pbuffer++ = tri_last & 0xFF;	}	*preadSize = size & ~1;	return RM_OK;}#define sin_size 192// perl -e 'for ($i = 0; $i < 192; $i++) { printf "%6d, ",  int(sin($i * 3.1415926535 * 2 / 192) * 32768); }'static const RMint32 sin_array[sin_size] = {	     0,   1072,   2143,   3211,   4277,   5337,   6392,   7440, 	  8480,   9512,  10532,  11542,  12539,  13523,  14492,  15446, 	 16383,  17303,  18204,  19086,  19947,  20787,  21605,  22399, 	 23170,  23916,  24636,  25330,  25996,  26635,  27245,  27826, 	 28377,  28898,  29388,  29847,  30273,  30667,  31029,  31357, 	 31651,  31912,  32138,  32330,  32487,  32610,  32697,  32750, 	 32767,  32750,  32697,  32610,  32487,  32330,  32138,  31912, 	 31651,  31357,  31029,  30667,  30273,  29847,  29388,  28898, 	 28377,  27826,  27245,  26635,  25996,  25330,  24636,  23916, 	 23170,  22399,  21605,  20787,  19947,  19086,  18204,  17303, 	 16384,  15446,  14492,  13523,  12539,  11542,  10532,   9512, 	  8480,   7440,   6392,   5337,   4277,   3211,   2143,   1072, 	     0,  -1072,  -2143,  -3211,  -4277,  -5337,  -6392,  -7440, 	 -8480,  -9512, -10532, -11542, -12539, -13523, -14492, -15446, 	-16383, -17303, -18204, -19086, -19947, -20787, -21605, -22399, 	-23170, -23916, -24636, -25330, -25996, -26635, -27245, -27826, 	-28377, -28898, -29388, -29847, -30273, -30667, -31029, -31357, 	-31651, -31912, -32138, -32330, -32487, -32610, -32697, -32750, 	-32768, -32750, -32697, -32610, -32487, -32330, -32138, -31912, 	-31651, -31357, -31029, -30667, -30273, -29847, -29388, -28898, 	-28377, -27826, -27245, -26635, -25996, -25330, -24636, -23916, 	-23170, -22399, -21605, -20787, -19947, -19086, -18204, -17303, 	-16384, -15446, -14492, -13523, -12539, -11542, -10532,  -9512, 	 -8480,  -7440,  -6392,  -5337,  -4277,  -3211,  -2143,  -1072};static RMuint64 sin_sample = 0;static RMstatus CreateSine(RMuint8 *pbuffer, RMuint32 size, RMuint32 *preadSize, RMuint32 audio_freq, RMuint32 sample_rate, RMbool cosine, RMuint32 dB){	RMuint32 i, phase;	RMint16 sample;	RMint32 factor = 0;		RMDBGLOG((DISABLE, "Filling %lu bytes at %p\n", size, pbuffer));	if (dB) {		RMreal bel = -0.05;		bel *= dB;		factor = (RMint32)(65536.0 * pow(10.0, bel));		RMDBGLOG((DISABLE, "Attenuating by -%lu dB = %f bel, factor %lu/65536\n", dB, bel, factor));	}	for (i = 0; i < size / 4; i++) {		if (sin_sample == (RMuint64)sin_size * (RMuint64)audio_freq * (RMuint64)sample_rate) sin_sample = 0;		phase = RM64mult32div32(sin_sample, sin_size * audio_freq, sample_rate) % sin_size;		sin_sample++;		// Left		sample = sin_array[phase];		if (factor || dB) sample = (RMint16)(((RMint32)sample) * factor / 65536);		*pbuffer++ = (sample >> 8) & 0xFF;		*pbuffer++ = sample & 0xFF;		// Right		if (cosine) {			phase = (phase + (sin_size * 3 / 4)) % sin_size;  // 90 degree phase shift, cosine on L			sample = sin_array[phase];			if (factor || dB) sample = (RMint16)(((RMint32)sample) * factor / 65536);		}		*pbuffer++ = (sample >> 8) & 0xFF;		*pbuffer++ = sample & 0xFF;	}	*preadSize = size & ~3;	return RM_OK;}static void show_usage(char *progname){	RMDBGPRINT((ENABLE, "COLOR BARS OPTIONS\n"		    "\t-m chip: Select the board number [0]\n"		    "\t-i <0|1>: Set the intensity level [0]=75%%, 1=100%%\n"		    "\t-s <pal|ntsc|auto>: Selects PAL or NTSC white [auto]\n"		    "\t-a <tri|sin|cos> [<freq> [<attenuation>]]: generate audio test signal (tri=triangle (+/-2), sin=sine, [cos]=cosine on L, freq=[1000] Hz attenuation=-[20] dB)\n"));	show_display_options();		RMDBGPRINT((ENABLE, "--------------------------------\n"));	RMDBGPRINT((ENABLE, "Minimum cmd line: %s\n", progname));	RMDBGPRINT((ENABLE, "--------------------------------\n"));}static RMstatus parse_cmdline(int argc, char *argv[], 	struct display_cmdline *disp_opt, 	struct playback_cmdline *play_opt, 	struct audio_cmdline *audio_opt){	RMstatus err = RM_OK;	int i;		if (argc < 1) 		show_usage(argv[0]);	 	i = 1;	while ((argc > i) && (argv[i][0] == '-')) {		if (RMCompareAscii(&(argv[i][1]), "m")) {			RMasciiToUInt32(argv[i+1], &chip_num);			i+=2;		}		else if (RMCompareAscii(&(argv[i][1]), "i")) {			RMasciiToUInt32(argv[i+1], &intensity);			i+=2;		}		else if (RMCompareAscii(&(argv[i][1]), "s")) {			if ( RMCompareAscii(argv[i+1], "pal")) {				standard = EMhwlibColorBarsStandard_PAL;			}			else if ( RMCompareAscii(argv[i+1], "ntsc")) {				standard = EMhwlibColorBarsStandard_NTSC;			}			else if ( RMCompareAscii(argv[i+1], "auto")) {				standard = 0;			}			else {				show_usage(argv[0]);				return RM_ERROR;			}			i+=2;		}		else if (RMCompareAscii(&(argv[i][1]), "a")) {			audio_generate = TRUE;			i++;			if ((i < argc) && (argv[i][0] != '-')) {				if (RMCompareAscii(argv[i], "tri")) {					audio_gen_type = audio_gen_tri;				} else if (RMCompareAscii(argv[i], "sin")) {					audio_gen_type = audio_gen_sin;				} else if (RMCompareAscii(argv[i], "cos")) {					audio_gen_type = audio_gen_cos;				} else {					show_usage(argv[0]);					return RM_ERROR;				}				i++;			}			if ((i < argc) && (argv[i][0] != '-')) {				RMasciiToUInt32(argv[i], &audio_freq);				i++;			}			if ((i < argc) && (argv[i][0] != '-')) {				RMasciiToUInt32(argv[i], &dB);				i++;			}		}		else {			err = parse_display_cmdline(argc, argv, &i, disp_opt);			if (err == RM_ERROR) {				show_usage(argv[0]);				return err;			}			if (err != RM_PENDING)				continue;			err = parse_playback_cmdline(argc, argv, &i, play_opt);			if (err == RM_ERROR) {				show_usage(argv[0]);				return err;			}			if (err != RM_PENDING)				continue;			err = parse_audio_cmdline(argc, argv, &i, audio_opt);			if (RMFAILED(err)) {				show_usage(argv[0]);				return err;			}		}	}		if (argc > i) {		show_usage(argv[0]);		return RM_ERROR;	}		return err;}int main(int argc, char *argv[]){	struct DCC *pDCC = NULL;	struct RUA *pInstance = NULL;	RMuint32 colorbars;	RMbool enable;	RMstatus err;	static struct dcc_context dcc_info = {0,};	struct dh_context dh_info = {0,};	struct display_cmdline disp_opt;	struct display_context disp_info;	struct audio_cmdline audio_opt;	struct playback_cmdline play_opt;	void **dmabuffer_array;	RMuint32 dmabuffer_index;	struct RUABufferPool *pDMA;	RMuint8 *buf = NULL;		init_display_options(&disp_opt);	init_audio_options(&audio_opt);	init_playback_options(&play_opt);	disp_opt.dh_info = &dh_info;	audio_opt.dh_info = &dh_info;		if (RMFAILED(err = parse_cmdline(argc, argv, &disp_opt, &play_opt, &audio_opt))) {		RMDBGLOG((ENABLE, "Error parsing command line! %d\n", err));		return -1;	}		if (RMFAILED(err = RUACreateInstance(&pInstance, chip_num))) {		RMDBGLOG((ENABLE, "Error creating instance! %d\n", err));		return -1;	}		err = DCCOpen(pInstance, &pDCC);	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Error Opening DCC! %d\n", err));		return -1;	}		if (audio_generate) {		err = DCCInitMicroCodeEx(pDCC, disp_opt.init_mode);	} else {		err = DCCInitChainEx(pDCC, disp_opt.init_mode);	}	if (RMFAILED(err)) {		RMDBGLOG((ENABLE, "Cannot initialize microcode %d\n", err));		return -1;	}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -