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.

synth_frequency_impl.cc 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright (C) 2000 Stefan Westerfeld
  3. stefan@space.twc.de
  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. #include "artsflow.h"
  18. #include "stdsynthmodule.h"
  19. #include <math.h>
  20. #include <stdio.h>
  21. using namespace Arts;
  22. namespace Arts {
  23. class Synth_FREQUENCY_impl :public Synth_FREQUENCY_skel, public StdSynthModule
  24. {
  25. float fpos;
  26. public:
  27. void streamInit() {
  28. fpos = 0;
  29. }
  30. void calculateBlock(unsigned long cycles) {
  31. float fsample = samplingRateFloat;
  32. float finc = *frequency/fsample;
  33. while(cycles)
  34. {
  35. if(cycles >= 8 && ((finc*8+fpos) < 0.9))
  36. {
  37. fpos += finc; *pos++ = fpos;
  38. fpos += finc; *pos++ = fpos;
  39. fpos += finc; *pos++ = fpos;
  40. fpos += finc; *pos++ = fpos;
  41. fpos += finc; *pos++ = fpos;
  42. fpos += finc; *pos++ = fpos;
  43. fpos += finc; *pos++ = fpos;
  44. fpos += finc; *pos++ = fpos;
  45. cycles -= 8;
  46. }
  47. else
  48. {
  49. fpos += finc;
  50. fpos -= floor(fpos);
  51. *pos++ = fpos;
  52. cycles--;
  53. }
  54. }
  55. }
  56. };
  57. REGISTER_IMPLEMENTATION(Synth_FREQUENCY_impl);
  58. }