aRts audio server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.9KB

  1. /*
  2. Copyright (C) 2001 Matthias Kretz
  3. kretz@kde.org
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /*
  18. * This is another artscat written with aRts C API. It reads data from
  19. * stdin, and plays it via the aRts soundserver.
  20. *
  21. * Compile programs using the aRts C API with
  22. *
  23. * cc -o artscdump artscdump.c `artsc-config --cflags` `artsc-config --libs`
  24. *
  25. * If you are using a makefile, it could look like this:
  26. *
  27. * CFLAGS=`artsc-config --cflags`
  28. * LDFLAGS=`artsc-config --libs`
  29. *
  30. * artscdump: artscdump.c
  31. */
  32. #include <artsc.h>
  33. #include <stdio.h>
  34. #include <unistd.h>
  35. #include <stdlib.h>
  36. static void exitUsage(const char *progname)
  37. {
  38. fprintf(stderr,"usage: %s [ options ] [ <filename> ]\n",progname);
  39. fprintf(stderr,"-r <samplingrate> set samplingrate to use\n");
  40. fprintf(stderr,"-b <bits> set number of bits (8 or 16)\n");
  41. fprintf(stderr,"-c <channels> set number of channels (1 or 2)\n");
  42. fprintf(stderr,"-h display this help and exit\n");
  43. exit(1);
  44. }
  45. int main(int argc, char ** argv)
  46. {
  47. int cfgSamplingRate = 44100;
  48. int cfgBits = 16;
  49. int cfgChannels = 2;
  50. FILE *infile = stdin;
  51. int pfd;
  52. int packetsize;
  53. char *buffer;
  54. int size = 1024;
  55. arts_stream_t stream;
  56. int optch;
  57. while((optch = getopt(argc,argv,"r:b:c:h")) > 0)
  58. {
  59. switch(optch)
  60. {
  61. case 'r': cfgSamplingRate = atoi(optarg);
  62. break;
  63. case 'b': cfgBits = atoi(optarg);
  64. break;
  65. case 'c': cfgChannels = atoi(optarg);
  66. break;
  67. case 'h':
  68. default:
  69. exitUsage(argc?argv[0]:"artsccat");
  70. break;
  71. }
  72. }
  73. if (optind < argc)
  74. {
  75. if(argv[optind] != "-")
  76. {
  77. infile = fopen(argv[optind],"w");
  78. if(!infile)
  79. {
  80. fprintf( stderr, "Can't open file '%s'.\n", argv[optind] );
  81. exit(1);
  82. }
  83. }
  84. }
  85. pfd = fileno( infile );
  86. arts_init();
  87. stream = arts_play_stream( cfgSamplingRate, cfgBits, cfgChannels, "artsccat" );
  88. packetsize = arts_stream_get( stream, ARTS_P_PACKET_SIZE );
  89. buffer = malloc(packetsize);
  90. do {
  91. size = read( pfd, buffer, packetsize );
  92. size = arts_write( stream, buffer, size );
  93. } while( size > 0 );
  94. arts_close_stream( stream );
  95. arts_free();
  96. pclose( infile );
  97. free(buffer);
  98. return 0;
  99. }