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

📄 sing.c

📁 使用ISP1362芯片的USB_OTG参考设计源代码比较新的版本
💻 C
📖 第 1 页 / 共 3 页
字号:
	
	if ( step )
	{
		if ( step == 1 )
			k	= M_2_dB;
		else if ( step == 2 )
			k	= M_4_dB;
		
		for ( i = 0; i < MEMORY_FILLING_SIZE_FROM_FILE; i += 2 )
		{
		
#ifdef	USE_AUDIO_PEAK_METER

			lev_l		+= ((*(buffer_ptr    )) & 0x8000) ? ~(*(buffer_ptr    )) : (*(buffer_ptr    ));
			lev_r		+= ((*(buffer_ptr + 1)) & 0x8000) ? ~(*(buffer_ptr + 1)) : (*(buffer_ptr + 1));

#endif
		
			*buffer_ptr++		= ((long)(*buffer_ptr) * k) >> (16 + shift);
			*buffer_ptr++		= ((long)(*buffer_ptr) * k) >> (16 + shift);
		}
	}
	else
	{
		for ( i = 0; i < MEMORY_FILLING_SIZE_FROM_FILE; i += 2 )
		{
		
#ifdef	USE_AUDIO_PEAK_METER

			lev_l		+= ((*(buffer_ptr    )) & 0x8000) ? ~(*(buffer_ptr    )) : (*(buffer_ptr    ));
			lev_r		+= ((*(buffer_ptr + 1)) & 0x8000) ? ~(*(buffer_ptr + 1)) : (*(buffer_ptr + 1));
#endif
		
			*buffer_ptr++		>>= shift;
			*buffer_ptr++		>>= shift;
		}
	}

#ifdef	USE_AUDIO_PEAK_METER

	g_peak_meter_left[  g_file_read_buffer_IN ]		= lev_l;
	g_peak_meter_right[ g_file_read_buffer_IN ]		= lev_r;
	
	audio_peak_indicator();

#endif
}


#ifdef		USE_AUDIO_PEAK_METER
//#define		SYNMETRICAL_METER

void audio_peak_indicator( void )
{
	unsigned long	l;
	unsigned long	r;
	char			ls[]	= "                                      ";
	char			rs[]	= "                                      ";
//							   1234567890123456789012345678901234567890

	if ( !gp_is_in_DOS_environment || (g_audio_source == SOURCE_IS_NON_FILE) )
		return;
		
	l	= g_peak_meter_left[  g_file_read_buffer_OUT ];
	r	= g_peak_meter_right[ g_file_read_buffer_OUT ];

	if ( (l >> (g_peak_meter_scaling_level + 6)) || (r >> (g_peak_meter_scaling_level + 6)) )
		g_peak_meter_scaling_level++;
		
	l	>>= g_peak_meter_scaling_level;
	r	>>= g_peak_meter_scaling_level;


#ifdef SYNMETRICAL_METER

	l	= 37 - ((l > 37) ? 37 : l);
	r	= ((r > 37) ? 37 : r);

	*(ls + l)	= 0;
	*(rs + r)	= 0;

	mprintf( (BLACK    << 4) | BLACK,    CONTINUE, "%s", ls );
	mprintf( (WHITE    << 4) | BLACK,    CONTINUE, "%s", ls + l + 1 );
	mprintf( (LIGHTRED << 4) | BLACK,    CONTINUE, "%s", rs );
	mprintf( (BLACK    << 4) | BLACK,    CONTINUE, "%s", rs + r + 1 );

#else

	l	= ((l > 37) ? 35 : l);
	r	= ((r > 37) ? 35 : r);

	*(ls + l)	= 0;
	*(rs + r)	= 0;

	mprintf( (WHITE    << 4) | BLACK,    CONTINUE, "%s", ls );
	mprintf( (BLACK    << 4) | BLACK,    CONTINUE, "%s", ls + l + 1 );
	mprintf( (LIGHTRED << 4) | BLACK,    CONTINUE, "%s", rs );
	mprintf( (BLACK    << 4) | BLACK,    CONTINUE, "%s", rs + r + 1 );
	
#endif

	mprintf( (BLACK << 4) | BLACK,    CONTINUE, "\r" );
}

#endif





void audio_volume_down( void )
{
	audio_volume_value_set( g_audio_level + 1 );
}


void audio_volume_up( void )
{
	audio_volume_value_set( g_audio_level - 1 );
}


void audio_volume_set_delta( char delta )
{
	audio_volume_value_set( g_audio_level + delta );
}


unsigned char audio_volume_mute_toggle( void )
{
	g_audio_mute			= g_audio_mute ? False : True;
	g_audio_level_changed	= AUDIO_LEVEL_CHANGE_TIMELIMIT;
	
	return ( g_audio_mute );
}


