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. sa_track* sa_track_new(int n) {
  9. sa_track* t = malloc(sizeof(sa_track));
  10. int i;
  11. t->channels = n;
  12. t->len = malloc(sizeof(int) * n);
  13. t->data = malloc(sizeof(sample*) * n);
  14. for (i = 0; i < n; i++) {
  15. t->data[i] = NULL;
  16. t->len[i] = 0;
  17. }
  18. return t;
  19. }
  20.  
  21. int sa_track_free(sa_track* t) {
  22. int i;
  23. for(i=0; i < t->channels; i++) {
  24. free(t->data[i]);
  25. }
  26. free(t->len);
  27. free(t->data);
  28. return 0;
  29. }
  30.  
  31. int sa_track_append(sa_track* t, sample* s, int n, int channel) {
  32. if(channel > t->channels) {
  33. fprintf(stderr, "Trying to channel %d, but track has on ly %d channels\n", channel, t->channels);
  34. exit(EXIT_FAILURE);
  35. }
  36. // Allargo lo spazio
  37.  
  38. if(!t->data[channel]) { t->data[channel] = (sample*) malloc(n * sizeof(sample)); }
  39. else {
  40. t->data[channel] = (sample*) realloc(t->data[channel], (t->len[channel] + n)* sizeof(sample));
  41. }
  42. memcpy(t->data[channel] + t->len[channel], s, n * sizeof(sample));
  43. t->len[channel] = t->len[channel] + n;
  44.  
  45. return 0;
  46. }
  47.  
  48. int sa_track_write(sa_track* t, char* filename) {
  49.  
  50. FILE* handle;
  51. int counter, j;
  52. sample buf;
  53.  
  54. if( (handle = fopen(filename, "w")) == NULL )
  55. {
  56. fprintf(stderr, "Impossibile aprire il file %s\n", filename);
  57. exit(EXIT_FAILURE);
  58. }
  59.  
  60. for(j = 1; j < t->channels; j++) {
  61. if(t->len[j] != t->len[0]) {
  62. fprintf(stderr, "Tutte le tracce devono avere lo stesso numero di canali!\n");
  63. }
  64. };
  65.  
  66. for(counter = 0; counter < t->len[0]; counter ++) {
  67. for (j = 0; j < t->channels; j++) {
  68. buf = t->data[j][counter];
  69. if(sa_is_little_endian()) { buf = sa_swap_bytes(buf); }
  70. fwrite(&buf, sizeof(buf), 1, handle);
  71. }
  72. }
  73.  
  74. fclose (handle);
  75. return EXIT_SUCCESS;
  76.  
  77. }
  78.  
  79. sample sa_note_sample(sa_instrument* instrument, double frequency, double time) {
  80.  
  81. // Calcolo il risultato della serie di Fourier al tempo time
  82. double value = instrument->fs->a_0;
  83. int i;
  84. for(i = 0; i < instrument->fs->cos_len; i++) {
  85. value += instrument->fs->cos_values[i] * cos(time * frequency * PID);
  86. }
  87. for(i = 0; i < instrument->fs->sin_len; i++) {
  88. value += instrument->fs->sin_values[i] * sin(time * frequency * PID);
  89. }
  90.  
  91. // Ritorno il valore convertito a short int
  92. return sa_double_to_sample (value);
  93. }
  94.  
  95. sample sa_double_to_sample(double s) {
  96. short int t = (short int) (32768 * s);
  97. sample ret;
  98. memcpy(&ret, &t, sizeof(sample));
  99. return ret;
  100. }
  101.  
  102. double sa_parse_note(char* note) {
  103. double base;
  104. double r2 = pow(2, 1/12.0);
  105.  
  106. // Prima scala
  107. base = 440.0;
  108. if (strcmp(note, "A2") == 0) { return 440.0; }
  109. if (strcmp(note, "B2") == 0) { return base * pow(r2, 2); }
  110. if (strcmp(note, "C3") == 0) { return base * pow(r2, 3); }
  111. if (strcmp(note, "D3") == 0) { return base * pow(r2, 5); }
  112. if (strcmp(note, "E3") == 0) { return base * pow(r2, 7); }
  113. if (strcmp(note, "F3") == 0) { return base * pow(r2, 8); }
  114. if (strcmp(note, "G3") == 0) { return base * pow(r2,10); }
  115.  
  116. // Seconda scala
  117. base = 880.0;
  118. if (strcmp(note, "A3") == 0) { return base; }
  119. if (strcmp(note, "B3") == 0) { return base * pow(r2, 2); }
  120. if (strcmp(note, "C4") == 0) { return base * pow(r2, 3); }
  121. if (strcmp(note, "D4") == 0) { return base * pow(r2, 5); }
  122. if (strcmp(note, "E4") == 0) { return base * pow(r2, 7); }
  123. if (strcmp(note, "F4") == 0) { return base * pow(r2, 8); }
  124. if (strcmp(note, "G4") == 0) { return base * pow(r2,10); }
  125.  
  126. return base;
  127. }
  128.  
  129. sample* sa_note(sa_instrument instrument, char* note, int len) {
  130.  
  131. double frequency = sa_parse_note (note);
  132. printf("Mapped %s to %lf Hz\n", note, frequency);
  133. int i;
  134. sample* s = (sample*) malloc(len * sizeof(sample));
  135. for(i = 0; i < len; i++) {
  136. s[i] = sa_note_sample(&instrument, frequency, i / 44100.0);
  137. }
  138.  
  139. return s;
  140. }
  141.  
  142. sample* sa_silence(int len) {
  143. sample* s = (sample*) malloc(sizeof(sample) * len);
  144. memset(s, 0, len * sizeof(sample));
  145. return s;
  146. }
  147.  
  148. sample sa_swap_bytes(sample s) {
  149. sample_b buf;
  150. unsigned char temp;
  151. buf.s = s;
  152. temp = buf.bytes[0];
  153. buf.bytes[0] = buf.bytes[1];
  154. buf.bytes[1] = temp;
  155. return buf.s;
  156. }
  157.  
  158.  
  159.  
  160. int sa_is_little_endian() {
  161. unsigned char endian[] = { 1, 0};
  162. if( *((short*) endian) == 1) { return 1; }
  163. return 0;
  164. }
  165.  
  166. int sa_is_big_endian() {
  167. unsigned char endian[] = { 1, 0};
  168. if( *( (short*) endian) == 256) { return 1; }
  169. return 0;
  170. }