une ancienne version
This commit is contained in:
		
							parent
							
								
									04544e9500
								
							
						
					
					
						commit
						1584115e8b
					
				
							
								
								
									
										3
									
								
								Ecoute/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Ecoute/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| 
 | ||||
| ecoute | ||||
| 
 | ||||
							
								
								
									
										60
									
								
								Ecoute/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Ecoute/Makefile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | ||||
| #----------------------------------------------------------------
 | ||||
| #
 | ||||
| #	abominable sound console player
 | ||||
| #	by Thierry 'tth' Boudet		- build on Slackware.
 | ||||
| #
 | ||||
| #	Recent versions: http://tontonth.free.fr/
 | ||||
| #	complains go to "tontonth O free o fr".
 | ||||
| #
 | ||||
| #----------------------------------------------------------------
 | ||||
| 
 | ||||
| VERSION=0.0036 | ||||
| 
 | ||||
| TEKFLAG= -DDEBUG_LEVEL=1 -g | ||||
| CFLAGS=-Wall -Wextra -ansi  $(TEKFLAG) -DVERSION=\"$(VERSION)\" | ||||
| BIBS=-lncurses -lao -lsndfile -logg | ||||
| 
 | ||||
| #---------------------------------------------------------
 | ||||
| 
 | ||||
| all:	ecoute | ||||
| 
 | ||||
| #---------------------------------------------------------
 | ||||
| 
 | ||||
| main.o:		main.c		ecoute.h	Makefile | ||||
| ecran.o:	ecran.c		ecoute.h	Makefile | ||||
| dump.o:		dump.c		ecoute.h	Makefile | ||||
| magic.o:	magic.c		ecoute.h	Makefile | ||||
| interactive.o:	interactive.c	ecoute.h	Makefile | ||||
| fonctions.o:	fonctions.c	ecoute.h	Makefile | ||||
| ifao.o:		ifao.c		ecoute.h	Makefile | ||||
| playwav.o:	playwav.c	ecoute.h	Makefile | ||||
| playnote.o:	playnote.c	ecoute.h	Makefile | ||||
| playau.o:	playau.c	ecoute.h	Makefile | ||||
| playogg.o:	playogg.c	ecoute.h	Makefile | ||||
| playspeex.o:	playspeex.c	ecoute.h	Makefile | ||||
| playflac.o:	playflac.c	ecoute.h	Makefile | ||||
| 
 | ||||
| OBJ=main.o ecran.o playnote.o playwav.o playogg.o fonctions.o interactive.o \
 | ||||
| 	dump.o playau.o playspeex.o playflac.o magic.o ifao.o | ||||
| 
 | ||||
| ecoute:		$(OBJ) | ||||
| 	gcc $(TEKFLAG) $(OBJ) $(BIBS) -o ecoute | ||||
| 
 | ||||
| #---------------------------------------------------------
 | ||||
| #  services targets
 | ||||
| 
 | ||||
| FILES=*.c *.h *.txt Makefile *.man *.html | ||||
| 
 | ||||
| install:	ecoute | ||||
| 	cp ./ecoute /usr/local/bin | ||||
| 
 | ||||
| lines: | ||||
| 	wc  $(FILES) | sort -n | ||||
| 
 | ||||
| tarball: $(FILES) | ||||
| 	ls $^ > MANIFEST ;			\
 | ||||
| 	( cd .. ;				\
 | ||||
| 	tar zcvf ecoute-$(VERSION).tar.gz `sed 's/^/Ecoute\//' Ecoute/MANIFEST` ) | ||||
| 	date >> tarball | ||||
| 
 | ||||
| #---------------------------------------------------------
 | ||||
							
								
								
									
										21
									
								
								Ecoute/README.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								Ecoute/README.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| 
 | ||||
|  4 Feb 2005 : this is a new project. I want a console player for ogg/wav | ||||
| 	audiofiles, and may be ogg & speex. | ||||
| 	who suit my needs: standalone, lowcost, easytouse. | ||||
| 
 | ||||
|  You need libsndfile and libao installed. | ||||
| 
 | ||||
|  I DON'T know the technic for playing .ogg files :( | ||||
| 
 | ||||
| --------------------------------------------------------------------------- | ||||
| TODO: | ||||
| 	- build the ogg player *now* | ||||
| 	- rename some files, because the 'info displayer' go in the | ||||
| 	  same file as the player. | ||||
| 	- write a better english. | ||||
| 	- build a function for detecting sound file with a bad .EXT | ||||
| 
 | ||||
| --------------------------------------------------------------------------- | ||||
| 
 | ||||
| 
 | ||||
| 						- Thierry 'tTh' Boudet - | ||||
							
								
								
									
										88
									
								
								Ecoute/dump.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								Ecoute/dump.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,88 @@ | ||||
| /*
 | ||||
|  *	dump.c | ||||
|  *	======	debug module for 'Ecoute' - 2005.03.06 | ||||
|  * | ||||
|  *  Warning: gruik coding inside. | ||||
|  */ | ||||
| 
 | ||||
| #include    <unistd.h> | ||||
| #include    <fcntl.h> | ||||
| #include    <string.h> | ||||
| #include    <ctype.h> | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| #define T_BUFF_HEX	(16*16) | ||||
| 
 | ||||
| int hexadump(char *fname, WINDOW *w) | ||||
| { | ||||
| int		fd; | ||||
| unsigned char	buffer[T_BUFF_HEX]; | ||||
| int		lig, col, idx; | ||||
| char		chaine[10], lettre; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "hexadump of %s\n", fname); | ||||
| #endif | ||||
| 
 | ||||
| if ( (fd=open(fname, O_RDONLY)) < 0 ) | ||||
| 	{ | ||||
| 	mvwaddstr(w, 2, 2, "err open");		wrefresh(w); | ||||
| 	getch(); | ||||
| 	return -1; | ||||
| 	} | ||||
| 
 | ||||
| if ( T_BUFF_HEX != read(fd, buffer, T_BUFF_HEX) ) | ||||
| 	{ | ||||
| 	mvwaddstr(w, 2, 2, "err read");		wrefresh(w); | ||||
| 	getch(); | ||||
| 	} | ||||
| close(fd); | ||||
| 
 | ||||
| for (lig=0; lig<16; lig++) | ||||
| 	{ | ||||
| 	for (col=0; col<16; col++) | ||||
| 		{ | ||||
| 		idx = (lig*16) + col; | ||||
| 		sprintf(chaine, "%02x", buffer[idx]); | ||||
| 		mvwaddstr(w, lig+1, (col*3)+1, chaine); | ||||
| 		if (isprint(buffer[idx])) | ||||
| 			lettre = buffer[idx]; | ||||
| 		else | ||||
| 			lettre = '.'; | ||||
| 		mvwaddch(w, lig+1, col+50, lettre); | ||||
| 		} | ||||
| 	} | ||||
| wrefresh(w); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	public entry point. | ||||
|  */ | ||||
| int dump_this_file(char *fname, int flag) | ||||
| { | ||||
| WINDOW		*popup; | ||||
| int		foo; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">> dump_this_file ( '%s' %d )\n", fname, flag); | ||||
| #endif | ||||
| 
 | ||||
| popup = newwin(18, 68, L_POPUP, C_POPUP); | ||||
| bordure(popup, 1); | ||||
| mvwaddstr(popup, 0, 2, "{{ dump of "); | ||||
| mvwaddstr(popup, 0, 13, fname); | ||||
| mvwaddstr(popup, 0, 13+strlen(fname), " }}"); | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| foo = hexadump(fname, popup); | ||||
| 
 | ||||
| wrefresh(popup); | ||||
| getch(); | ||||
| delwin(popup);	 | ||||
| touchwin(stdscr); refresh(); | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										100
									
								
								Ecoute/ecoute.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								Ecoute/ecoute.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | ||||
| /*
 | ||||
|  *	ecoute.h | ||||
|  *	--------		Fevrier 2005 a Frontignan-Plage | ||||
|  * | ||||
|  */ | ||||
| #include  <ncurses.h> | ||||
| 
 | ||||
| #define		T_BUFFER	8192 | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void	about(void); | ||||
| void	help(void); | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	ecran.c - ncurses related functions and global vars. | ||||
|  */ | ||||
| #define		L_POPUP		5 | ||||
| #define		C_POPUP		9 | ||||
| 
 | ||||
