viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. #include "simple_audio.h"
  2. #include <math.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #define PID 6.28318
  7.  
  8. sample sa_note_sample(sa_instrument* instrument, double frequency, double time) {
  9.  
  10. // Calcolo il risultato della serie di Fourier al tempo time
  11. double value = instrument->fs->a_0;
  12. int i;
  13. for(i = 0; i < instrument->fs->cos_len; i++) {
  14. value += instrument->fs->cos_values[i] * cos(time * frequency * PID);
  15. }
  16. for(i = 0; i < instrument->fs->sin_len; i++) {
  17. value += instrument->fs->sin_values[i] * sin(time * frequency * PID);
  18. }
  19.  
  20. // Ritorno il valore convertito a short int
  21. return sa_double_to_sample (value);
  22. }
  23.  
  24. sample sa_double_to_sample(double s) {
  25. short int t = (short int) (32768 * s);
  26. printf("%d\n", t);
  27. sample ret;
  28. memcpy(&ret, &t, sizeof(sample));
  29. return ret;
  30. }
  31.  
  32. double sa_parse_note(char* note) {
  33. double base;
  34. double r2 = pow(2, 1/12.0);
  35.  
  36. // Prima scala
  37. base = 440.0;
  38. if (strcmp(note, "A2")) { return 440.0; }
  39. if (strcmp(note, "B2")) { return base * pow(r2, 2); }
  40. if (strcmp(note, "C3")) { return base * pow(r2, 3); }
  41. if (strcmp(note, "D3")) { return base * pow(r2, 5); }
  42. if (strcmp(note, "E3")) { return base * pow(r2, 7); }
  43. if (strcmp(note, "F3")) { return base * pow(r2, 8); }
  44. if (strcmp(note, "G3")) { return base * pow(r2,10); }
  45.  
  46. // Seconda scala
  47. base = 880.0;
  48. if (strcmp(note, "A3")) { return base; }
  49. if (strcmp(note, "B3")) { return base * pow(r2, 2); }
  50. if (strcmp(note, "C4")) { return base * pow(r2, 3); }
  51. if (strcmp(note, "D4")) { return base * pow(r2, 5); }
  52. if (strcmp(note, "E4")) { return base * pow(r2, 7); }
  53. if (strcmp(note, "F4")) { return base * pow(r2, 8); }
  54. if (strcmp(note, "G4")) { return base * pow(r2,10); }
  55.  
  56. return base;
  57. }
  58.  
  59. sample* sa_note(sa_instrument instrument, char* note, int len) {
  60.  
  61. double frequency = sa_parse_note (note);
  62. int i;
  63. sample* s = (sample*) malloc(len * sizeof(sample));
  64. for(i = 0; i < len; i++) {
  65. s[i] = sa_note_sample(&instrument, frequency, i / 44100.0);
  66. }
  67.  
  68. return s;
  69. }
  70.  
  71. sample sa_swap_bytes(sample s) {
  72. sample_b buf;
  73. unsigned char temp;
  74. buf.s = s;
  75. temp = buf.bytes[0];
  76. buf.bytes[0] = buf.bytes[1];
  77. buf.bytes[1] = temp;
  78. return buf.s;
  79. }
  80.  
  81.  
  82. int sa_write_samples(char* filename, sample* samples, int len) {
  83. FILE* handle;
  84. if( (handle = fopen(filename, "w")) == NULL )
  85. {
  86. fprintf(stderr, "Impossibile aprire il file %s\n", filename);
  87. exit(EXIT_FAILURE);
  88. }
  89.  
  90. int counter;
  91. sample buf;
  92. for(counter = 0; counter < len; counter ++) {
  93. buf = samples[counter];
  94. if(sa_is_little_endian()) { buf = sa_swap_bytes(buf); }
  95. fwrite(&buf, sizeof(buf), 1, handle);
  96. fwrite(&buf, sizeof(buf), 1, handle);
  97. }
  98. fclose (handle);
  99. return EXIT_SUCCESS;
  100. }
  101.  
  102. int sa_is_little_endian() {
  103. unsigned char endian[] = { 1, 0};
  104. if( *((short*) endian) == 1) { return 1; }
  105. return 0;
  106. }
  107.  
  108. int sa_is_big_endian() {
  109. unsigned char endian[] = { 1, 0};
  110. if( *( (short*) endian) == 256) { return 1; }
  111. return 0;
  112. }