Ich werfe einen Editor an, schreibe ein paar Codezeilen, compiliere, führe das Programm aus und habe dann PCM-Dateien, mit der ich entweder CD-RWs oder Soundkarten beglücke. Einen Tag später weiß ich nicht mehr, wo die Quelldatei gelandet ist, weil die meist x.c oder y.c heißt.elchhome hat geschrieben:Was für einen SW Tongenerator nimmst du denn, oder benutzt du HW?
Code: Alles auswählen
#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323844
#endif
static short
double2int16 (double x )
{
if ( x < -32768. ) return -32768 ;
if ( x > +32767. ) return +32767 ;
return (short) floor (x+0.5) ;
}
static void
calc ( const char* filename, const float* c, float fs, long samples )
{
FILE* fp ;
int i ;
int j ;
double sum ;
short i16[2] ;
fp = fopen ( filename, "wb" ) ;
for ( i = 0; i < samples; i++ ) {
sum = 0. ;
for ( j = 0; coeff[j] != 0.; j += 2 )
sum += sin (c[j] * 2. * M_PI * i / fs) * c[j+1] ;
i16[0] = i16[1] = double2int16 ( 16000 * sum ) ;
fwrite ( i16, 2, 2, fp ) ;
}
fclose (fp) ;
}
int main
(void)
{
static float f1[] = { 24, 0.5, 0 } ;
static float f2[] = { 24, 0.5, 36, 0.16, 60, 0.05, 84, 0.02, 0 } ;
static float f3[] = { 24, 0.5, 32, 0.16, 40, 0.08, 56, 0.05, 64, 0.03, 84, 0.02, 0 } ;
calc ( "t1.pcm", f1, 44100., 44100*10 ) ;
calc ( "t2.pcm", f2, 44100., 44100*10 ) ;
calc ( "t3.pcm", f3, 44100., 44100*10 ) ;
return 0 ;
}