| void	bordure(WINDOW * w, int flag); | ||||
| int	progress_bar(WINDOW *win, long val, long maxval, int type); | ||||
| void	prepare_ecran(void); | ||||
| void	say_goodbye(void); | ||||
| 
 | ||||
| extern int	couleur; | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	interactive.c - choice a file to play | ||||
|  */ | ||||
| #define SORT_NAME_A	1 | ||||
| #define SORT_NAME_B	2 | ||||
| 
 | ||||
| int	fileselector(void); | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	sound file types | ||||
|  */ | ||||
| #define		SON_UNKNOW	0 | ||||
| #define		SON_NOTE	42 | ||||
| #define		SON_WAV		95 | ||||
| #define		SON_OGG		20 | ||||
| #define		SON_SPEEX	21 | ||||
| #define		SON_FLAC	22 | ||||
| #define		SON_AU		128 | ||||
| 
 | ||||
| /*
 | ||||
|  *	players functions | ||||
|  */ | ||||
| int	note_player(char *fname, WINDOW *popup); | ||||
| int	wav_player(char *fname, WINDOW *popup); | ||||
| int	au_player(char *fname, WINDOW *popup); | ||||
| int	ogg_player(char *fname, WINDOW *popup); | ||||
| int	speex_player(char *fname, WINDOW *popup); | ||||
| int	flac_player(char *fname, WINDOW *popup); | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	_magic.c_ 	check if the file is a sound file. | ||||
|  */ | ||||
| int	magic_detect(char *filename, long *pb); | ||||
| void	magic_plop(int type); | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	'fonctions.c' | ||||
|  */ | ||||
| long	taille_fichier(int fd); | ||||
| int	type_du_fichier(char *nom); | ||||
| char	*type2ext(int type); | ||||
| char	*type2descr(int type); | ||||
| 
 | ||||
| /*
 | ||||
|  *	Flags  is a bitfield | ||||
|  */ | ||||
| int	play_this_file(char *nom, int type, int flags); | ||||
| 
 | ||||
| /*
 | ||||
|  *	new, 18 Avril 2005, proto may change. | ||||
|  */ | ||||
| int	info_about_this_file(char *nom, int type); | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	hexadecimal dumper. | ||||
|  */ | ||||
| int	dump_this_file(char *fname, int flag); | ||||
| 
 | ||||
| /*
 | ||||
|  *	libao technical interface | ||||
|  */ | ||||
| int	init_sound_output(char *dev, int k); | ||||
| int	setup_sound_output(int splr, int nbch); | ||||
| int	start_sound_output(int k); | ||||
| int	stop_sound_output(int k); | ||||
| int	infos_sound_output(char *title); | ||||
| 
 | ||||
| void	infos_driver_son(void); | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										49
									
								
								Ecoute/ecoute.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Ecoute/ecoute.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| <html> | ||||
| <head> | ||||
| <title>Ecoute, c'est du Tonton Th</title> | ||||
| </head> | ||||
| 
 | ||||
| <body> | ||||
| 
 | ||||
| <h1 align=center>Ecoute</h1> | ||||
| 
 | ||||
| <p> | ||||
| Le tinyware <tt>ecoute</tt> est un embryon de <i>player</i> de fichiers | ||||
| son, destiné à un usage <i>one-shoot</i>: vous le lancez, il démarre | ||||
| en moins d'une seconde, vous choisissez le fichier à écouter, et | ||||
| voilà, c'est fini... | ||||
| </p> | ||||
| 
 | ||||
| <p> | ||||
| Pour le moment, il sait lire les <tt>.wav</tt>, les <tt>.au</tt> | ||||
| et un format étrange que j'utilise pour mes diverses expériences | ||||
| sonores. Vous êtes prévenus, c'est un bricolage. | ||||
| </p> | ||||
| 
 | ||||
| <h2 align=center><a href="ecoute.tar.gz">download</a></h2> | ||||
| 
 | ||||
| <p align="center"><img src="ecoute-help.gif" alt="capture fenetre aide"></p> | ||||
| 
 | ||||
| 
 | ||||
| <p align="center"><img src="ecoute-dump.gif" alt="capture fenetre dump"></p> | ||||
| 
 | ||||
| <p> | ||||
| La prochaine étape sera la lecture des <tt>.ogg</tt>, suivie de peu | ||||
| par les <tt>.speex</tt>. Quand ces deux formats seront assimilés, | ||||
| je me pencherais volontiers sur des améliorations de l'interface | ||||
| utilisateur, afin d'en faire un truc encore plus <i>one-shoot</i>, | ||||
| tout en conservant l'aspect glamour de l'interface ncurses. | ||||
| </p> | ||||
| 
 | ||||
| <p> | ||||
| C'est fait sur, et pour, du Linux. Il faut avoir les bibliothèques | ||||
| <tt>libsndfile</tt>, <tt>libogg</tt> et <tt>libao</tt> installées. | ||||
| A priori, c'est | ||||
| portable vers d'autres variantes d'Unix. D'ailleurs, je vais | ||||
| essayer de le faire tourner dans OpenBSD un de ces soirs, parce | ||||
| que bon, ya pas de raisons que ça ne marche pas. | ||||
| Enfin, si il y en a, on va bientôt savoir lesquelles... | ||||
| </p> | ||||
| 
 | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										30
									
								
								Ecoute/ecoute.man
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Ecoute/ecoute.man
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| .TH Ecoute 1 "2005 September" "various OS" "Tonton Th" | ||||
| 
 | ||||
| .SH NAME | ||||
| ecoute \- ncurses based note,wav,ogg,au player. | ||||
| 
 | ||||
| .SH SYNOPSYS | ||||
| \fBecoute\fP  | ||||
| 
 | ||||
| .SH OPTIONS | ||||
| No command-line available. | ||||
| 
 | ||||
| .SH INTERACTIVE | ||||
| This player is a real ncurses based interactive software. | ||||
| Full of bugs, a lot of to_be_done functions. You can try | ||||
| the '?' key at main screen. | ||||
| 
 | ||||
| .SH CONFIG FILE | ||||
| All your config files are belong to us.  | ||||
| 
 | ||||
| .SH WHAT IS A .note FILE ? | ||||
| This a raw, monophonic, 16 bits, 24000 smpl/s binary file. | ||||
| You can seek the web for a 'ziktth' software if you need more informations. | ||||
| 
 | ||||
| 
 | ||||
| .SH AUTHOR(S) | ||||
| Thierry (aka tth) Boudet. http://tboudet.free.fr/ | ||||
| 
 | ||||
| .SH DEDICACE | ||||
| This software is dedicated to DEC, who build the pdp11. | ||||
| 
 | ||||
							
								
								
									
										119
									
								
								Ecoute/ecran.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										119
									
								
								Ecoute/ecran.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,119 @@ | ||||
