drunkfix.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
  3. * http://www.trevorwishart.co.uk
  4. * http://www.composersdesktop.com
  5. *
  6. This file is part of the CDP System.
  7. The CDP System is free software; you can redistribute it
  8. and/or modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The CDP System is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the CDP System; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. 02111-1307 USA
  19. *
  20. */
  21. /*************************** BOUNCE_OFF_FILE_END_IF_NECESSARY
  22. **************************/
  23. int bounce_off_file_end_if_necessary(int *here,int thisdur,int chans,int
  24. splicelen,dataptr dz)
  25. {
  26. int diff, initial_diff, needed;
  27. initial_diff = abs(dz->insams[0] - *here); /* Ensure enough room to read
  28. final segment and splice */
  29. if(EVEN(chans) && ODD(initial_diff)) {
  30. sprintf(errstr,"Stereo anomaly at file end:
  31. bounce_off_file_end_if_necessary()\n");
  32. return(PROGRAM_ERROR);
  33. }
  34. if((needed = thisdur + splicelen) > dz->sampbuf[0]) {
  35. sprintf(errstr,"Segement duration exceeds size of sound\n");
  36. return(DATA_ERROR);
  37. }
  38. while((diff = dz->insams[0] - *here) < needed) {
  39. *here -= initial_diff; /* Bounce off end of buffer if ness */
  40. if(*here < 0) { /* But, if it bounces off BOTH ends !! */
  41. *here = (dz->insams[0] - needed)/dz->infile->channels;
  42. *here = (int)round(*here * drand48()) * dz->infile->channels;
  43. /*
  44. sprintf(errstr,"Anomaly in bounce_off_file_end_if_necessary()\n");
  45. return(PROGRAM_ERROR);
  46. */
  47. }
  48. }
  49. return(FINISHED);
  50. }