Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

97 lines
3.1KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. static float seconds_to_buffer = 5.0f;
  19. /* A Disk_Stream uses a separate I/O thread to stream a track's
  20. regions from disk into a ringbuffer, to be processed by the RT
  21. thread (or vice-versa). */
  22. /* FIXME: handle termination of IO thread in destructor */
  23. /* FIXME: could all of this not simply be included in the Track_Header
  24. class? */
  25. /** start Disk_Stream thread */
  26. void
  27. Disk_Stream::run ( void )
  28. {
  29. if ( pthread_create( 0, 0, &Disk_Stream::io_thread, this ) != 0 )
  30. /* error */;
  31. }
  32. /* static wrapper */
  33. void
  34. Disk_Stream::io_thread ( void *arg )
  35. {
  36. ((Disk_Stream*)arg)->io_thread();
  37. }
  38. /* THREAD: IO */
  39. /** read a block of data from the track into /buf/ */
  40. Disk_Stream::read_block ( sample_t *buf )
  41. {
  42. if ( _th->track()->play( buf, _frame, _nframes, channels() ) )
  43. _frame += nframes;
  44. else
  45. /* error */;
  46. }
  47. /* THREAD: IO */
  48. void
  49. Disk_Stream::io_thread ( void )
  50. {
  51. printf( "IO thread running...\n" );
  52. /* buffer to hold the interleaved data returned by the track reader */
  53. sample_t *buf = new sample_t[ _nframes * channels() ];
  54. /* buffer for a single channel */
  55. sample_t *cbuf = new sample_t[ _nframes ];
  56. const size_t block_size = _nframes * sizeof( sample_t );
  57. while ( wait_for_block() )
  58. {
  59. read_block( buf );
  60. /* deinterleave the buffer and stuff it into the per-channel ringbuffers */
  61. for ( int i = channels(); i-- )
  62. {
  63. int k = 0;
  64. for ( int j = i; j < _nframes; j += channels() )
  65. cbuf[ k++ ] = buf[ j ];
  66. jack_ringbuffer_write( _rb[ i ], cbuf, block_size );
  67. }
  68. }
  69. delete[] buf;
  70. delete[] cbuf;
  71. }
  72. /* THREAD: RT */
  73. void
  74. Disk_Stream::process ( nframes_t nframes )
  75. {
  76. _th->channels();
  77. block_processed();
  78. }