Example #1
0
File: te.c Project: ITikhonov/tem
void jam_keypress(unsigned int k) {
	if(k==GDK_KEY_Tab) { pa_stream_cork(ps,1,jam_end,0); return; }

	uint8_t n=lettertonote(k);
	if(n==255) return;
	uint32_t f=note2freq(n);

	int i;
	for(i=0;i<stack.len;i++) {
		if(stack.action[i].f==action_play_sound && stack.action[i].a.u32==f) return;
	}
	struct action *a=push_stack(action_play_sound);
	a->a.u32=a->u32=f;
}
Example #2
0
File: te.c Project: ITikhonov/tem
void jam_keyrelease(unsigned int k) {
	int i,m=0;
	uint8_t n=lettertonote(k);
	if(n==255) return;
	uint32_t f=note2freq(n);
	printf("release %hhu\n",n); print_stack();

	for(i=0;i<stack.len;i++) {
		if(stack.action[i].f==action_play_sound && stack.action[i].a.u32==f) { m++; continue; }
		if(m>0) stack.action[i-m]=stack.action[i];
	}
	stack.len-=m;
	printf("/release\n"); print_stack();
}
Example #3
0
File: te.c Project: ITikhonov/tem
int pushNote(char c0) {
	int sharp=0;
	char c=gc();
	if(c=='#') { sharp=1; c=gc(); }
	unsigned int octave=c-'0';
	int n;

	printf("play note %c%s%c\n",c0,sharp?"#":"",c);

	if(sharp) {
		switch(c0) {
		case 'C': n=-5; break;
		case 'D': n=-3; break;
		case 'F': n=0; break;
		case 'G': n=2; break;
		case 'A': n=4; break;
		default: return -1;
		}
	} else {
		switch(c0) {
		case 'C': n=-6; break;
		case 'D': n=-4; break;
		case 'E': n=-2; break;
		case 'F': n=-1; break;
		case 'G': n=1; break;
		case 'A': n=3; break;
		case 'B': n=5; break;
		default: return -1;
		}
	}
	//  C   C# D  D#  E   F   F# G G# A A# B
	//  -6 -5 -4  -3 -2  -1   0  1 2  3 4  5

	int note=octave*12+n;

	printf("play note %c%s%c (%u)\n",c0,sharp?"#":"",c,note);

	// 0 is F#, A is 3
	struct action *a=push_stack(action_play_sound);
	a->a.u32=a->u32=note2freq(note);
	a->b.u32=tickno*ticksize;
	return 0;
}
Example #4
0
static Song *read_song(FILE *file)
{
    Command command;
    Song *song = malloc(sizeof(Song));
    Chunk *chunk = NULL;
    song->ended = 0;
    song->nb_chunks = 0;
    song->chunks_f = song->chunks_l = NULL;
    if(g_debug)
        fprintf(stderr, "Starting parsing of song file...\n");
    while(read_line(file, &command) != -1)
    {
        switch(command.command)
        {
        case '\0':
            break;
        case 'p':
            {
                if(g_debug)
                    fprintf(stderr, "New chunk (%d channels)\n",
                            command.number.param);
                if(command.number.param < 1)
                    return NULL;
                if(chunk)
                    chunk->pos = 0;
                chunk = new_chunk(song, command.number.param);
            }
            break;
        case 'v':
            {
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* set the volume */
                channel->volume = command.number.param;
            }
            break;
        case 'i':
            {
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* set the instrument */
                channel->instrument = command.number.param;
            }
            break;
        case 'n':
            {
                size_t i;
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* fill it with notes! */
                channel->length = strlen(command.string.param);
                channel->notes = malloc(sizeof(float) * channel->length);
                for(i = 0; i < channel->length; i++)
                    channel->notes[i] = note2freq(command.string.param[i]);
                if(g_debug)
                    fprintf(stderr, "%u notes read into channel %u\n",
                        channel->length, chunk->pos);

                /* to next channel */
                chunk->pos++;
                if(chunk->pos < chunk->nb_channels)
                    chunk->channels[chunk->pos] = new_channel();
            }
            break;
        case 'l':
        case 'j':
            fprintf(stderr, "Warning: '%c' is currently unimplemented\n",
                command.command);
            break;
        }
    }
    if(chunk->pos != chunk->nb_channels)
    {
        fprintf(stderr, "Missing %d channels in chunk\n",
                chunk->nb_channels - chunk->pos);
        return NULL;
    }
    chunk->pos = 0;
    if(g_debug)
        fprintf(stderr, "Song file parsed\n");
    return song;
}
Example #5
0
int main(void) 
{
	scalar_t sample_freq = 44100;
	scalar_t i, j, freq;
	int b;

	osc_t osc[3];
	osc_init(&osc[0], OSC_TYPE_SAWTOOTH);
	osc_init(&osc[1], OSC_TYPE_SAWTOOTH);
	osc_init(&osc[2], OSC_TYPE_SAWTOOTH);

	filter_moog_t f;
	filter_moog_init(&f);

	i = 0.06f;
	j = -0.01f;
		
	b = 0;
// init oscillator state

	for (b=0; b<7; b++) {
		freq = note2freq(A, b);
		fprintf(stderr, "freq=%3.2f, oct=%i\n", freq, b);
		osc[0].freq = freq;
		make_noise(osc, 1, 0.4f, sample_freq, 0.0001, NULL);
	}

	b=0;

	//return 0;

	for (;;) {	
		
		
		if (b++ == 1) {
			b = 0;
			j *= -1;
		}

		osc[0].freq = 109;
		osc[1].freq = 111;
		osc[2].freq = 55;

		i += j;
		filter_moog_set_params(&f, i, 0.6f);

		make_noise(osc, 3, 0.1f, sample_freq, 0.0002, &f);

		osc[0].freq = 219;
		osc[1].freq = 221;
		osc[2].freq = 55;

		i += j;
		filter_moog_set_params(&f, i, 0.6f);

		make_noise(osc, 3, 0.1f, sample_freq, 0.0002, &f);
		
		osc[0].freq = note2freq(Cb, 2) - 1;
		osc[1].freq = note2freq(Cb, 2) + 1;
		osc[2].freq = note2freq(Cb, 1);


		i += j;
		filter_moog_set_params(&f, i, 0.6f);

		make_noise(osc, 3, 0.2f, sample_freq, 0.0001, &f);

		//osc_init(&osc, OSC_TYPE_SAWTOOTH);
		//make_noise(&osc, 2, 2.0f, sample_freq);
		
		//osc_init(&osc, OSC_TYPE_SQUARE);
		//make_noise(&osc, 2, 2.0f, sample_freq);
	}
}