diff --git a/lyric_analysis/bin/main b/lyric_analysis/bin/main new file mode 100755 index 0000000..d3cc908 Binary files /dev/null and b/lyric_analysis/bin/main differ diff --git a/lyric_analysis/lrc/简单爱.lrc b/lyric_analysis/lrc/简单爱.lrc new file mode 100755 index 0000000..a05be43 --- /dev/null +++ b/lyric_analysis/lrc/简单爱.lrc @@ -0,0 +1,30 @@ +[ti:简单爱] +[ar:周杰伦] +[al:范特西] +[by:大脸猫] +[00:04.41]周杰伦 Chow, Jay Jou +[00:10.56]简单爱(台视Star blue蓝星主题曲) +[00:18.48]词:徐若瑄 曲:周杰伦 +[00:26.44]说不上为什么 我变得很主动 +[00:31.37]若爱上一个人 什么都会值得去做 +[02:04.94][00:36.09]我想大声宣布 对你依依不舍 +[02:09.97][00:41.26]连隔壁邻居都猜到我现在的感受 +[02:14.94][00:46.17]河边的风 在吹着头发 飘动 +[02:19.80][00:51.25]牵着你的手 一阵莫名感动 +[02:24.61][00:55.86]我想带你 回我的外婆家 +[02:28.32][00:59.79]一起看着日落 一直到我们都睡着 +[03:34.64][02:34.71][01:05.83]我想就这样牵着你的手不放开 +[03:39.68][02:39.34][01:10.71]爱能不能够永远单纯没有悲哀 +[03:44.27][02:43.90][01:15.44]我想 带你骑单车 +[03:46.74][02:46.60][01:18.05]我想 和你看棒球 +[03:49.77][02:49.58][01:20.71]想这样没担忧 +[03:51.61][02:51.59][01:22.69]唱着歌 一直走☆ +[03:54.38][02:54.35][01:25.57]我想就这样牵着你的手不放开 +[03:59.19][02:59.01][01:30.41]爱可不可以简简单单没有伤害 +[04:03.77][03:03.73][01:35.04]你 靠着我的肩膀 +[04:06.33][03:06.26][01:37.49]你 在我胸口睡着 +[04:09.13][03:09.34][01:40.57]像这样的生活 +[04:11.36][03:11.26][01:42.66]我爱你 你爱我★ +[03:13.76][01:44.97]想~~~ 简!简!单!单! 爱~~~ +[03:23.61][01:54.30]想~~~ 简!简!单!单! 爱~~~ + diff --git a/lyric_analysis/objs/console.o b/lyric_analysis/objs/console.o new file mode 100644 index 0000000..f62fa4a Binary files /dev/null and b/lyric_analysis/objs/console.o differ diff --git a/lyric_analysis/objs/lrc.o b/lyric_analysis/objs/lrc.o new file mode 100644 index 0000000..fe8db8a Binary files /dev/null and b/lyric_analysis/objs/lrc.o differ diff --git a/lyric_analysis/objs/main.o b/lyric_analysis/objs/main.o new file mode 100644 index 0000000..92a2ceb Binary files /dev/null and b/lyric_analysis/objs/main.o differ diff --git a/lyric_analysis/objs/start_mplayer.o b/lyric_analysis/objs/start_mplayer.o new file mode 100644 index 0000000..29b4460 Binary files /dev/null and b/lyric_analysis/objs/start_mplayer.o differ diff --git a/lyric_analysis/songs/简单爱.mp3 b/lyric_analysis/songs/简单爱.mp3 new file mode 100755 index 0000000..f9eb1ad Binary files /dev/null and b/lyric_analysis/songs/简单爱.mp3 differ diff --git a/lyric_analysis/srcs/Makefile b/lyric_analysis/srcs/Makefile new file mode 100644 index 0000000..df3ff8e --- /dev/null +++ b/lyric_analysis/srcs/Makefile @@ -0,0 +1,19 @@ +# SRC_DIR := ./srcs +OBJ_DIR := ../objs +BIN_DIR := ../bin +CC = gcc +TARGET = $(BIN_DIR)/main +# SRC = $(SRC_DIR)/lrc.c $(SRC_DIR)/console.c $(SRC_DIR)/start_mplayer.c $(SRC_DIR)/main.c +OBJ = $(OBJ_DIR)/lrc.o $(OBJ_DIR)/console.o $(OBJ_DIR)/start_mplayer.o $(OBJ_DIR)/main.o + +# $(OBJ_DIR)/%.o: %.c +# $(CC) -c $< -o $@ + +$(OBJ_DIR)/%.o: %.c + $(CC) -c $< -o $@ + +$(TARGET): $(OBJ) + $(CC) $^ -o $@ + +clean: + rm -rf $(OBJ_DIR)/*.o $(TARGET) \ No newline at end of file diff --git a/lyric_analysis/srcs/console.c b/lyric_analysis/srcs/console.c new file mode 100755 index 0000000..7647d51 --- /dev/null +++ b/lyric_analysis/srcs/console.c @@ -0,0 +1,57 @@ +#include +#include +#include "./includes/console.h" + +void cusor_moveto(int x, int y) +{ // ESC[y;xH + printf("\033[%d;%dH", y, x); + fflush(stdout); +} + +//保存光标位置 +void cusor_get_pos(void) +{ // ESC[s + printf("\033[s"); + fflush(stdout); +} + +//恢复光标位置 +void cusor_set_pos(void) +{ // ESC[u + printf("\033[u"); + fflush(stdout); +} +void cusor_hide(void) +{ + printf("\033[?25l"); +} +//清屏 +void clear_screen(void) +{ // ESC[2J + printf("\033[2J"); + fflush(stdout); +} + +/* +COLOR_RED 红 +COLOR_BLACK 黑 +COLOR_GREEN 绿 +COLOR_BLUE 蓝 +COLOR_YELLOW 黄 +COLOR_WHITE 白 +COLOR_CYAN 青 +COLOR_MAGENTA 洋红 +*/ +//设置前景颜色 +void set_fg_color(int color) +{ // ESC[#m + printf("\033[%dm", color); + fflush(stdout); +} + +//设置背景颜色 +void set_bg_color(int color) +{ // ESC[#m + printf("\033[%dm", (color + 10)); + fflush(stdout); +} \ No newline at end of file diff --git a/lyric_analysis/srcs/includes/console.h b/lyric_analysis/srcs/includes/console.h new file mode 100755 index 0000000..5ee248c --- /dev/null +++ b/lyric_analysis/srcs/includes/console.h @@ -0,0 +1,33 @@ +#ifndef _CONSOLE_H_ +#define _CONSOLE_H_ + +#define COLOR_RED 31 +#define COLOR_BLACK 30 +#define COLOR_GREEN 32 +#define COLOR_BLUE 34 +#define COLOR_YELLOW 33 +#define COLOR_WHITE 37 +#define COLOR_CYAN 36 +#define COLOR_MAGENTA 35 +/* +COLOR_RED 红 +COLOR_BLACK 黑 +COLOR_GREEN 绿 +COLOR_BLUE 蓝 +COLOR_YELLOW 黄 +COLOR_WHITE 白 +COLOR_CYAN 青 +COLOR_MAGENTA 洋红 +*/ + +extern void cusor_moveto(int x, int y);//光标跳转到 y行 x列 +extern void cusor_get_pos(void);//保存光标位置 +extern void cusor_hide(void); +extern void cusor_set_pos(void);//恢复光标位置 +extern void clear_screen(void);//清屏 +extern void set_fg_color(int color);//设置字体前景色 +extern void set_bg_color(int color);//设置字体背景色 + +#endif //_CONSOLE_H_ + + diff --git a/lyric_analysis/srcs/includes/lrc.h b/lyric_analysis/srcs/includes/lrc.h new file mode 100644 index 0000000..430e488 --- /dev/null +++ b/lyric_analysis/srcs/includes/lrc.h @@ -0,0 +1,11 @@ +#ifndef __LRC_H__ +#define __LRC_H__ + +#include +#include +#include + +FILE *open_lrc_file(const char *lrc_path); // 打开歌词文件 +long get_lrc_size(FILE *fp); // 获取歌词文件大小 + +#endif \ No newline at end of file diff --git a/lyric_analysis/srcs/includes/start_mplayer.h b/lyric_analysis/srcs/includes/start_mplayer.h new file mode 100755 index 0000000..8fda957 --- /dev/null +++ b/lyric_analysis/srcs/includes/start_mplayer.h @@ -0,0 +1,6 @@ +#ifndef __START_MPLAYER_H__ +#define __START_MPLAYER_H__ +//启动mplayer播放器 +//参数song_path 为歌曲的路径 +extern void mplayer_play(const char *song_path); +#endif \ No newline at end of file diff --git a/lyric_analysis/srcs/lrc.c b/lyric_analysis/srcs/lrc.c new file mode 100644 index 0000000..4422ae9 --- /dev/null +++ b/lyric_analysis/srcs/lrc.c @@ -0,0 +1,20 @@ +#include "./includes/lrc.h" + +FILE *open_lrc_file(const char *lrc_path) +{ + FILE *fp = fopen(lrc_path, "rb"); + if (fp == NULL) + { + return NULL; + } + return fp; +} + +long get_lrc_size(FILE *fp) +{ + fseek(fp, 0, SEEK_END); // fseek()将文件指针移动到文件末尾 + long size = ftell(fp); // ftell()返回当前文件指针位置, 即文件大小 + rewind(fp); // rewind()将文件指针移动到文件开头 + printf("歌词大小为: %ld Byte\n", size); + return size; +} \ No newline at end of file diff --git a/lyric_analysis/srcs/main.c b/lyric_analysis/srcs/main.c new file mode 100644 index 0000000..5d0081c --- /dev/null +++ b/lyric_analysis/srcs/main.c @@ -0,0 +1,31 @@ +#include "./includes/lrc.h" +#include "./includes/console.h" +#include "./includes/start_mplayer.h" + +int main() +{ + // 定义歌曲和歌词文件路径 + const char *song_path = "../songs/简单爱.mp3"; + const char *lrc_path = "../lrc/简单爱.lrc"; + + FILE *fp = open_lrc_file(lrc_path); // 打开歌词文件 + if (NULL == fp) + { + printf("歌词打开失败\n"); + perror("fopen"); + return -1; // 打开歌词文件失败,退出程序 + } + mplayer_play(song_path); // 启动mplayer播放器,播放歌曲 + + long lrc_size = get_lrc_size(fp); // 获取并打印歌词文件大小 + + char *lrc_mem_data = (char *)malloc(lrc_size); // 为歌词数据分配内存 + if (NULL == lrc_mem_data) + { + printf("歌词数据分配内存失败\n"); + perror("malloc"); + return -1; // 为歌词数据分配内存失败,退出程序 + } + + return 0; +} \ No newline at end of file diff --git a/lyric_analysis/srcs/start_mplayer.c b/lyric_analysis/srcs/start_mplayer.c new file mode 100755 index 0000000..0246c1b --- /dev/null +++ b/lyric_analysis/srcs/start_mplayer.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include "./includes/start_mplayer.h" +//启动mplayer播放器:需要安装mplayer, 安装命令:sudo apt install mplayer -y +//命令测试mplayer播放器: mplayer 简单爱.mp3 +//参数song_path 为歌曲的路径 +void mplayer_play(const char *song_path) // 启动mplayer播放器,播放歌曲 +{ + pid_t pid; // 进程id + pid = fork(); // 创建子进程, 用于启动mplayer播放器 + if (pid < 0) // 创建失败, fork()返回值小于0,表示创建子进程失败 + { + perror("fork"); // 打印错误信息 + } + else if (pid == 0) // 子进程中, fork()返回值为0,表示当前进程为子进程 + { + close(1); // 关闭标准输出 + close(2); // 关闭标准错误输出 + // 启动mplayer播放器,参数为歌曲路径,-slave表示mplayer进入slave模式,-quiet表示mplayer进入安静模式,不输出任何信息,NULL表示参数列表结束,execlp()函数执行成功后,当前进程就被替换成mplayer进程,所以当前进程不会执行到下面的代码 + execlp("mplayer", "mplayer", "-slave", "-quiet", song_path, NULL); + // execlp("mplayer", "mplayer", "-slave", song_path, NULL); + exit(0); // 子进程退出 + } +} \ No newline at end of file diff --git a/lyric_analysis/srcs/time_delay.c b/lyric_analysis/srcs/time_delay.c new file mode 100755 index 0000000..443b9d0 --- /dev/null +++ b/lyric_analysis/srcs/time_delay.c @@ -0,0 +1,26 @@ +#include +#include +void time_delay(int sec) +{ + int s_time,e_time; + s_time=time(NULL); + while(1) + { + e_time=time(NULL); + if(e_time==s_time+sec) + break; + } +} +int main(int argc, char *argv[]) +{ + while(1) + { + printf("hello world\n"); + time_delay(3); + } + return 0; +} + + + +