char audio_volume_value_set( char value )
{
	if ( (value == GET_CURRENT_VOLUME_LEVEL) || g_audio_mute )
		return ( g_audio_level );

	value	= ( value        < 0     ) ? 0            : value;
	value	= ( VOLUME_LIMIT < value ) ? VOLUME_LIMIT : value;
	
	g_audio_level			= value;
	g_audio_level_changed	= AUDIO_LEVEL_CHANGE_TIMELIMIT;
	return ( value );
}






/*********															*********/
/*																			*/
/*	User interface (to show the audio status) function						*/
/*																			*/
/*		This functions is called from "ui_status_monitor()" in "ui.c" as 		*/
/*		callback function. 													*/
/*		This routine will be installed by "audio_init_commands()" at		*/
/*		audio device enumeration.											*/
/*																			*/
/*********															*********/

#if 0

void audio_status_monitor( unsigned char dummy_for_func_compatibility )
{
	unsigned char	state_change_happened;
	unsigned char	buffer_state;
	unsigned char	buffer_state_color;
	
	dummy_for_func_compatibility	= dummy_for_func_compatibility;		//	This line for erase warning
	
	state_change_happened	= g_audio_current_target_device_address ^ g_previous_audio_state;

	if ( g_audio_level_changed )
	{
		g_audio_level_changed--;

		gotoxy( 1, wherey() );
		mprintf( BG_BLUE | WHITE       , CONTINUE, "    Audio  " );
		mprintf( BG_BLUE | LIGHTGRAY   , CONTINUE, "(addr %2u) : ", g_audio_device_addr );

		if ( g_audio_level_changed == (AUDIO_LEVEL_CHANGE_TIMELIMIT - 1) )
		{
			if ( g_audio_mute )
			{
				mprintf( BG_BLUE | LIGHTRED    , CONTINUE, "Mute ON                                                " );
			}
			else
			{		
				mprintf( BG_BLUE | WHITE    , CONTINUE, "Volume  |---------+---------+--------| %-02ddB         ", g_audio_level * dB_STEP );
				gotoxy( wherex() - g_audio_level - 15, wherey() );
				mprintf( BG_BLUE | YELLOW    , CONTINUE, "*" );
			}
			return;
		}
		else if  ( g_audio_level_changed == 1 )
		{
			state_change_happened	= True;
		}
		else
		{
			if ( g_audio_mute )
				g_audio_level_changed	= AUDIO_LEVEL_CHANGE_TIMELIMIT - 2;		//	To keep indication on screen

			return;
		}
	}

	if ( state_change_happened )
	{
		if ( g_audio_current_target_device_address )
		{
			gotoxy( 1, wherey() );
			mprintf( BG_BLUE | WHITE       , CONTINUE, "    Audio  " );
			mprintf( BG_BLUE | LIGHTGRAY   , CONTINUE, "(addr %2u) : ", g_audio_device_addr );

			mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "USB speaker is " );
			
			if ( g_audio_source == SOURCE_IS_FILE )
			{
				mprintf( BG_BLUE | WHITE,     CONTINUE, "singing" );
				mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ". remaining play time = %03lusec", g_total_music_length_in_sec - bytes_to_sec( g_current_music_time_in_bytes ) );
			}
			else if ( g_audio_source == SOURCE_IS_REMOTE_FILE )
			{
				mprintf( BG_BLUE | WHITE,     CONTINUE, "singing" );
				mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ". (remote file)  Bf state = " );
			}
			else
			{
				mprintf( BG_BLUE | WHITE    , CONTINUE, "beeping                               " );
			}
		}
		else
		{
			//	Audio play finished
		
			gotoxy( 1, wherey() );
			mprintf( BG_BLUE | WHITE       , CONTINUE, "    Audio  " );
			mprintf( BG_BLUE | LIGHTGRAY   , CONTINUE, "(addr %2u) : ", g_audio_device_addr );

			mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "USB speaker ready. Press [a] key to play music        " );
		}
	}

	if ( g_audio_current_target_device_address && (g_audio_source == SOURCE_IS_FILE) )
	{
		buffer_state	= sing_buffer_stored_length();
	
		if ( 29 < buffer_state )
			buffer_state_color		= WHITE;
		else if ( 3 < buffer_state )
			buffer_state_color		= YELLOW;
		else
			buffer_state_color		= LIGHTRED;
	
		gotoxy( 39, wherey() );
		mprintf( BG_BLUE | buffer_state_color, CONTINUE, "singing" );
		
		gotoxy( 70, wherey() );
		mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "%03lu", g_total_music_length_in_sec - bytes_to_sec( g_current_music_time_in_bytes ) );
	}
	else if ( g_audio_current_target_device_address && (g_audio_source == SOURCE_IS_REMOTE_FILE) )
	{
		buffer_state	= sing_buffer_stored_length();
	
		if ( 29 < buffer_state )
			buffer_state_color		= WHITE;
		else if ( 3 < buffer_state )
			buffer_state_color		= YELLOW;
		else
			buffer_state_color		= LIGHTRED;
	
		gotoxy( 39, wherey() );
		mprintf( BG_BLUE | buffer_state_color, CONTINUE, "singing" );
		
		gotoxy( 74, wherey() );
		mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "%02u", buffer_state );
	}
	
	g_previous_audio_state		= g_audio_current_target_device_address;
}


