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]
#include "simple_audio.h" #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define PID 6.28318 sa_track* sa_track_new(int n) { sa_track* t = malloc(sizeof(sa_track)); int i; t->channels = n; t->len = malloc(sizeof(int) * n); t->data = malloc(sizeof(sample*) * n); for (i = 0; i < n; i++) { t->data[i] = NULL; t->len[i] = 0; } return t; } int sa_track_free(sa_track* t) { int i; for(i=0; i < t->channels; i++) { free(t->data[i]); } free(t->len); free(t->data); return 0; } int sa_track_append(sa_track* t, sample* s, int n, int channel) { if(channel > t->channels) { fprintf(stderr, "Trying to channel %d, but track has on ly %d channels\n", channel, t->channels); exit(EXIT_FAILURE); } // Allargo lo spazio if(!t->data[channel]) { t->data[channel] = (sample*) malloc(n * sizeof(sample)); } else { t->data[channel] = (sample*) realloc(t->data[channel], (t->len[channel] + n)* sizeof(sample)); } memcpy(t->data[channel] + t->len[channel], s, n * sizeof(sample)); t->len[channel] = t->len[channel] + n; return 0; } int sa_track_write(sa_track* t, char* filename) { FILE* handle; int counter, j; sample buf; if( (handle = fopen(filename, "w")) == NULL ) { fprintf(stderr, "Impossibile aprire il file %s\n", filename); exit(EXIT_FAILURE); } for(j = 1; j < t->channels; j++) { if(t->len[j] != t->len[0]) { fprintf(stderr, "Tutte le tracce devono avere lo stesso numero di canali!\n"); } }; for(counter = 0; counter < t->len[0]; counter ++) { for (j = 0; j < t->channels; j++) { buf = t->data[j][counter]; if(sa_is_little_endian()) { buf = sa_swap_bytes(buf); } fwrite(&buf, sizeof(buf), 1, handle); } } fclose (handle); return EXIT_SUCCESS; } sample sa_note_sample(sa_instrument* instrument, double frequency, double time) { // Calcolo il risultato della serie di Fourier al tempo time double value = instrument->fs->a_0; int i; for(i = 0; i < instrument->fs->cos_len; i++) { value += instrument->fs->cos_values[i] * cos(time * frequency * PID); } for(i = 0; i < instrument->fs->sin_len; i++) { value += instrument->fs->sin_values[i] * sin(time * frequency * PID); } // Ritorno il valore convertito a short int return sa_double_to_sample (value); } sample sa_double_to_sample(double s) { short int t = (short int) (32768 * s); sample ret; memcpy(&ret, &t, sizeof(sample)); return ret; } double sa_parse_note(char* note) { double base; double r2 = pow(2, 1/12.0); // Prima scala base = 440.0; if (strcmp(note, "A2") == 0) { return 440.0; } if (strcmp(note, "B2") == 0) { return base * pow(r2, 2); } if (strcmp(note, "C3") == 0) { return base * pow(r2, 3); } if (strcmp(note, "D3") == 0) { return base * pow(r2, 5); } if (strcmp(note, "E3") == 0) { return base * pow(r2, 7); } if (strcmp(note, "F3") == 0) { return base * pow(r2, 8); } if (strcmp(note, "G3") == 0) { return base * pow(r2,10); } // Seconda scala base = 880.0; if (strcmp(note, "A3") == 0) { return base; } if (strcmp(note, "B3") == 0) { return base * pow(r2, 2); } if (strcmp(note, "C4") == 0) { return base * pow(r2, 3); } if (strcmp(note, "D4") == 0) { return base * pow(r2, 5); } if (strcmp(note, "E4") == 0) { return base * pow(r2, 7); } if (strcmp(note, "F4") == 0) { return base * pow(r2, 8); } if (strcmp(note, "G4") == 0) { return base * pow(r2,10); } return base; } sample* sa_note(sa_instrument instrument, char* note, int len) { double frequency = sa_parse_note (note); int i; sample* s = (sample*) malloc(len * sizeof(sample)); for(i = 0; i < len; i++) { s[i] = sa_note_sample(&instrument, frequency, i / 44100.0); } return s; } sample* sa_silence(int len) { sample* s = (sample*) malloc(sizeof(sample) * len); memset(s, 0, len * sizeof(sample)); return s; } sample sa_swap_bytes(sample s) { sample_b buf; unsigned char temp; buf.s = s; temp = buf.bytes[0]; buf.bytes[0] = buf.bytes[1]; buf.bytes[1] = temp; return buf.s; } int sa_is_little_endian() { unsigned char endian[] = { 1, 0}; if( *((short*) endian) == 1) { return 1; } return 0; } int sa_is_big_endian() { unsigned char endian[] = { 1, 0}; if( *( (short*) endian) == 256) { return 1; } return 0; }