| /*
 | ||||
|  *	ecran.c | ||||
|  *	------- | ||||
|  *  | ||||
|  *  Maybe, one day, we can have colors... | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include  <stdlib.h> | ||||
| #include  <unistd.h> | ||||
| 
 | ||||
| #include  "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	global variables | ||||
|  */ | ||||
| int	couleur = 0; | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void bordure(WINDOW * w, int flag) | ||||
| { | ||||
| if (flag) | ||||
| 	box(w, 0, 0); | ||||
| else | ||||
| 	wborder(w, '|', '|', '-', '-', '+', '+', '+', '+'); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int alerte(char *texte, int flag) | ||||
| { | ||||
| /*
 | ||||
|  * this func is a stub. real implementation for the next release. | ||||
|  */ | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| #define T_MAX_PB 90 | ||||
| int	progress_bar(WINDOW *win, long val, long maxval, int type) | ||||
| { | ||||
| int	foo, largeur; | ||||
| int	larg_win, haut_win; | ||||
| int	curseur; | ||||
| char	chaine[T_MAX_PB+1]; | ||||
| 
 | ||||
| /*
 | ||||
|  *	premier defi, retrouver largeur et hauteur de la fenetre | ||||
|  */ | ||||
| larg_win = getmaxx(win); | ||||
| haut_win = getmaxy(win); | ||||
| 
 | ||||
| largeur = (T_MAX_PB<larg_win ? T_MAX_PB : larg_win) - 6; | ||||
| 
 | ||||
| #if DEBUG_LEVEL > 1 | ||||
| sprintf(chaine, "> x %-4d y %-4d l %-4d <", larg_win, haut_win, largeur); | ||||
| mvwaddstr(win, 1, 1, chaine); | ||||
| wrefresh(win); | ||||
| #endif | ||||
| 
 | ||||
| curseur = (val*largeur) / maxval; | ||||
| 
 | ||||
| #if DEBUG_LEVEL > 1 | ||||
| fprintf(stderr, "maxval %ld  val %ld  largeur %d  curseur %d\n", | ||||
| 			maxval, val, largeur, curseur); | ||||
| #endif | ||||
| 
 | ||||
| chaine[0] = '[', chaine[largeur] = ']', chaine[largeur+1] = '\0'; | ||||
| for (foo=1; foo<largeur; foo++) | ||||
| 	{ | ||||
| 	if (foo<curseur) | ||||
| 		chaine[foo] = 'o'; | ||||
| 	else | ||||
| 		chaine[foo] = '-'; | ||||
| 	} | ||||
| mvwaddstr(win, haut_win-3, 2, chaine); | ||||
| wrefresh(win); | ||||
| 
 | ||||
| foo = 42; | ||||
| return foo; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void termine_ecran(void) | ||||
| { | ||||
| endwin();	exit(0); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void prepare_ecran(void) | ||||
| { | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( )\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| initscr(); | ||||
| 
 | ||||
| if (has_colors()) | ||||
| 	{ | ||||
| 	use_default_colors(); | ||||
| 	couleur = 1; | ||||
| 	} | ||||
| 
 | ||||
| nonl();		cbreak();	noecho(); | ||||
| 
 | ||||
| keypad(stdscr, TRUE);		/* acces aux touches 'curseur' */ | ||||
| 
 | ||||
| bordure(stdscr, 1); | ||||
| standout(); | ||||
| mvaddstr(0, 5, "{ Ecoute v " VERSION " - by tTh }"); | ||||
| mvaddstr(LINES-1, 5, "{ hit '?' for help, 'Q' for quit }"); | ||||
| standend(); | ||||
| refresh(); | ||||
| 
 | ||||
| atexit(termine_ecran); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void	say_goodbye(void) | ||||
| { | ||||
| bordure(stdscr, 0); | ||||
| wrefresh(stdscr); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										223
									
								
								Ecoute/fonctions.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										223
									
								
								Ecoute/fonctions.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,223 @@ | ||||
| /*
 | ||||
|  *	fonctions.c		Ecoute: a sound player. | ||||
|  *	-----------		23 Fev 2005 - dans le froid de Frontignan | ||||
|  */ | ||||
| 
 | ||||
| #include    <stdio.h> | ||||
| #include    <string.h> | ||||
| #include    <sys/types.h> | ||||
| #include    <sys/stat.h> | ||||
| 
 | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| long	taille_fichier(int fd) | ||||
| { | ||||
| struct stat	st; | ||||
| int		foo; | ||||
| foo = fstat(fd, &st); | ||||
| if (foo) { | ||||
| 	perror("fonctions.c:18 fstat"); | ||||
| 	return -1; | ||||
| 	} | ||||
| return st.st_size; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| struct un_type_de_fichier { | ||||
| 	char	*extension; | ||||
| 	int	numtype; | ||||
| 	char	*descr; | ||||
| 	} types_de_fichiers[] = | ||||
| { | ||||
|  {	".note",	SON_NOTE,	"tTh .note files"		}, | ||||
|  {	".wav",		SON_WAV,	"Microsoft Wave"		}, | ||||
|  {	".ogg",		SON_OGG,	"Xiph Ogg/Vorbis"		}, | ||||
|  {	".speex",	SON_SPEEX,	"Xiph Compressed speach"	}, | ||||
|  {	".au",		SON_AU,		"Sun/NeXT audio data"		}, | ||||
|  {	".flac",	SON_FLAC,	"Free Lossless Audio Codec"	}, | ||||
| }; | ||||
| #define NBR_TYPES 	\ | ||||
| 	(sizeof(types_de_fichiers)/sizeof(struct un_type_de_fichier)) | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	this function is based on the .extension of the filename. | ||||
|  *	this is a very crude system, because we run on Unix, where | ||||
|  *	file extensions are not a hard law. | ||||
|  * | ||||
|  *	see also 'magic.c' for a more advanced function... | ||||
|  */ | ||||
| int	type_du_fichier(char *nom) | ||||
| { | ||||
| int		foo, len_nom, len_ext; | ||||
| 
 | ||||
| #if DEBUG_LEVEL > 1 | ||||
| fprintf(stderr, "type_du_fichier(%s)\n", nom); | ||||
| #endif | ||||
| len_nom = strlen(nom); | ||||
| for (foo=0; foo<NBR_TYPES; foo++) | ||||
| 	{ | ||||
| 	len_ext = strlen(types_de_fichiers[foo].extension); | ||||
| 	if ( (len_nom > len_ext) && | ||||
| 	     !strcmp(nom+(len_nom-len_ext), types_de_fichiers[foo].extension) ) | ||||
| 		{ | ||||
| #if DEBUG_LEVEL > 1 | ||||
| 		fprintf(stderr, "   found %s\n", types_de_fichiers[foo].descr); | ||||
| #endif | ||||
| 		return(types_de_fichiers[foo].numtype); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| #if DEBUG_LEVEL > 1 | ||||
| fprintf(stderr, "    fail...\n"); | ||||
| #endif | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| char	*type2ext(int type) | ||||
| { | ||||
| int	foo; | ||||
| 
 | ||||
| if (type == SON_UNKNOW) | ||||
| 	return "unknow"; | ||||
| 
 | ||||
| for (foo=0; foo<NBR_TYPES; foo++) | ||||
| 	{ | ||||
| 	if (type==types_de_fichiers[foo].numtype) | ||||
| 		return (types_de_fichiers[foo].extension)+1; | ||||
| 	} | ||||
| return "???"; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| char	*type2descr(int type) | ||||
| { | ||||
| int	foo; | ||||
| 
 | ||||
| if (type == SON_UNKNOW) | ||||
| 	return "unknow"; | ||||
| 
 | ||||
| for (foo=0; foo<NBR_TYPES; foo++) | ||||
| 	{ | ||||
| 	if (type==types_de_fichiers[foo].numtype) | ||||
| 		return (types_de_fichiers[foo].descr); | ||||
| 	} | ||||
| return "lp0 on fire"; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	play_this_file(char *nom, int type, int flags) | ||||
| { | ||||
| int		foo; | ||||
| WINDOW		*popup; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( '%s' %d 0x%x )\n", __func__, nom, type, flags); | ||||
| #endif | ||||
| 
 | ||||
| /*
 | ||||
|  *	ncurses initial stuff | ||||
|  */ | ||||
| popup = newwin(12, 60, L_POPUP, C_POPUP); | ||||
| bordure(popup, 1); | ||||
| /* wstandout(popup); */ | ||||
| mvwaddstr(popup, 0, 2, "{ playing "); | ||||
| mvwaddstr(popup, 0, 12, nom); | ||||
| mvwaddstr(popup, 0, 12+strlen(nom), " }"); | ||||
| /*wstandend(popup); */ | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| foo = start_sound_output(0); | ||||
| 
 | ||||
| switch (type) | ||||
| 	{ | ||||
| 	case SON_NOTE: | ||||
| 		foo = note_player(nom, popup); | ||||
| 		break;	 | ||||
| 	case SON_WAV: | ||||
| 		foo = wav_player(nom, popup); | ||||
| 		break; | ||||
| 	case SON_OGG: | ||||
| 		foo = ogg_player(nom, popup); | ||||
| 		break; | ||||
| 	case SON_AU: | ||||
| 		foo = au_player(nom, popup); | ||||
| 		break; | ||||
| 	case SON_SPEEX: | ||||
| 		foo = speex_player(nom, popup); | ||||
| 		break; | ||||
| 	case SON_FLAC: | ||||
| 		foo = flac_player(nom, popup); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| foo = stop_sound_output(0); | ||||
| 
 | ||||
| /*
 | ||||
|  *	screen washing. | ||||
|  */ | ||||
| delwin(popup); | ||||
| touchwin(stdscr);	refresh(); | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "    end of %s\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| return foo; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	info_about_this_file(char *nom, int type) | ||||
| { | ||||
| int		foo; | ||||
| WINDOW		*popup; | ||||
| char		chaine[100]; | ||||
| struct stat	st; | ||||
| long		magicbits; | ||||
| 
 | ||||
| /*
 | ||||
|  *	ncurses initial stuff | ||||
|  */ | ||||
| popup = newwin(12, 64, L_POPUP, C_POPUP); | ||||
| bordure(popup, 1); | ||||
| wstandout(popup); | ||||
| mvwaddstr(popup, 0, 2, "{ infos about "); | ||||
| mvwaddstr(popup, 0, 16, nom); | ||||
| mvwaddstr(popup, 0, 16+strlen(nom), " }"); | ||||
| wstandend(popup); | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| /*
 | ||||
|  *	filesystem infos | ||||
|  */ | ||||
| foo = stat(nom, &st); | ||||
| if (foo != 0) | ||||
| 	{ | ||||
| 	mvwaddstr(popup, 3, 2, "hu ho, stat failed ?"); | ||||
| 	} | ||||
| else | ||||
| 	{ | ||||
| 	sprintf(chaine, "owned by:  user id %d, group id %d",  | ||||
| 			st.st_uid, st.st_gid); | ||||
| 	mvwaddstr(popup, 3, 2, chaine); | ||||
| 	sprintf(chaine, "size:      %ld bytes ", st.st_size); | ||||
| 	mvwaddstr(popup, 4, 2, chaine); | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	internals infos | ||||
|  */ | ||||
| foo = magic_detect(nom, &magicbits); | ||||
| sprintf(chaine, "magic_detect: %4d", foo); | ||||
| mvwaddstr(popup, 8, 2, chaine); | ||||
| mvwaddstr(popup, 8, 25, type2descr(foo)); | ||||
| 
 | ||||
| wrefresh(popup); | ||||
| getch(); | ||||
| 
 | ||||
| /*
 | ||||
|  *	screen cleanup. | ||||
|  */ | ||||
| delwin(popup); | ||||
| touchwin(stdscr);	refresh(); | ||||
| 
 | ||||
| return foo; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										141
									
								
								Ecoute/ifao.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								Ecoute/ifao.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,141 @@ | ||||
| /*
 | ||||
|  *		ifao.c		(libao interface) | ||||
|  *		------ | ||||
|  */ | ||||
| 
 | ||||
| #include    <stdlib.h> | ||||
| #include    <unistd.h> | ||||
| #include    <string.h> | ||||
| #include    <ao/ao.h> | ||||
| 
 | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	privates variables of this module. MUST be static ! | ||||
|  */ | ||||
| 
 | ||||
| #define TBUF	100 | ||||
| 
 | ||||
| static int			isactive; | ||||
| static char			devname[TBUF+1]; | ||||
| static ao_sample_format		AOSF; | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  */ | ||||
| int setup_sound_output(int splr, int nbch) | ||||
| { | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %d %d )\n", __func__, splr, nbch); | ||||
| #endif | ||||
| 
 | ||||
| if (splr)	AOSF.rate        = splr; | ||||
| if (nbch)	AOSF.channels    = nbch; | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	initialisation of this module who MUST be called | ||||
|  *	before any use of this module ! | ||||
|  */ | ||||
| int   init_sound_output(char *device, int k) | ||||
| { | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, device, k); | ||||
| #endif | ||||
| 
 | ||||
| /* some default values */ | ||||
| AOSF.rate 		= 44100; | ||||
| AOSF.channels		= 2; | ||||
| AOSF.bits		= 16; | ||||
| AOSF.byte_format	= AO_FMT_LITTLE;		/* XXX ??? */ | ||||
| 
 | ||||
| /*  XXX    see the libao documentation for exact syntax */ | ||||
| if (TBUF < strlen(device)) { | ||||
| 	fprintf(stderr, "buffer overflow in %s\n", __func__); | ||||
| 	exit(1); | ||||
| 	} | ||||
| strcpy(devname, device); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int   start_sound_output(int k) | ||||
| { | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %d )\n", __func__, k); | ||||
| #endif | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int   stop_sound_output(int k) | ||||
| { | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( %d )\n", __func__, k); | ||||
| #endif | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int   infos_sound_output(char *title) | ||||
| { | ||||
| 
 | ||||
| if (NULL==title) { | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| fprintf(stderr, "   +------ snd out infos (%s)\n", title); | ||||
| fprintf(stderr, "   |  device name      '%s'\n", devname); | ||||
| fprintf(stderr, "   |  sample rate      %d\n", AOSF.rate); | ||||
| fprintf(stderr, "   |  channels         %d\n", AOSF.channels ); | ||||
| fprintf(stderr, "   |  bits/smpl        %d\n", AOSF.bits ); | ||||
| fprintf(stderr, "   |  is active ?      %s\n", isactive ? "yes" : "no"); | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void  infos_driver_son(void) | ||||
| { | ||||
| int		foo; | ||||
| WINDOW		*popup; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( )\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| #define VID_INV 0 | ||||
| 
 | ||||
| popup = newwin(12, 60, L_POPUP, C_POPUP); | ||||
| bordure(popup, 1); | ||||
| #if VID_INV | ||||
| wstandout(popup); | ||||
| #endif | ||||
| mvwaddstr(popup, 0, 2, "{{ sound driver }}"); | ||||
| #if VID_INV | ||||
| wstandend(popup); | ||||
| #endif | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| foo = start_sound_output(0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "  %s: start_sound_output -> %d\n", __func__, foo); | ||||
| 	} | ||||
| foo = stop_sound_output(0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "  %s: stop_sound_output -> %d\n", __func__, foo); | ||||
| 	} | ||||
| 
 | ||||
| mvwaddstr(popup,  4, 9, "* function not implemented *"); | ||||
| mvwaddstr(popup, 11, 2, "{{ hit any key to reboot }}"); | ||||
| wrefresh(popup); | ||||
| getch(); | ||||
| delwin(popup); | ||||
| touchwin(stdscr);	refresh(); | ||||
| 
 | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| 
 | ||||
							
								
								
									
										301
									
								
								Ecoute/interactive.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										301
									
								
								Ecoute/interactive.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,301 @@ | ||||
| /*
 | ||||
|  *	fileselector.c | ||||
|  *	--------------		18 Fevrier 2005. | ||||
|  * | ||||
|  *	some code borrowed from 'Visual Hexdiff' :-) | ||||
|  */ | ||||
| 
 | ||||
| #include    <stdio.h> | ||||
| #include    <stdlib.h> | ||||
| #include    <string.h> | ||||
| #include    <sys/time.h> | ||||
| #include    <sys/stat.h> | ||||
| #include    <dirent.h> | ||||
| #include    <errno.h> | ||||
| 
 | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| extern char *strdup(const char *);		/* WTF? */ | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| typedef struct { | ||||
| 	long		smplrate; | ||||
| 	short		channels; | ||||
| 	short		type; | ||||
| 	} FICH_SON; | ||||
| 
 | ||||
| typedef struct  { | ||||
| 	long		taille; | ||||
| 	char		*nom; | ||||
| 	int		idx; | ||||
| 	time_t		epochtime; | ||||
| 	FICH_SON	son; | ||||
| 	} FICH; | ||||
| 	 | ||||
| static FICH	*liste; | ||||
| static int	taille;		/* taille de la liste */ | ||||
| static int	nombre;		/* nbre d'entrées dans la liste */ | ||||
| 
 | ||||
| #define		TCHONK	42 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	return 1 if we can safely read the file | ||||
|  */ | ||||
| int	teste_fichier(char *nom, struct stat *stb, int flag) | ||||
| { | ||||
| int		foo; | ||||
| foo = stat(nom, stb); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "in %s stat -> %d\n", __func__, errno); | ||||
| 	} | ||||
| if (S_ISDIR(stb->st_mode))	return 0; | ||||
| /* XXX
 | ||||
|  *	check if the file is readable | ||||
|  */ | ||||
| return 1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*
 | ||||
|  *	dedicated comparaison functions for sorting in the file selector. | ||||
|  * | ||||
|  */ | ||||
| static int cmp_name_asc(const void *a, const void *b) | ||||
| { return strcmp( ((FICH *)a)->nom, ((FICH *)b)->nom); } | ||||
| static int cmp_name_dsc(const void *a, const void *b) | ||||
| { return strcmp( ((FICH *)b)->nom, ((FICH *)a)->nom); } | ||||
| 
 | ||||
| static int cmp_idx_asc(const void *a, const void *b) | ||||
| { return ((FICH *)a)->idx - ((FICH *)b)->idx; } | ||||
| static int cmp_idx_dsc(const void *a, const void *b) | ||||
| { return ((FICH *)b)->idx - ((FICH *)a)->idx; } | ||||
| 
 | ||||
| static int cmp_size_asc(const void *a, const void *b) | ||||
| { return ((FICH *)a)->taille - ((FICH *)b)->taille; } | ||||
| static int cmp_size_dsc(const void *a, const void *b) | ||||
| { return ((FICH *)b)->taille - ((FICH *)a)->taille; } | ||||
| 
 | ||||
| /* and sorting by date ? */ | ||||
| 
 | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	trier_la_liste(int mode) | ||||
| { | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "tri de la liste, mode=%d\n", mode); | ||||
| #endif | ||||
| switch(mode) | ||||
| 	{ | ||||
| 	case 1: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_name_asc); | ||||
| 		break; | ||||
| 	case 2: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_name_dsc); | ||||
| 		break; | ||||
| 	case 3: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_size_asc); | ||||
| 		break; | ||||
| 	case 4: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_size_dsc); | ||||
| 		break; | ||||
| 	case 10: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_idx_asc); | ||||
| 		break; | ||||
| 	case 11: | ||||
| 		qsort(liste, nombre, sizeof(FICH), cmp_idx_dsc); | ||||
| 		break; | ||||
| 	} | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	faire_la_liste(void) | ||||
| { | ||||
| DIR		*dir; | ||||
| struct dirent	*de; | ||||
| struct stat	statbuf; | ||||
| int		foo, type; | ||||
| int		devine; | ||||
| long		magicbits; | ||||
| 
 | ||||
| if ( NULL == (liste = malloc(TCHONK*sizeof(FICH))) ) | ||||
| 	{ | ||||
| 	fprintf(stderr, "\nno memory in file-listing\n"); | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| dir = opendir("."); | ||||
| if (dir == NULL) { abort(); }		/* XXX hard failure */ | ||||
| 
 | ||||
| nombre = 0; | ||||
| while ( (de=readdir(dir)) != NULL) | ||||
| 	{ | ||||
| #if DEBUG_LEVEL | ||||
| #endif | ||||
| 	if ( ! teste_fichier(de->d_name, &statbuf, 0) ) | ||||
| 		{ | ||||
| 		continue; | ||||
| 		} | ||||
| 	type = type_du_fichier(de->d_name); | ||||
| 	if (type < 0) | ||||
| 		{ | ||||
| 		continue; | ||||
| 		} | ||||
| 
 | ||||
| 	/* use the magic system (new 13 mai, may be bugged) */ | ||||
| 	devine = magic_detect(de->d_name, &magicbits); | ||||
| 	fprintf(stderr, "%s %s %d\n", __func__, de->d_name, devine); | ||||
| 
 | ||||
| 	/* strdup is a 'non-portable' function ? */ | ||||
| 	liste[nombre].nom = strdup(de->d_name); | ||||
| 	liste[nombre].taille = statbuf.st_size; | ||||
| 	liste[nombre].idx = nombre; | ||||
| 	liste[nombre].son.type = type; | ||||
| 	liste[nombre].epochtime = 15000; | ||||
| #if DEBUG_LEVEL > 1 | ||||
| 	fprintf(stderr, "%4d: %-20s %8ld  %4d\n", | ||||
| 			nombre, liste[nombre].nom, liste[nombre].taille, type); | ||||
| #endif | ||||
| 	nombre++; | ||||
| 	/* if needed, increase the size of the list */ | ||||
| 	if (nombre >= taille) | ||||
| 		{ | ||||
| 		liste = realloc(liste, sizeof(FICH)*(taille+TCHONK)); | ||||
| 		taille += TCHONK; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| foo = closedir(dir); | ||||
| 
 | ||||
| return nombre;			/* ??? */ | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int print_entry(WINDOW *w, int number, int line) | ||||
| { | ||||
| int	ln; | ||||
| 
 | ||||
| ln = strlen(liste[number].nom); | ||||
| 
 | ||||
| mvwprintw(w, line, 2, "%3d    %-40s  %9d  ",  | ||||
| 				liste[number].idx, | ||||
| 				liste[number].nom, | ||||
| 				liste[number].taille); | ||||
| return 0; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int fileselector(void) | ||||
| { | ||||
| int		foo; | ||||
| WINDOW		*wfs; | ||||
| int		first, curseur, idx, affh; | ||||
| int		key, flag_exit; | ||||
| char		chaine[100]; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( )\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| foo = faire_la_liste(); | ||||
| 
 | ||||
| affh = LINES-7; | ||||
| /*
 | ||||
|  *	create a subwindow for list of files | ||||
|  */ | ||||
| wfs = derwin(stdscr, affh, COLS-2, 2, 1); | ||||
| #if DEBUG_LEVEL > 1 | ||||
| bordure(wfs, 0); | ||||
| #endif | ||||
| wrefresh(wfs); | ||||
| 
 | ||||
| first = curseur = 0; | ||||
| flag_exit = 0; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "    %s enter interactive\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| do | ||||
| 	{ | ||||
| #if DEBUG_LEVEL > 1 | ||||
| 	sprintf(chaine, "nombre:%3d first:%3d  curseur:%3d", | ||||
| 				nombre, first, curseur); | ||||
| 	mvwaddstr(wfs, 0, 50, chaine); | ||||
| #endif | ||||
| 
 | ||||
| 	for (foo=0; foo<affh; foo++) | ||||
| 		{ | ||||
| 		idx = foo+first; | ||||
| 		if (idx >= nombre)	break; | ||||
| 
 | ||||
| 		if (curseur==foo)	wstandout(wfs); | ||||
| 		/*
 | ||||
| 		 * display the entry, need more work :( | ||||
| 		 */ | ||||
| 		print_entry(wfs, idx, foo); | ||||
| 		if (curseur==foo)	wstandend(wfs); | ||||
| 		} | ||||
| 	wrefresh(wfs); | ||||
| 
 | ||||
| 	key = getch(); | ||||
| 	/*
 | ||||
| 	 *	ici il faudrait effacer le curseur ? | ||||
| 	 */ | ||||
| 	switch (key) | ||||
| 		{ | ||||
| 		case KEY_UP: | ||||
| 			if (curseur)			curseur--; | ||||
| 			else if (first>0)		first--; | ||||
| 			break; | ||||
| 
 | ||||
| 		case KEY_DOWN: | ||||
| 			if ((curseur+first) >= (nombre-1))	break; | ||||
| 			if (curseur < affh-1)		curseur++; | ||||
| 			else if (first<(nombre-affh))	first++; | ||||
| 			break; | ||||
| 
 | ||||
| 		case KEY_HOME: | ||||
| 			curseur = first = 0; | ||||
| 			break; | ||||
| 
 | ||||
| 		/* the show must go on */ | ||||
| 		case '\r': case 'p': | ||||
| 			idx = curseur+first;	/* ??? */ | ||||
| 			play_this_file(liste[idx].nom, liste[idx].son.type, 0); | ||||
| 			break; | ||||
| 
 | ||||
| 		case 'D':	case 'd': | ||||
| 			idx = curseur+first;	/* ??? FIXME */ | ||||
| 			dump_this_file(liste[idx].nom, 0); | ||||
| 			break; | ||||
| 
 | ||||
| 		case 'I':	case 'i': | ||||
| 			idx = curseur+first;	/* ??? FIXME */ | ||||
| 			info_about_this_file(liste[idx].nom, | ||||
| 						liste[idx].son.type); | ||||
| 			break; | ||||
| 
 | ||||
| 		case 'A':	case 'a': about(); break; | ||||
| 		case 'H':	case 'h':	case '?': help(); break; | ||||
| 
 | ||||
| 		case 'n':	trier_la_liste(1);	break; | ||||
| 		case 'N':	trier_la_liste(2);	break; | ||||
| 		case 's':	trier_la_liste(3);	break; | ||||
| 		case 'S':	trier_la_liste(4);	break; | ||||
| 		case 'u':	trier_la_liste(10);	break; | ||||
| 		case 'U':	trier_la_liste(11);	break; | ||||
| 
 | ||||
| 		case '$':	infos_driver_son();	break; | ||||
| 
 | ||||
| 		case 'Q':	case 'q': | ||||
| 			flag_exit = 1; | ||||
| 			break; | ||||
| 		} | ||||
| 
 | ||||
| 	} while ( ! flag_exit ); | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "    %s exit interactive\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										72
									
								
								Ecoute/magic.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								Ecoute/magic.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,72 @@ | ||||
| /*
 | ||||
|  *	magic.c | ||||
|  *	=======		26 Avril 2005 | ||||
|  * | ||||
|  *	reconnaissance heuristique des fichiers sons. | ||||
|  *	Gruik coding inside. | ||||
|  */ | ||||
| 
 | ||||
| #include    <stdio.h> | ||||
| #include    <unistd.h> | ||||
| #include    <fcntl.h> | ||||
| #include    <string.h> | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| #define   T_BUFF_MAGIC	222 | ||||
| 
 | ||||
| int	magic_detect(char *fname, long *pbits) | ||||
| { | ||||
| int		fd; | ||||
| char		buffer[T_BUFF_MAGIC]; | ||||
| 
 | ||||
| if ( (fd=open(fname, O_RDONLY)) < 0 ) | ||||
| 	{ | ||||
| 	perror(fname); | ||||
| 	return -1; | ||||
| 	} | ||||
| if ( T_BUFF_MAGIC != read(fd, buffer, T_BUFF_MAGIC) ) | ||||
| 	{ | ||||
| 	close(fd); | ||||
| 	return -2; | ||||
| 	} | ||||
| close(fd);		 | ||||
| 
 | ||||
| /* now, we have the first bytes of the file in the buffer, so we can
 | ||||
|    try the divination process... */ | ||||
| 
 | ||||
| *pbits = 0L; | ||||
| 
 | ||||
| if (0 == strncmp(buffer, "RIFF", 4)) | ||||
| 	{ | ||||
| 	if (0 == strncmp(buffer+8, "WAVE", 4)) | ||||
| 		{ | ||||
| 		return SON_WAV; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| if (0 == strncmp(buffer, ".snd", 4)) | ||||
| 	{ | ||||
| 	return SON_AU; | ||||
| 	} | ||||
| 
 | ||||
| if (0 == strncmp(buffer, "OggS", 4)) | ||||
| 	{ | ||||
| 	if (0 == strncmp(buffer+28, "\x01vorbis", 7)) | ||||
| 		{ | ||||
| 		return SON_OGG; | ||||
| 		} | ||||
| 	if (0 == strncmp(buffer+28, "Speex   ", 7)) | ||||
| 		{ | ||||
| 		return SON_SPEEX; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /* please add FLAC magic here XXX */ | ||||
| 
 | ||||
| 
 | ||||
| /* really don't know, baylout */ | ||||
| return SON_UNKNOW; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										151
									
								
								Ecoute/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								Ecoute/main.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,151 @@ | ||||
| /*
 | ||||
|  *		------ | ||||
|  *		Ecoute | ||||
|  *		------  an ogg/note/wav player from tth | ||||
|  * | ||||
|  * 15 juillet 2007: ogg palying don(t work, sorry... | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include    <stdlib.h> | ||||
| #include    <unistd.h> | ||||
| #include    <string.h> | ||||
| #include    <getopt.h> | ||||
| 
 | ||||
| #include    "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| static char *about_texte[] =  | ||||
| 	{ | ||||
| 	"{{ About... }}", | ||||
| 	"Ecoute, a sound player - version " VERSION, | ||||
| 	"Another ugly software made by tontonTh", | ||||
| 	"", | ||||
| 	"Send bugs reports: tontonth(O)free(o)fr", | ||||
| 	"", | ||||
| 	"Binary build: " __DATE__ "  /  " __TIME__, | ||||
| 	NULL | ||||
| 	}; | ||||
| static char *help_texte[] =  | ||||
| 	{ | ||||
| 	"{{ Help me }}", | ||||
| 	"<enter>     Play the selected file", | ||||
| 	"A           About this software...", | ||||
| 	"D           Dump begin of file in hexadecimal", | ||||
| 	"R           Play a randomly selected file", | ||||
| 	"nN          Sort by name", | ||||
| 	"sS          Sort by file size", | ||||
| 	"tT          Sort by file time", | ||||
| 	"uU          Sort by order (unsort)", | ||||
| 	"I           Infos about this file", | ||||
| 	"$           What is the sound driver ?", | ||||
| 	"", | ||||
| 	"Q           Quit", | ||||
| 	NULL | ||||
| 	}; | ||||
| void popup_texte(char *lignes[]) | ||||
| { | ||||
| WINDOW * popup; | ||||
| int	nblignes; | ||||
| int	foo, largmax; | ||||
| char	**ptr; | ||||
| 
 | ||||
| nblignes = largmax = 0; | ||||
| ptr = lignes+1; | ||||
| while ( *ptr != NULL ) | ||||
| 	{ | ||||
| #if DEBUG_LEVEL > 1 | ||||
| 	fprintf(stderr, "%p  %s\n", ptr, *ptr); | ||||
| #endif | ||||
| 	foo = strlen(*ptr); | ||||
| 	if (largmax < foo)	largmax = foo; | ||||
| 	nblignes++; | ||||
| 	ptr++; | ||||
| 	} | ||||
| 
 | ||||
| popup = newwin((nblignes)+5, largmax+6, L_POPUP, C_POPUP); | ||||
| bordure(popup, 1); | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| for (foo=1; foo<=nblignes; foo++) | ||||
| 	{ | ||||
| 	mvwaddstr(popup, (foo)+1, 3, lignes[foo]); | ||||
| #if DEBUG_LEVEL > 1 | ||||
| 	fprintf(stderr, "%4d %s\n", foo, lignes[foo]); | ||||
| #endif | ||||
| 	} | ||||
| mvwaddstr(popup, 0, 5, *lignes);		/* window title */ | ||||
| wmove(popup, 0, 0); | ||||
| wrefresh(popup); | ||||
| getch(); | ||||
| delwin(popup);	 | ||||
| 			/* pourquoi, quand je fait le 'delwin', ncurses
 | ||||
| 			   ne rafraichit pas la zone qui était masquée ? */ | ||||
| touchwin(stdscr); refresh(); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void about(void) | ||||
| { | ||||
| #if DEBUG_LEVEL > 1 | ||||
| fprintf(stderr, "------------ about\n"); | ||||
| #endif | ||||
| popup_texte(about_texte); | ||||
| } | ||||
| void help(void) | ||||
| { | ||||
| #if DEBUG_LEVEL > 1 | ||||
| fprintf(stderr, "------------ help\n"); | ||||
| #endif | ||||
| popup_texte(help_texte); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| void help_cli(char *command) | ||||
| { | ||||
| printf("Usage: %s <options>\n", command); | ||||
| puts("Options:"); | ||||
| puts("\t-d\taudio device"); | ||||
| puts("\t-h\tthis help"); | ||||
| puts("\t-x\tenable crash"); | ||||
| 
 | ||||
| exit(0); | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| /*									*/ | ||||
| int main(int argc, char * argv[]) | ||||
| { | ||||
| int		opt = 0; | ||||
| int		foo; | ||||
| char		*audiodevice = "none"; | ||||
| 
 | ||||
| while ((opt = getopt(argc, argv, "d:hx")) != -1) { | ||||
| 	switch (opt) { | ||||
| 		case 'd': | ||||
| 			audiodevice = optarg; | ||||
| 			break; | ||||
| 		case 'h': | ||||
| 			help_cli(argv[0]);		break; | ||||
| 		default: | ||||
| 			fprintf(stderr, "gni %c ?\n", opt); | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| fprintf(stderr, "audio device = %s\n", audiodevice); | ||||
| 
 | ||||
| foo = init_sound_output(audiodevice, 0); | ||||
| if (foo) { | ||||
| 	fprintf(stderr, "init sound output -> %d\n", foo); | ||||
| 	exit(1); | ||||
| 	} | ||||
| 
 | ||||
| infos_sound_output("dans main"); | ||||
| 
 | ||||
| prepare_ecran(); | ||||
| 
 | ||||
| fileselector(); | ||||
| 
 | ||||
| say_goodbye(); | ||||
| 
 | ||||
| return 0; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										138
									
								
								Ecoute/playau.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								Ecoute/playau.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,138 @@ | ||||
| /*
 | ||||
|  *	playau.c | ||||
|  *	--------			2 Mars 2005 | ||||
|  * | ||||
|  *	This code is almost a copy'n'past from "playwav.c", but | ||||
|  *	it was slightly updated. May be I have introduced new bugs, | ||||
|  *	who have to be backported :) | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include   <fcntl.h> | ||||
| #include   <string.h> | ||||
| #include   <sndfile.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| 
 | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	au_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| SNDFILE			* sndf; | ||||
| SF_INFO			sfinfo; | ||||
| ao_sample_format	format; | ||||
| ao_device		* device; | ||||
| int			driver; | ||||
| 
 | ||||
| char			chaine[100]; | ||||
| short			* samples; | ||||
| long			total_lu; | ||||
| int			lu; | ||||
| int			maxsample; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, fname, popup); | ||||
| #endif | ||||
| 
 | ||||
| /*
 | ||||
|  *	get help from 'sndfile' for getting datas | ||||
|  */ | ||||
| memset(&sfinfo, 0, sizeof(sfinfo)); | ||||
| 
 | ||||
| sndf = sf_open(fname, SFM_READ, &sfinfo); | ||||
| if (sndf==NULL) | ||||
| 	{ | ||||
| 	mvwaddstr(popup, 4, 4, "Invalid file ?"); | ||||
| 	wrefresh(popup); | ||||
| 	getch(); | ||||
| 	delwin(popup); | ||||
| 	touchwin(stdscr);	refresh(); | ||||
| 	return -1; | ||||
| 	} | ||||
| 
 | ||||
| sprintf(chaine, "frames         %lu", (unsigned long)sfinfo.frames); | ||||
| mvwaddstr(popup, 2, 5, chaine); | ||||
| sprintf(chaine, "sample rate    %d", sfinfo.samplerate); | ||||
| mvwaddstr(popup, 3, 5, chaine); | ||||
| sprintf(chaine, "channels       %d", sfinfo.channels); | ||||
| mvwaddstr(popup, 4, 5, chaine); | ||||
| sprintf(chaine, "format         %x", sfinfo.format); | ||||
| mvwaddstr(popup, 5, 5, chaine); | ||||
| 
 | ||||
| wrefresh(popup); | ||||
| #if DEBUG_LEVEL | ||||
| getch(); | ||||
| #endif | ||||
| 
 | ||||
| /*
 | ||||
|  *	memory allocation | ||||
|  *	warning, we can get multiples channels. | ||||
|  */ | ||||
| if ( NULL == (samples = malloc(T_BUFFER*sizeof(short))) ) | ||||
| 	{ | ||||
| 	perror("\n no memory in AU player"); | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	configuration of the sound output | ||||
|  */ | ||||
| ao_initialize();	 | ||||
| driver = ao_default_driver_id(); | ||||
| format.bits		= 16;				/* ? */ | ||||
| format.channels		= sfinfo.channels; | ||||
| format.rate		= sfinfo.samplerate; | ||||
| format.byte_format	= AO_FMT_LITTLE;		/* XXX ??? */ | ||||
| device = ao_open_live(driver, &format, NULL); | ||||
| if (device == NULL) | ||||
| 	{ | ||||
| 	fprintf(stderr, "\nEcoute: Error open device\n"); | ||||
| 	/*
 | ||||
| 	 *  comment connaitre la cause de l'erreur ? | ||||
| 	 */ | ||||
| 	abort();   | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	Go! Read the samples, compute some numbers and... | ||||
|  *	...??? | ||||
|  */ | ||||
| total_lu = 0L; | ||||
| maxsample = 0; | ||||
| while ( (lu=sf_read_short(sndf, samples, T_BUFFER)) > 0 ) | ||||
| 	{ | ||||
| 	ao_play(device, (char *)samples, lu*2); | ||||
| 
 | ||||
| 	/* WHY IS THIS CODE COMMENTED-OUT ? 
 | ||||
| 
 | ||||
| 	for (foo=0; foo<lu; foo++) | ||||
| 		{ | ||||
| 		bar = samples[foo]; | ||||
| 		if (bar > maxsample) | ||||
| 			{ | ||||
| 			sprintf(chaine, "%9ld %6d", total_lu, bar); | ||||
| 			mvwaddstr(popup, 7, 1, chaine); | ||||
| 			wrefresh(popup); | ||||
| 			maxsample = bar; | ||||
| 			} | ||||
| 		} | ||||
| 	maxsample = 0; | ||||
| 	*/ | ||||
| 
 | ||||
| 	total_lu += (long)lu; | ||||
| 	progress_bar(popup, total_lu/sfinfo.channels, sfinfo.frames, 0); | ||||
| 	wrefresh(popup); | ||||
| 	} | ||||
| 
 | ||||
| fprintf(stderr, "maxsample = %d\n", maxsample); | ||||
| 
 | ||||
| /*
 | ||||
|  *	some cleanup... | ||||
|  */ | ||||
| free(samples);					/* kill buff */ | ||||
| sf_close(sndf); | ||||
| ao_close(device);	ao_shutdown();	 | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										28
									
								
								Ecoute/playflac.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								Ecoute/playflac.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| /*
 | ||||
|  *	playflac.c | ||||
|  *	----------			20 Janvier 2022 | ||||
|  */ | ||||
| 
 | ||||
| #include   <fcntl.h> | ||||
| #include   <unistd.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| 
 | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	flac_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| int			ret; | ||||
| 
 | ||||
| ret = 43; | ||||
| 
 | ||||
| mvwaddstr(popup, 1, 2, "Flac playing: work in progress..."); | ||||
| wrefresh(popup);	sleep(1); | ||||
| 
 | ||||
| mvwaddstr(popup, 6, 6, "*** COREDUMPING ***"); | ||||
| wrefresh(popup);	getch(); | ||||
| 
 | ||||
| return ret; 		/* XXX */ | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| 
 | ||||
							
								
								
									
										91
									
								
								Ecoute/playnote.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								Ecoute/playnote.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,91 @@ | ||||
| /*
 | ||||
|  *	playnote.c | ||||
|  *	----------			23 Fevrier 2005 | ||||
|  *  | ||||
|  *  this subplayer is a personnal subplayer. Far back in the past, | ||||
|  *  I've made a lot of softwares around sound synteses. The unique | ||||
|  *  file format was 16bits, 2400samples/seconds and Intel endianism. | ||||
|  * | ||||
|  *		Here is the player. | ||||
|  */ | ||||
| 
 | ||||
| #include   <unistd.h> | ||||
| #include   <fcntl.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int note_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| int			driver; | ||||
| ao_sample_format	format; | ||||
| ao_device		*device; | ||||
| int			lu, fd; | ||||
| short			*samples; | ||||
| char			chaine[100]; | ||||
| long			taille, total; | ||||
| 
 | ||||
| /*
 | ||||
|  *	file and memory stuff | ||||
|  */ | ||||
| if ( NULL == (samples = malloc(T_BUFFER*sizeof(short))) ) | ||||
| 	{ | ||||
| 	perror("memory in note_player"); | ||||
| 	abort(); | ||||
| 	} | ||||
| if ( 0 > (fd=open(fname, O_RDONLY)) ) | ||||
| 	{ | ||||
| 	perror(fname); | ||||
| 	abort(); | ||||
| 	} | ||||
| taille = taille_fichier(fd); | ||||
| if (taille < 0) { | ||||
| 	fprintf(stderr, "%s: size < 0        WTF?\n", __func__); | ||||
| 	} | ||||
| sprintf(chaine, "%10ld samples, %5ld seconds", taille/2, taille/(24000*2)); | ||||
| mvwaddstr(popup, 2, 2, chaine); | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| ao_initialize();			/* must be paired with ao_shutdown */ | ||||
| driver = ao_default_driver_id(); | ||||
| 
 | ||||
| format.bits		= 16; | ||||
| format.channels		= 1; | ||||
| format.rate		= 24000; | ||||
| format.byte_format	= AO_FMT_LITTLE;		/* XXX ??? */ | ||||
| device = ao_open_live(driver, &format, NULL); | ||||
| if (device == NULL) | ||||
| 	{ | ||||
| 	fprintf(stderr, "\r\n%s: Error open device\n", __func__); | ||||
| 	/* comment connaitre la cause de l'erreur ? */ | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *		+-------------------------------+ | ||||
|  *		|   let's the show go on...     | | ||||
|  *		+-------------------------------+ | ||||
|  */ | ||||
| total = 0L; | ||||
| while ( (lu=read(fd, samples, T_BUFFER)) > 0 ) | ||||
| 	{ | ||||
| #if DEBUG_LEVEL | ||||
| 	sprintf(chaine, "%9ld Kb    %-7d", total/1024, lu); | ||||
| #else | ||||
| 	sprintf(chaine, "%9ld Kb", total/1024); | ||||
| #endif | ||||
| 	mvwaddstr(popup, 5, 7, chaine); wrefresh(popup);  | ||||
| 	total += lu; | ||||
| 	progress_bar(popup, total, taille, 0); | ||||
| 	ao_play(device, (char *)samples, lu); | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	this is the end, my friends... | ||||
|  */ | ||||
| ao_close(device); | ||||
| ao_shutdown();				/* must be paired with ao_initialise */ | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										52
									
								
								Ecoute/playogg.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Ecoute/playogg.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,52 @@ | ||||
| /*
 | ||||
|  *	playogg.c | ||||
|  *	---------			2 Mars 2005 | ||||
|  * | ||||
|  * | ||||
|  *  2005, Apr 11:	just downloaded some tarball from xiph.org, thinking | ||||
|  *			about some code samples... | ||||
|  */ | ||||
| 
 | ||||
| #include   <fcntl.h> | ||||
| #include   <unistd.h> | ||||
| #include   <ogg/ogg.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| 
 | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	ogg_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| ogg_sync_state		oy; | ||||
| char			*oggbuff; | ||||
| int			ret; | ||||
| 
 | ||||
| mvwaddstr(popup, 1, 2, "Ogg playing: work in progress..."); | ||||
| wrefresh(popup);	sleep(1); | ||||
| 
 | ||||
| mvwaddstr(popup, 6, 6, "*** COREDUMPING ***"); | ||||
| wrefresh(popup);	getch(); | ||||
| 
 | ||||
| return -42; 		/* XXX */ | ||||
| 
 | ||||
| /*
 | ||||
|  *	preparation | ||||
|  */ | ||||
| ret = ogg_sync_init(&oy); | ||||
| mvwprintw(popup, 2, 2, "ogg_sync_init -> %d", ret); | ||||
| 
 | ||||
| oggbuff = ogg_sync_buffer(&oy, T_BUFFER); | ||||
| mvwprintw(popup, 3, 2, "ogg_sync_buffer -> %p", oggbuff); | ||||
| wrefresh(popup); | ||||
| getch(); | ||||
| 
 | ||||
| /*
 | ||||
|  *	termination | ||||
|  */ | ||||
| ogg_sync_clear(&oy); | ||||
| ogg_sync_destroy(&oy); | ||||
| getch(); | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										26
									
								
								Ecoute/playspeex.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Ecoute/playspeex.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| /*
 | ||||
|  *	playspeex.c | ||||
|  *	-----------			12 Avril 2005 | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include   <fcntl.h> | ||||
| #include   <unistd.h> | ||||
| #include   <ogg/ogg.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| 
 | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	speex_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| mvwaddstr(popup, 1, 2, fname); | ||||
| mvwaddstr(popup, 1, 4, "Speex playing: work in progress..."); | ||||
| wrefresh(popup);	sleep(1); | ||||
| 
 | ||||
| mvwaddstr(popup, 6, 6, "*** COREDUMPING ***"); | ||||
| wrefresh(popup);	getch(); | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
							
								
								
									
										132
									
								
								Ecoute/playwav.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										132
									
								
								Ecoute/playwav.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,132 @@ | ||||
| /*
 | ||||
|  *	playwav.c | ||||
|  *	---------			23 Fevrier 2005 | ||||
|  */ | ||||
| 
 | ||||
| #include   <fcntl.h> | ||||
| #include   <string.h> | ||||
| #include   <sndfile.h> | ||||
| #include   <ao/ao.h>		/* for the sound output */ | ||||
| 
 | ||||
| #include   "ecoute.h" | ||||
| 
 | ||||
| /*==------------------------------------------------------------------==*/ | ||||
| int	wav_player(char *fname, WINDOW *popup) | ||||
| { | ||||
| SNDFILE			* sndf; | ||||
| SF_INFO			sfinfo; | ||||
| int			driver; | ||||
| ao_sample_format	format; | ||||
| ao_device		* device; | ||||
| char			chaine[120]; | ||||
| short			* samples; | ||||
| int			lu; | ||||
| long			total_lu; | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, fname, popup); | ||||
| #endif | ||||
| 
 | ||||
| /*
 | ||||
|  *	get help from 'sndfile' for getting datas | ||||
|  */ | ||||
| memset(&sfinfo, 0, sizeof(sfinfo)); | ||||
| 
 | ||||
| sndf = sf_open(fname, SFM_READ, &sfinfo); | ||||
| if (sndf==NULL) | ||||
| 	{ | ||||
| 	mvwaddstr(popup, 4, 4, "Invalid file ?"); | ||||
| 	wrefresh(popup); | ||||
| 	getch(); | ||||
| 	delwin(popup); | ||||
| 	touchwin(stdscr);	refresh(); | ||||
| 	return -1; | ||||
| 	} | ||||
| 
 | ||||
| sprintf(chaine, "frames      %lu", (unsigned long)sfinfo.frames); | ||||
| mvwaddstr(popup, 2, 5, chaine); | ||||
| sprintf(chaine, "smplrate    %d", sfinfo.samplerate); | ||||
| mvwaddstr(popup, 3, 5, chaine); | ||||
| sprintf(chaine, "channels    %d", sfinfo.channels); | ||||
| mvwaddstr(popup, 4, 5, chaine); | ||||
| sprintf(chaine, "format      0x%x", sfinfo.format); | ||||
| mvwaddstr(popup, 5, 5, chaine); | ||||
| sprintf(chaine, "sections    %d", sfinfo.sections); | ||||
| mvwaddstr(popup, 6, 5, chaine); | ||||
| 
 | ||||
| wrefresh(popup); | ||||
| 
 | ||||
| #if DEBUG_LEVEL > 1 | ||||
| getch();					/* XXX */ | ||||
| #endif | ||||
| 
 | ||||
| /*
 | ||||
|  *	memory allocation | ||||
|  *	warning, we can get multiples channels. | ||||
|  */ | ||||
| if ( NULL == (samples = malloc(T_BUFFER*sizeof(short))) ) | ||||
| 	{ | ||||
| 	perror("memory shortage in WAV player"); | ||||
| 	abort(); | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	initialize the "Cabasse Sampan" output device (aka libao) | ||||
|  */ | ||||
| ao_initialize(); | ||||
| driver = ao_default_driver_id(); | ||||
| /* XXX valeurs provisoires XXX */ | ||||
| memset(&format, 0, sizeof(ao_sample_format)); | ||||
| format.bits		= 16; | ||||
| format.channels		= sfinfo.channels; | ||||
| format.rate		= sfinfo.samplerate; | ||||
| format.byte_format	= AO_FMT_LITTLE;		/* XXX ??? */ | ||||
| device = ao_open_live(driver, &format, NULL); | ||||
| if (device == NULL) | ||||
| 	{ | ||||
| 	fprintf(stderr, "\nEcoute: Error open device\n"); | ||||
| 	/*
 | ||||
| 	 *  comment connaitre la cause de l'erreur ? | ||||
| 	 */ | ||||
| 	abort();   | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	********************** | ||||
|  *	*  the playing loop  * | ||||
|  *	********************** | ||||
|  */ | ||||
| total_lu = 0L; | ||||
| while ( (lu=sf_read_short(sndf, samples, T_BUFFER)) > 0 ) | ||||
| 	{ | ||||
| 	ao_play(device, (char *)samples, lu*2); | ||||
| 	total_lu += (long)lu; | ||||
| 	progress_bar(popup, total_lu/sfinfo.channels, sfinfo.frames, 0); | ||||
| 	wrefresh(popup); | ||||
| 
 | ||||
| 	/* HERE WE HAVE TO DETECT A 'STOP LISTEN' FUNCTION. */ | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| /*
 | ||||
|  *	shutdown "La voix du Theatre" | ||||
|  */ | ||||
| ao_close(device);	ao_shutdown();	 | ||||
| 
 | ||||
| /*
 | ||||
|  *	memory release | ||||
|  */ | ||||
| free(samples); | ||||
| 
 | ||||
| /*
 | ||||
|  *	releasing 'sndfile' ressources | ||||
|  */ | ||||
| sf_close(sndf); | ||||
| 
 | ||||
| #if DEBUG_LEVEL | ||||
| fprintf(stderr, "    end of %s\n", __func__); | ||||
| #endif | ||||
| 
 | ||||
| return -1; | ||||
| } | ||||
| /*==------------------------------------------------------------------==*/ | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 tTh
						tTh