#else

void audio_status_monitor( unsigned char dummy_for_func_compatibility )
{
	unsigned char	state_change_happened;
	unsigned char	buffer_state;
	unsigned char	buffer_state_color;
	
	dummy_for_func_compatibility	= dummy_for_func_compatibility;		//	This line for erase warning
	
	state_change_happened	= g_audio_current_target_device_address ^ g_previous_audio_state;

	if ( g_audio_level_changed )
	{
		g_audio_level_changed--;
	
		if ( g_audio_level_changed == (AUDIO_LEVEL_CHANGE_TIMELIMIT - 1) )
		{
			if ( g_audio_mute )
			{
				mprintf( BG_BLUE | WHITE       , CONTINUE, "    Audio            : " );
				mprintf( BG_BLUE | LIGHTRED    , CONTINUE, "Mute ON                                                " );
			}
			else
			{		
				mprintf( BG_BLUE | WHITE    , CONTINUE, "    Audio            : Volume  |---------+---------+--------| %-02ddB         ", g_audio_level * dB_STEP );
				gotoxy( wherex() - g_audio_level - 15, wherey() );
				mprintf( BG_BLUE | YELLOW    , CONTINUE, "*" );
			}
			return;
		}
		else if  ( g_audio_level_changed == 1 )
		{
			state_change_happened	= True;
		}
		else
		{
			if ( g_audio_mute )
				g_audio_level_changed	= AUDIO_LEVEL_CHANGE_TIMELIMIT - 2;		//	To keep indication on screen

			return;
		}
	}

	if ( state_change_happened )
	{
		if ( g_audio_current_target_device_address )
		{
			mprintf( BG_BLUE | WHITE    , CONTINUE, "    Audio            : " );
			mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "USB speaker is " );
			
			if ( g_audio_source == SOURCE_IS_FILE )
			{
				mprintf( BG_BLUE | WHITE,     CONTINUE, "singing" );
				mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ". remaining play time = %03lusec", g_total_music_length_in_sec - bytes_to_sec( g_current_music_time_in_bytes ) );
			}
			else if ( g_audio_source == SOURCE_IS_REMOTE_FILE )
			{
				mprintf( BG_BLUE | WHITE,     CONTINUE, "singing" );
				mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ". (remote file)  Bf state = " );
			}
			else
			{
				mprintf( BG_BLUE | WHITE    , CONTINUE, "beeping                               " );
			}
		}
		else
		{
			//	Audio play finished
		
			mprintf( BG_BLUE | WHITE    , CONTINUE, "    Audio            " );
//			mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ": USB speaker ready. Press [a] key to play music        " );
			mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, ": ready. %s", g_audio_device_name );
		}
	}

	if ( g_audio_current_target_device_address && (g_audio_source == SOURCE_IS_FILE) )
	{
		buffer_state	= sing_buffer_stored_length();
	
		if ( 29 < buffer_state )
			buffer_state_color		= WHITE;
		else if ( 3 < buffer_state )
			buffer_state_color		= YELLOW;
		else
			buffer_state_color		= LIGHTRED;
	
		gotoxy( 39, wherey() );
		mprintf( BG_BLUE | buffer_state_color, CONTINUE, "singing" );
		
		gotoxy( 70, wherey() );
		mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "%03lu", g_total_music_length_in_sec - bytes_to_sec( g_current_music_time_in_bytes ) );
	}
	else if ( g_audio_current_target_device_address && (g_audio_source == SOURCE_IS_REMOTE_FILE) )
	{
		buffer_state	= sing_buffer_stored_length();
	
		if ( 29 < buffer_state )
			buffer_state_color		= WHITE;
		else if ( 3 < buffer_state )
			buffer_state_color		= YELLOW;
		else
			buffer_state_color		= LIGHTRED;
	
		gotoxy( 39, wherey() );
		mprintf( BG_BLUE | buffer_state_color, CONTINUE, "singing" );
		
		gotoxy( 74, wherey() );
		mprintf( BG_BLUE | LIGHTGRAY, CONTINUE, "%02u", buffer_state );
	}
	
	g_previous_audio_state		= g_audio_current_target_device_address;
}

