"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/wavplay.c" between
xcdroast-1.18.tar.gz and xcdroast-1.19.tar.gz

About: X-CD-Roast is a graphical user interface (GUI) for the command-line cdrtools.

wavplay.c  (xcdroast-1.18):wavplay.c  (xcdroast-1.19)
/* /*
* wavplay.c * wavplay.c
* *
* simple wavfile-player. plays only 44.1khz,16bit,stereo files. * simple wavfile-player. plays only 44.1khz,16bit,stereo files.
* gui-mode to fully control all play-functions via external interface * gui-mode to fully control all play-functions via external interface
* *
* works fine on little and big endian machines. * works fine on little and big endian machines.
* 30.05.99 tn * 30.05.99 tn
* 07.11.18 tn - add ALSA support for linux
* *
* *
* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. * Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
* *
* This file is part of xcdroast. * This file is part of xcdroast.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
skipping to change at line 46 skipping to change at line 47
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#if defined(linux) || defined(__CYGWIN32__) #if defined(linux) || defined(__CYGWIN32__)
# include <getopt.h> # include <getopt.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#if defined(linux) || defined(__FreeBSD__) #if defined(linux)
# include <alsa/asoundlib.h>
#endif
#if defined(__FreeBSD__)
# include <sys/soundcard.h> # include <sys/soundcard.h>
# include <sys/ioctl.h> # include <sys/ioctl.h>
#endif #endif
#if defined(sun) || defined(__OpenBSD__) #if defined(sun) || defined(__OpenBSD__)
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <sys/audioio.h> # include <sys/audioio.h>
#endif #endif
#ifdef aix #ifdef aix
#include <errno.h> #include <errno.h>
#include <sys/audio.h> #include <sys/audio.h>
skipping to change at line 79 skipping to change at line 83
#include <glib.h> #include <glib.h>
#include "xcdroast.h" #include "xcdroast.h"
#if defined(__sgi) #if defined(__sgi)
#include <dmedia/audio.h> #include <dmedia/audio.h>
#endif #endif
static off_t waveBase ; static off_t waveBase ;
static gint abuf_size; static gint abuf_size;
#if defined(linux)
static gint alsa_frame_size;
#endif
static guchar *audiobuf; static guchar *audiobuf;
gint read_line(gint fd, gchar *ptr, gint maxlen); gint read_line(gint fd, gchar *ptr, gint maxlen);
off_t is_std_wav_file(int f, off_t *offset); off_t is_std_wav_file(int f, off_t *offset);
#if defined(linux) || defined(__FreeBSD__) #if defined(linux)
#define DEFAULT_AUDIO_DEVICE "default"
#elif defined(__FreeBSD__)
#define DEFAULT_AUDIO_DEVICE "/dev/dsp" #define DEFAULT_AUDIO_DEVICE "/dev/dsp"
#elif defined (aix) #elif defined (aix)
#define DEFAULT_AUDIO_DEVICE "" #define DEFAULT_AUDIO_DEVICE ""
#elif defined(__sgi) #elif defined(__sgi)
#define DEFAULT_AUDIO_DEVICE "" #define DEFAULT_AUDIO_DEVICE ""
#else #else
#define DEFAULT_AUDIO_DEVICE "/dev/audio" #define DEFAULT_AUDIO_DEVICE "/dev/audio"
#endif #endif
#define DEFAULT_BUFFER_SIZE 22050 #define DEFAULT_BUFFER_SIZE 22050
#if defined(linux) || defined(__FreeBSD__) #if defined(linux)
/*
* open the alsa-device of linux and set cd-quality
*/
snd_pcm_t *open_alsa_audio(gchar *dev) {
snd_pcm_t *playback_handle;
snd_pcm_hw_params_t *hw_params;
snd_pcm_uframes_t buffer_size, periods;
gint err;
if ((err = snd_pcm_open (&playback_handle, dev, SND_PCM_STREAM_PLAYBACK,
0)) < 0) {
g_warning("cannot open audio device %s (%s)\n", dev, snd_
strerror (err));
return(NULL);
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
g_warning("cannot allocate hardware parameter structure (
%s)\n",
snd_strerror (err));
return(NULL);
}
if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
g_warning("cannot initialize hardware parameter structure
(%s)\n",
snd_strerror (err));
return(NULL);
}
if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_
PCM_ACCESS_RW_INTERLEAVED)) < 0) {
g_warning("cannot set access type (%s)\n", snd_strerror (
err));
return(NULL);
}
if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_
PCM_FORMAT_S16_LE)) < 0) {
g_warning("cannot set sample format (%s)\n", snd_strerror
(err));
return(NULL);
}
if ((err = snd_pcm_hw_params_set_rate (playback_handle, hw_params, 44100,
0)) < 0) {
g_warning("cannot set sample rate (%s)\n", snd_strerror (
err));
return(NULL);
}
if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)
) < 0) {
g_warning("cannot set channel count (%s)\n", snd_strerror
(err));
return(NULL);
}
periods = 4;
if ((err = snd_pcm_hw_params_set_periods (playback_handle, hw_params, per
iods, 0)) < 0) {
g_warning("cannot set periode size (%s)\n", snd_strerror
(err));
return(NULL);
}
buffer_size = CDDAFRAME * periods;
if ((err = snd_pcm_hw_params_set_buffer_size_near (playback_handle, hw_pa
rams, &buffer_size)) < 0) {
g_warning("cannot set buffer size (%s)\n", snd_strerror (
err));
return(NULL);
}
if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
g_warning("cannot set parameters (%s)\n", snd_strerror (e
rr));
return(NULL);
}
/* determine real buffer size */
snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
alsa_frame_size = snd_pcm_format_size(SND_PCM_FORMAT_S16_LE, 2);
abuf_size = (gint)buffer_size * alsa_frame_size;
snd_pcm_hw_params_free (hw_params);
if ((err = snd_pcm_prepare (playback_handle)) < 0) {
g_warning("cannot prepare audio interface for use (%s)\n"
,
snd_strerror (err));
return(NULL);
}
return (playback_handle);
}
#endif
#if defined(__FreeBSD__)
/* /*
* open the sound-device of linux and set cd-quality * open the sound-device of linux and set cd-quality
*/ */
gint open_linux_audio(gchar *dev) { gint open_linux_audio(gchar *dev) {
gint audio; gint audio;
gint tmp; gint tmp;
gint samplesize = 16; gint samplesize = 16;
gint dsp_stereo = 1; gint dsp_stereo = 1;
gint dsp_speed = 44100; gint dsp_speed = 44100;
skipping to change at line 524 skipping to change at line 615
g_print(" -q : quiet-mode\n"); g_print(" -q : quiet-mode\n");
} }
/* /*
* main programm * main programm
*/ */
gint main(gint argc, gchar **argv) { gint main(gint argc, gchar **argv) {
gint c; gint c;
gchar audio_dev[MAXLINE]; gchar audio_dev[MAXLINE];
gchar wavname[MAXLINE]; gchar wavname[MAXLINE];
gint audio = -1;
gint fd; gint fd;
gint l; gint l;
gint guimode = 0; gint guimode = 0;
gint quiet = 0; gint quiet = 0;
gint doplay = 1; gint doplay = 1;
gint tick = 0; gint tick = 0;
gint oldtick = 0; gint oldtick = 0;
off_t bytessofar = 0; off_t bytessofar = 0;
off_t totalbytes; off_t totalbytes;
gint min,sec; gint min,sec;
gchar keybuffer[MAXLINE]; gchar keybuffer[MAXLINE];
#if !(defined(linux)) #if !(defined(linux))
gint audio = -1;
gint ii; gint ii;
guchar tmpswap; guchar tmpswap;
#endif #endif
#if defined(linux)
snd_pcm_t *playback_handle;
snd_pcm_sframes_t frames, wroteframes;
#endif
/* if no device given, set default device */ /* if no device given, set default device */
strcpy(audio_dev,DEFAULT_AUDIO_DEVICE); strcpy(audio_dev,DEFAULT_AUDIO_DEVICE);
strcpy(wavname,""); strcpy(wavname,"");
while ((c = getopt(argc, argv, "d:gq")) != EOF) while ((c = getopt(argc, argv, "d:gq")) != EOF)
switch ((gchar)c) { switch ((gchar)c) {
case 'd': case 'd':
strncpy(audio_dev,optarg,MAXLINE); strncpy(audio_dev,optarg,MAXLINE);
break; break;
skipping to change at line 575 skipping to change at line 671
/* additional parameter given? */ /* additional parameter given? */
if (optind > argc -1) { if (optind > argc -1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
} else { } else {
strncpy(wavname,argv[optind++],MAXLINE); strncpy(wavname,argv[optind++],MAXLINE);
} }
/* the open sets also the global abuf_size-variable */ /* the open sets also the global abuf_size-variable */
#if defined(linux) || defined(__FreeBSD__) #if defined(linux)
playback_handle = open_alsa_audio(audio_dev);
#endif
#if defined(__FreeBSD__)
audio = open_linux_audio(audio_dev); audio = open_linux_audio(audio_dev);
#endif #endif
#if defined(sun) || defined(__OpenBSD__) #if defined(sun) || defined(__OpenBSD__)
audio = open_solaris_audio(audio_dev); audio = open_solaris_audio(audio_dev);
#endif #endif
#ifdef aix #ifdef aix
audio = open_aix_audio(audio_dev); audio = open_aix_audio(audio_dev);
#endif #endif
#ifdef hpux #ifdef hpux
audio = open_hpux_audio(audio_dev); audio = open_hpux_audio(audio_dev);
#endif #endif
#if defined(__sgi) #if defined(__sgi)
audio = open_irix_audio(audio_dev); audio = open_irix_audio(audio_dev);
#endif #endif
#if defined(linux)
if (playback_handle == NULL) {
g_warning("Can't init sound-system\n");
exit(1);
}
#endif
#if !(defined(linux))
if (audio < 0) { if (audio < 0) {
g_warning("Can't init sound-system\n"); g_warning("Can't init sound-system\n");
exit(1); exit(1);
} }
#endif
if ((audiobuf = (guchar *)g_new(guchar *,abuf_size)) == NULL) { if ((audiobuf = (guchar *)g_new(guchar *,abuf_size)) == NULL) {
g_warning("Unable to allocate audio-buffer\n"); g_warning("Unable to allocate audio-buffer\n");
exit(1); exit(1);
} }
/* open wavfile */ /* open wavfile */
fd = open (wavname, O_RDONLY, 0); fd = open (wavname, O_RDONLY, 0);
if (fd == -1) { if (fd == -1) {
skipping to change at line 643 skipping to change at line 750
} }
/* ok..all set now, start playing */ /* ok..all set now, start playing */
while (1) { while (1) {
/* guimode: look for commands from stdin */ /* guimode: look for commands from stdin */
if (guimode && (read_line(STDIN_FILENO,keybuffer,MAXLINE) > 0)) { if (guimode && (read_line(STDIN_FILENO,keybuffer,MAXLINE) > 0)) {
/* stop command */ /* stop command */
if (g_ascii_strncasecmp(keybuffer,"stop",4) == 0) { if (g_ascii_strncasecmp(keybuffer,"stop",4) == 0) {
lseek(fd, waveBase, SEEK_SET); lseek(fd, waveBase, SEEK_SET);
#if defined(linux)
snd_pcm_drain(playback_handle);
#endif
bytessofar = 0; bytessofar = 0;
tick = 0; tick = 0;
doplay = 0; doplay = 0;
g_print("stop0\n"); g_print("stop0\n");
fflush(stdout); fflush(stdout);
} }
/* play command */ /* play command */
if (g_ascii_strncasecmp(keybuffer,"play",4) == 0) { if (g_ascii_strncasecmp(keybuffer,"play",4) == 0) {
#if defined(linux)
snd_pcm_prepare(playback_handle);
#endif
doplay = 1; doplay = 1;
} }
/* pause command */ /* pause command */
if (g_ascii_strncasecmp(keybuffer,"pause",5) == 0) { if (g_ascii_strncasecmp(keybuffer,"pause",5) == 0) {
doplay=1-doplay; if (doplay) {
g_print("%s%d\n",doplay?"play":"stop",tick); doplay = 0;
fflush(stdout); g_print("%s%d\n","stop",tick);
fflush(stdout);
}
} }
/* setxxx command */ /* setxxx command */
if (g_ascii_strncasecmp(keybuffer,"set",3) == 0) { if (g_ascii_strncasecmp(keybuffer,"set",3) == 0) {
tick = atoi(keybuffer+3); tick = atoi(keybuffer+3);
bytessofar = (off_t)tick *CDDAFRAME*75; bytessofar = (off_t)tick *CDDAFRAME*75;
lseek(fd, waveBase+bytessofar, lseek(fd, waveBase+bytessofar,
SEEK_SET); SEEK_SET);
g_print("%s%d\n",doplay?"play":"stop",tick); g_print("%s%d\n",doplay?"play":"stop",tick);
fflush(stdout); fflush(stdout);
skipping to change at line 716 skipping to change at line 831
tick=(gint)(bytessofar/CDDAFRAME/75); tick=(gint)(bytessofar/CDDAFRAME/75);
if (tick != oldtick) { if (tick != oldtick) {
g_print("play%d\n",tick); g_print("play%d\n",tick);
fflush(stdout); fflush(stdout);
oldtick = tick; oldtick = tick;
} }
} }
#if defined(__sgi) #if defined(__sgi)
write_irix_audio(audiobuf, l); write_irix_audio(audiobuf, l);
#elif defined(linux)
frames = (snd_pcm_sframes_t) (l/alsa_frame_size);
wroteframes = snd_pcm_writei (playback_handle, au
diobuf, frames);
if (wroteframes != frames) {
g_print("write error to audio-device (wro
te %d/%d)\n", (gint)wroteframes, (gint)frames);
exit(-1);
}
#else #else
if (write(audio, audiobuf, l) != l) { if (write(audio, audiobuf, l) != l) {
g_print("write error to audio-device\n"); g_print("write error to audio-device\n");
exit(-1); exit(-1);
} }
#endif #endif
bytessofar+=(off_t)l; bytessofar+=(off_t)l;
} else { } else {
/* read error on wav-file */ /* read error on wav-file */
skipping to change at line 755 skipping to change at line 877
/* we are in pause-mode */ /* we are in pause-mode */
/* wait a short while and then look for commands again */ /* wait a short while and then look for commands again */
usleep(100); usleep(100);
} }
} }
close(fd); close(fd);
#if defined(__sgi) #if defined(__sgi)
close_irix_audio(); close_irix_audio();
#elif defined(linux)
snd_pcm_close (playback_handle);
#else #else
close(audio); close(audio);
#endif #endif
#if (defined hpux) && (defined hpux_alib) #if (defined hpux) && (defined hpux_alib)
ASetCloseDownMode( audioServer, AKeepTransactions, NULL ); ASetCloseDownMode( audioServer, AKeepTransactions, NULL );
ACloseAudio( audioServer, NULL ); ACloseAudio( audioServer, NULL );
#endif #endif
return 0; return 0;
 End of changes. 16 change blocks. 
8 lines changed or deleted 152 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)