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

📄 playlist.c

📁 一款MP3 Player Firmware 的原代码,非常有参考价值
💻 C
📖 第 1 页 / 共 2 页
字号:
// press next/prev direcory buttons to jump between directories.// The next_playlist_ptr() and prev_playlist_ptr() functions need// to report would 'would' happen, so it is not acceptable to store// a single static variable of the "current_list" as was previously// done.  Each directory needs to store its own randomized order// so we can move between them and have all the buttons function// in the way a user expects (songs come up in a seemingly very// "random" order, but all next/prev buttons have highly predictable// behavior when traversing to previously heard songs).  Initialization// is also tricky, because the when the mode is initialized we are// required to start on "current_file", but when a new directory is// entered we're supposed to start at some "random" point in it.static voiddirrand_show_current_playlist(void) // Shows the Current Playlist (randomized){	playlist_t * pl_struct; 	temp_id = ((playlist_list_t *)Addr6(current_playlist))->playlist_start_random;	pl_struct = (playlist_t *)addr6(temp_id);	while (1) {		print_hex32(simm_id_from_pointer(pl_struct));		print_hex32(pl_struct->prev_random);		print_hex32(pl_struct->next_random);		print_hex32(temp_id);		print_str((xdata char *)Addr7(((filelist_t *)Addr7(pl_struct->fl_rec))->long_name));		print_crlf();		if (pl_struct->next_random == temp_id) break;		pl_struct = (playlist_t *)Addr6(pl_struct->next_random);	}	print_crlf();}static playlist_t *dirrand_choose_file(void){	unsigned int count;	playlist_t *entry;	//unsigned int r;	entry = Addr7(dirrand_current_list->playlist_start_sequential);	 //r = rand16();	 //print("rand = ");	 //print_hex16(r);	 //print(", num_unrand_files = ");	 //print_hex16(dirrand_current_list->num_unrand_files);	 //print_crlf();	count = rand16() % dirrand_current_list->num_unrand_files;	#ifdef VERBOSE_DEBUG	printf("begin dirrand_choose_file, count=%u, num_unrand=%u\r\n",		count, dirrand_current_list->num_unrand_files);	#endif	while (1) {		if (!entry->is_randomized) {			#ifdef VERBOSE_DEBUG			printf(" [%lx]", simm_id_from_pointer(entry));			#endif			if (count == 0) {				#ifdef VERBOSE_DEBUG				print("\r\nend dirrand_choose_file\r\n");				#endif				return entry;			}			count--;		} else {			#ifdef VERBOSE_DEBUG			printf(" (%lx)", simm_id_from_pointer(entry));			#endif		}		entry = Addr7(entry->next_sequential);	}}static voiddirrand_initialize(void){	temp_id = first_playlist;	// mark all the directories as not randomized	while (temp_id) {		dirrand_current_list = (playlist_list_t *)addr6(temp_id);		dirrand_current_list->is_randomized_l = 0;		temp_id = dirrand_current_list->next_sequential;	}	dirrand_new_list(((playlist_t *)Addr6(current_file))->playlist, 1);}static simm_iddirrand_new_list(simm_id /* playlist_list_t */ list_id, unsigned char use_current_file){	playlist_t *entry;	//unsigned int num_files=0;	addr6_backup = addr6_val;	addr7_backup = addr7_val;	dirrand_current_list = (playlist_list_t *)Addr6(list_id);	// we're already been to this dir, so no action needed	if (dirrand_current_list->is_randomized_l) {		return dirrand_current_list->playlist_start_random;	}	// a new dir we're not seen before... must initialize it	temp_id = dirrand_current_list->playlist_start_sequential;	dirrand_current_list->num_unrand_files = 0;	dirrand_current_list->is_randomized_l = 1;	while (temp_id) {		entry = (playlist_t *)addr7(temp_id);		entry->is_randomized = 0;		entry->prev_random = 0;		entry->next_random = 0;		temp_id = entry->next_sequential;		dirrand_current_list->num_unrand_files++;	}	if (dirrand_current_list->num_unrand_files > 1) {		dirrand_current_list->num_unrand_files--;		if (use_current_file) {			entry = Addr7(current_file);		} else {			entry = dirrand_choose_file();		}		entry->is_randomized = 1;		temp_id = simm_id_from_pointer(entry);		dirrand_current_list->playlist_start_random = temp_id;		dirrand_current_list->playlist_random_head = temp_id;		dirrand_current_list->playlist_random_tail = temp_id;		#ifdef VERBOSE_DEBUG		print("Init rand one list, 1st=");		print_hex32(temp_id);		print_crlf();		#endif	} else {		temp_id = dirrand_current_list->playlist_start_sequential;		dirrand_current_list->playlist_start_random = temp_id;		dirrand_current_list->num_unrand_files = 0;		entry = (playlist_t *)addr7(temp_id);		entry->prev_random = temp_id;		entry->next_random = temp_id;		entry->is_randomized = 1;	}	addr6_val = addr6_backup;	addr7_val = addr7_backup;	return temp_id;}static voiddirrand_randomize_incremental(simm_id /* playlist_t */ current){	playlist_t *entry;	addr6_backup = addr6_val;	addr7_backup = addr7_val;	entry = (playlist_t *)Addr7(current);	dirrand_current_list = (playlist_list_t *)Addr6(entry->playlist);	if (entry->next_random == 0) {		entry = dirrand_choose_file();		entry->is_randomized = 1;		entry->prev_random = current;		temp_id = simm_id_from_pointer(entry);		entry = (playlist_t *)Addr7(current);		entry->next_random = temp_id;		dirrand_current_list->playlist_random_head = temp_id;		dirrand_current_list->num_unrand_files--;		#ifdef VERBOSE_DEBUG		print("current=");		print_hex32(current);		print(" next=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (entry->prev_random == 0) {		entry = dirrand_choose_file();		entry->is_randomized = 1;		entry->next_random = current;		temp_id = simm_id_from_pointer(entry);		entry = (playlist_t *)Addr7(current);		entry->prev_random = temp_id;		dirrand_current_list->playlist_random_tail = temp_id;		dirrand_current_list->num_unrand_files--;		#ifdef VERBOSE_DEBUG		print("current=");		print_hex32(current);		print(" prev=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (dirrand_current_list->num_unrand_files == 0) {		#ifdef VERBOSE_DEBUG		print("Finalizing, head=");		print_hex32(dirrand_current_list->playlist_random_head);		print("tail=");		print_hex32(dirrand_current_list->playlist_random_tail);		print_crlf();		#endif		((playlist_t *)Addr7(dirrand_current_list->playlist_random_head))->		  next_random = dirrand_current_list->playlist_random_tail;		((playlist_t *)Addr7(dirrand_current_list->playlist_random_tail))->		  prev_random = dirrand_current_list->playlist_random_head;	}	addr6_val = addr6_backup;	addr7_val = addr7_backup;}/*************************************************************************************//* Randomization code for MODE_PLSTRAND (seq within each dir, choose dirs randomly)  *//*************************************************************************************/static playlist_list_t *plstrand_choose_list(void){	unsigned int count;	playlist_list_t *list;	list = (playlist_list_t *)Addr6(first_playlist);	count = rand16() % num_unrand_lists;	#ifdef VERBOSE_DEBUG	printf("begin plstrand_choose_list, count=%u, num_unrand=%u\r\n",		count, num_unrand_lists);	#endif	while (1) {		if (!list->is_randomized_l) {			#ifdef VERBOSE_DEBUG			printf(" [%lx]", simm_id_from_pointer(list));			#endif			if (count == 0) {				#ifdef VERBOSE_DEBUG				print("\r\nend plstrand_choose_list\r\n");				#endif				return list;			}			count--;		} else {			#ifdef VERBOSE_DEBUG			printf(" (%lx)", simm_id_from_pointer(list));			#endif		}		list = (playlist_list_t *)Addr6(list->next_sequential);	}}static voidplstrand_initialize(void){	playlist_list_t *list;	addr6_backup = addr6_val;	/* mark all playlists as not randomized */	num_unrand_lists = 0;	temp_id = first_playlist;	while (temp_id) {		list = (playlist_list_t *)addr6(temp_id);		list->is_randomized_l = 0;		list->next_random = 0;		list->prev_random = 0;		temp_id = list->next_sequential;		num_unrand_lists++;	}	if (num_unrand_lists > 1) {		num_unrand_lists--;		list = Addr6(((playlist_t *)Addr6(current_file))->playlist);		list->is_randomized_l = 1;		temp_id = simm_id_from_pointer(list);		start_rand_playlist = temp_id;		head_rand_playlist = temp_id;		tail_rand_playlist = temp_id;		#ifdef VERBOSE_DEBUG        	print("Init rand lists, 1st=");		print_hex32(temp_id);		print_crlf();		#endif	} else {		num_unrand_lists = 0;		start_rand_playlist = first_playlist;		list = (playlist_list_t *)Addr6(first_playlist);		list->next_random = first_playlist;		list->prev_random = first_playlist;		list->is_randomized_l = 1;	}	addr6_val = addr6_backup;}static voidplstrand_randomize_incremental(simm_id /* playlist_list_t */ list_id){	playlist_list_t *list;	addr6_backup = addr6_val;	list = (playlist_list_t *)Addr6(list_id);	if (list->next_random == 0) {		list = plstrand_choose_list();		list->is_randomized_l = 1;		list->prev_random = list_id;		temp_id = simm_id_from_pointer(list);		list = (playlist_list_t *)Addr6(list_id);		list->next_random = temp_id;		head_rand_playlist = temp_id;		num_unrand_lists--;		#ifdef VERBOSE_DEBUG		print("list_id=");		print_hex32(list_id);		print(" next=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (list->prev_random == 0) {		list = plstrand_choose_list();		list->is_randomized_l = 1;		list->next_random = list_id;		temp_id = simm_id_from_pointer(list);		list = (playlist_list_t *)Addr6(list_id);		list->prev_random = temp_id;		tail_rand_playlist = temp_id;		num_unrand_lists--;		#ifdef VERBOSE_DEBUG		print("list_id=");		print_hex32(list_id);		print(" prev=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (num_unrand_lists == 0) {		#ifdef VERBOSE_DEBUG		print("Finalizing, head=");		print_hex32(head_rand_playlist);		print("tail=");		print_hex32(tail_rand_playlist);		print_crlf();		#endif		((playlist_list_t *)Addr6(head_rand_playlist))->next_random =			tail_rand_playlist;		((playlist_list_t *)Addr6(tail_rand_playlist))->prev_random =			head_rand_playlist;	}	addr6_val = addr6_backup;}/*************************************************************************************//* Randomization code for MODE_ALLRAND (randomly choose files among all dirs)        *//*************************************************************************************/static playlist_t *allrand_choose_file(void){	unsigned int count;	playlist_t *file;	playlist_list_t *list;	count = rand16() % num_unrand_all_files;	#ifdef VERBOSE_DEBUG	printf("begin allrand_choose_file, count=%u, num_unrand=%u\r\n",		count, num_unrand_all_files);	#endif	list = (playlist_list_t *)Addr6(first_playlist);	while (count >= list->num_unrand_files) {		 #ifdef VERBOSE_DEBUG		 print("skipping list ");		 print_hex32(simm_id_from_pointer(list));		 printf(" with %u files\r\n", list->num_unrand_files);		 #endif		count -= list->num_unrand_files;		list = (playlist_list_t *)Addr6(list->next_sequential);	}	#ifdef VERBOSE_DEBUG	print("using list ");	print_hex32(simm_id_from_pointer(list));	printf(" with %u files\r\n", list->num_unrand_files);	#endif	list->num_unrand_files--;	file = (playlist_t *)Addr7(list->playlist_start_sequential);	while (1) {		if (!file->is_randomized) {			#ifdef VERBOSE_DEBUG			printf(" [%lx]", simm_id_from_pointer(file));			#endif			if (count == 0) {				num_unrand_all_files--;				#ifdef VERBOSE_DEBUG				print("\r\nend allrand_choose_file\r\n");				#endif				return file;			}			count--;		} else {			#ifdef VERBOSE_DEBUG			printf(" (%lx)", simm_id_from_pointer(file));			#endif		}		// TODO: using Addr7 causes crash... is this a FPGA		// timing problem, and why does addr7 not crash??		// TODO: is this still a problem ???  Test with different simms		file = (playlist_t *)Addr7(file->next_sequential);	}}static unsigned intallrand_init_one_list(simm_id list_id){	unsigned int count=0;	playlist_t *file;	temp_id = list_id;	while (temp_id) {		file = (playlist_t *)addr7(temp_id);		file->is_randomized = 0;		file->prev_random = 0;		file->next_random = 0;		temp_id = file->next_sequential;		count++;	}	return count;}static voidallrand_initialize(void){	playlist_list_t *list;	playlist_t *file;	addr6_backup = addr6_val;	addr7_backup = addr7_val;	list = (playlist_list_t *)Addr6(first_playlist);	num_unrand_all_files = 0;	while (1) {		num_unrand_all_files += list->num_unrand_files = 		  allrand_init_one_list(list->playlist_start_sequential);		if (list->next_sequential) {			list = (playlist_list_t *)Addr6(list->next_sequential);		} else {			break;		}	}	file = Addr7(current_file);	file->is_randomized = 1;	((playlist_list_t *)Addr6(file->playlist))->num_unrand_files--;	num_unrand_all_files--;	start_all_rand = current_file;	head_all_rand = current_file;	tail_all_rand = current_file;	#ifdef VERBOSE_DEBUG	print("Init rand all, 1st=");	print_hex32(current_file);	print_crlf();	#endif	addr6_val = addr6_backup;	addr7_val = addr7_backup;}static voidallrand_randomize_incremental(simm_id /* playlist_t */ current){	playlist_t *file;	addr6_backup = addr6_val;	addr7_backup = addr7_val;	file = (playlist_t *)Addr7(current);	if (file->next_random == 0) {		file = allrand_choose_file();		file->is_randomized = 1;		file->prev_random = current;		temp_id = simm_id_from_pointer(file);		file = (playlist_t *)Addr7(current);		file->next_random = temp_id;		head_all_rand = temp_id;		#ifdef VERBOSE_DEBUG                print("current=");		print_hex32(current);		print(" next=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (file->prev_random == 0) {		file = allrand_choose_file();		file->is_randomized = 1;		file->next_random = current;		temp_id = simm_id_from_pointer(file);		file = (playlist_t *)Addr7(current);		file->prev_random = temp_id;		tail_all_rand = temp_id;		#ifdef VERBOSE_DEBUG                print("current=");		print_hex32(current);		print(" prev=");		print_hex32(temp_id);		print_crlf();		#endif	}	if (num_unrand_all_files == 0) {		#ifdef VERBOSE_DEBUG		print("Finalizing, head=");		print_hex32(head_all_rand);		print("tail=");		print_hex32(tail_all_rand);		print_crlf();		#endif		((playlist_t *)Addr7(head_all_rand))->next_random = tail_all_rand;		((playlist_t *)Addr7(tail_all_rand))->prev_random = head_all_rand;	}	addr6_val = addr6_backup;	addr7_val = addr7_backup;}		

⌨️ 快捷键说明

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