#endif





unsigned char get_music_number( void )
{
	char				s[ 40 ];
	unsigned char		selection;
	unsigned char		selection_lim;
	int					i;

//	if ( !(*(gp_sing_file_strings[ 2 ].file_path_and_name)) )
//		return ( 0 );
	
	mprintf( WHITE, CONTINUE, "\r\n    music file list (local peer) :\r\n" );
//	mprintf( WHITE, CONTINUE,     "    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n" );

	for ( i = 0; i < MAX_NUM_OF_AUDIO_FILES; i++ )
	{
		if ( !(*gp_sing_file_strings[ i ].file_path_and_name) )
			break;
			
		mprintf( LIGHTRED, CONTINUE, "      [%d]   ", i );
		
		strncpy( s, gp_sing_file_strings[ i ].file_path_and_name, 25 );
		*(s + 25)	= 0;
		mprintf( WHITE, CONTINUE, "%-25s", s );

		strncpy( s, gp_sing_file_strings[ i ].file_comment, 38 );
		*(s + 38)	= 0;
		mprintf( WHITE, CONTINUE, "  : %s", s );
		mprintf( WHITE, CONTINUE, "\r\n" );
	}
	
	selection_lim	= i;

	for ( ; i < MAX_NUM_OF_AUDIO_FILES; i++ )
		mprintf( RED, CONTINUE, "      [%d]\r\n", i );
	
#if 1
#ifdef AUDIO_FROM_STORAGE

	if ( storage_volume_ready() )
	{
		mprintf( LIGHTRED, CONTINUE,   "      [a]" );
		mprintf( LIGHTCYAN, CONTINUE,  "|" );
		mprintf( LIGHTRED, CONTINUE,   "[o]" );
		mprintf( LIGHTCYAN, CONTINUE,  " for OTG, " );
		mprintf( LIGHTRED, CONTINUE,   "[s]" );
		mprintf( LIGHTCYAN, CONTINUE,  " for USB-storage" );
	}
	else
	{
		mprintf( LIGHTRED, CONTINUE,   "      [a]" );
		mprintf( LIGHTCYAN, CONTINUE,  " or " );
		mprintf( LIGHTRED, CONTINUE,   "[o]" );
		mprintf( LIGHTCYAN, CONTINUE,  " for OTG remote file play..." );
	}

#else	//	AUDIO_FROM_STORAGE

	mprintf( LIGHTRED, CONTINUE,   "      [a]" );
	mprintf( LIGHTCYAN, CONTINUE,  " or " );
	mprintf( LIGHTRED, CONTINUE,   "[o]" );
	mprintf( LIGHTCYAN, CONTINUE,  " for OTG remote file play..." );

#endif	//	AUDIO_FROM_STORAGE

	mprintf( YELLOW, CONTINUE,     "          your selection : [ ]" );
	
	gotoxy( wherex() - 2, wherey() );

	selection	= ui_key_wait();
	
	mprintf( YELLOW, CONTINUE, "%c]\r\n\r\n", selection );
	
#else	//	1

	mprintf( LIGHTRED, CONTINUE, "      [a]" );
	mprintf( LIGHTCYAN, CONTINUE, " or " );
	mprintf( LIGHTRED, CONTINUE, "[o]" );
	mprintf( LIGHTCYAN, CONTINUE, " for OTG remote file play...\r\n" );
	mprintf( YELLOW, CONTINUE, "                                           your selection : [ ]\r" );
	mprintf( YELLOW, CONTINUE, "                                           your selection : [" );
	
	selection	= ui_key_wait();
	
	mprintf( YELLOW, CONTINUE, "\r                                           your selection : [%c]\r\n\r\n", selection );
	
#endif	//	1

	if ( selection == 0x0D )
		selection	= 0;
	else if ( (selection == 'O') || (selection == 'o') || (selection == 'A') || (selection == 'a') )
		selection	= OTG_AUDIO_SPECIAL_CODE | OTG_AUDIO_MANUAL_SELECTION;

#ifdef AUDIO_FROM_STORAGE

	else if ( (selection == 'S') || (selection == 's') )
	{
		if ( storage_volume_ready() )
			selection	= STORAGE_AUDIO_SPECIAL_CODE;
		else
		{
			mprintf( LIGHTRED,   CONTINUE, "\r\n  USB-storage volume " );
			mprintf( LIGHTGREEN, CONTINUE, "is not ready to use.\r\n" );
			return ( 0xFF );
		}
	}
#endif	//	AUDIO_FROM_STORAGE

	else
		selection	-= '0';

	if ( !(selection & 0xF0) )
		if ( !(selection < selection_lim) )
			return ( 0xFF );
	
	return ( selection );
}






















⌨️ 快捷键说明

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