static int hairwrite(int fd, char *buf, int len) { int num_bytes=len; int send; int ret; char *output_samples; output_samples = buf; if(__UsbSoundCard) alsa_play(buf,num_bytes); while(num_bytes > 0) { send = num_bytes>I2S_BUF? I2S_BUF:num_bytes; ret = write(fd, output_samples, send); if (ret < 0) { usleep(50000); printf("write error!\n"); ret = write(fd, output_samples, send); return ret; } num_bytes-=ret; output_samples+=ret; } }
int main (int argc, char *argv []) { if (argc < 2) { printf ("\nUsage : %s <input sound file>\n\n", program_name (argv [0])) ; printf (" Using %s.\n\n", sf_version_string ()) ; #if (OS_IS_WIN32 == 1) printf ("This is a Unix style command line application which\n" "should be run in a MSDOS box or Command Shell window.\n\n") ; printf ("Sleeping for 5 seconds before exiting.\n\n") ; Sleep (5 * 1000) ; #endif return 1 ; } ; #if defined (__ANDROID__) puts ("*** Playing sound not yet supported on Android.") ; puts ("*** Please feel free to submit a patch.") ; return 1 ; #elif defined (__linux__) #if HAVE_ALSA_ASOUNDLIB_H if (access ("/proc/asound/cards", R_OK) == 0) alsa_play (argc, argv) ; else #endif opensoundsys_play (argc, argv) ; #elif defined (__FreeBSD_kernel__) || defined (__FreeBSD__) opensoundsys_play (argc, argv) ; #elif (defined (__MACH__) && defined (__APPLE__) && OSX_DARWIN_VERSION <= 11) macosx_play (argc, argv) ; #elif HAVE_SNDIO_H sndio_play (argc, argv) ; #elif (defined (sun) && defined (unix)) solaris_play (argc, argv) ; #elif (OS_IS_WIN32 == 1) win32_play (argc, argv) ; #elif (defined (__MACH__) && defined (__APPLE__) && OSX_DARWIN_VERSION > 11) printf ("OS X 10.8 and later have a new Audio API.\n") ; printf ("Someone needs to write code to use that API.\n") ; return 1 ; #elif defined (__BEOS__) printf ("This program cannot be compiled on BeOS.\n") ; printf ("Instead, compile the file sfplay_beos.cpp.\n") ; return 1 ; #else puts ("*** Playing sound not yet supported on this platform.") ; puts ("*** Please feel free to submit a patch.") ; return 1 ; #endif return 0 ; } /* main */
void alsa_check_fds(fd_set * rfds, fd_set * wfds) { struct pollfd *f; int err; unsigned short revents; if (out_handle && !rdpsnd_queue_empty()) { for (f = pfds_out; f < &pfds_out[num_fds_out]; f++) { f->revents = 0; if (f->fd != -1) { /* Fixme: This doesn't properly deal with things like POLLHUP */ if (FD_ISSET(f->fd, rfds)) f->revents |= POLLIN; if (FD_ISSET(f->fd, wfds)) f->revents |= POLLOUT; } } err = snd_pcm_poll_descriptors_revents(out_handle, pfds_out, num_fds_out, &revents); if (err < 0) return; if (revents & POLLOUT) alsa_play(); } if (in_handle) { for (f = pfds_in; f < &pfds_in[num_fds_in]; f++) { f->revents = 0; if (f->fd != -1) { /* Fixme: This doesn't properly deal with things like POLLHUP */ if (FD_ISSET(f->fd, rfds)) f->revents |= POLLIN; if (FD_ISSET(f->fd, wfds)) f->revents |= POLLOUT; } } err = snd_pcm_poll_descriptors_revents(in_handle, pfds_in, num_fds_in, &revents); if (err < 0) return; if (revents & POLLIN) alsa_record(); } }
int main (int argc, char *argv []) { if (argc < 2) { printf ("\nUsage : %s <input sound file>\n\n", argv [0]) ; #if (OS_IS_WIN32 == 1) printf ("This is a Unix style command line application which\n" "should be run in a MSDOS box or Command Shell window.\n\n") ; printf ("Sleeping for 5 seconds before exiting.\n\n") ; /* This is the officially blessed by microsoft way but I can't get ** it to link. ** Sleep (15) ; ** Instead, use this: */ Sleep (5 * 1000) ; #endif return 1 ; } ; #if defined (__linux__) #if HAVE_ALSA_ASOUNDLIB_H if (access ("/proc/asound/cards", R_OK) == 0) alsa_play (argc, argv) ; else #endif opensoundsys_play (argc, argv) ; #elif defined (__FreeBSD_kernel__) || defined (__FreeBSD__) opensoundsys_play (argc, argv) ; #elif (defined (__MACH__) && defined (__APPLE__)) macosx_play (argc, argv) ; #elif defined HAVE_SNDIO_H sndio_play (argc, argv) ; #elif (defined (sun) && defined (unix)) solaris_play (argc, argv) ; #elif (OS_IS_WIN32 == 1) win32_play (argc, argv) ; #elif defined (__BEOS__) printf ("This program cannot be compiled on BeOS.\n") ; printf ("Instead, compile the file sfplay_beos.cpp.\n") ; return 1 ; #else puts ("*** Playing sound not yet supported on this platform.") ; puts ("*** Please feel free to submit a patch.") ; return 1 ; #endif return 0 ; } /* main */