From 4d103a16413f580703579f492335c44af3a956d6 Mon Sep 17 00:00:00 2001 From: angel Date: Tue, 31 May 2005 05:43:36 +0000 Subject: [PATCH] The function ss_ins_note_on_by_freq() has been substituted by another, ss_ins_play(), where a specific wave is given to be played. This fixes the pitch_stretch out-of-bounds issue (Closes: #1064). git-svn-id: file:///home/angel/tmp/svn-triptico/ahxm/trunk@623 c87de0a0-a11c-0410-a1e5-866214bc28b2 --- TODO | 6 ++--- examples/example2.ahs | 2 +- ss_ins.c | 66 +++++++++++++++++++++++++++------------------------ ss_ins.h | 3 ++- ss_song.c | 3 +-- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/TODO b/TODO index f705652..35093b6 100644 --- a/TODO +++ b/TODO @@ -18,9 +18,6 @@ Release Critical Bugs * 1063: Now that I've tested it with good hardware, the new ss_outdev driver is useless as is due to horrible latency. So, it must be rewritten to do direct writing to devices. - * 1064: Document or fix the 'feature' of pitch_stretch that, if the chosen - wave can't handle the final frequency (due to min/max boundaries), it can - end up not sounding at all. * 1065: Create a document about the extended commands. Open Bugs @@ -160,5 +157,8 @@ Closed writing to ports (Closed by #1063; Mon, 30 May 2005 18:14:44 +0200). * 1059: Add channel maps to language (Mon, 30 May 2005 18:50:38 +0200). * 1040: Get rid of all _ prefixed symbols (Mon, 30 May 2005 19:12:19 +0200). + * 1064: Document or fix the 'feature' of pitch_stretch that, if the chosen + wave can't handle the final frequency (due to min/max boundaries), it can + end up not sounding at all (Tue, 31 May 2005 07:41:50 +0200). Email bugs to angel@triptico.com diff --git a/examples/example2.ahs b/examples/example2.ahs index 4d49aca..d01558b 100644 --- a/examples/example2.ahs +++ b/examples/example2.ahs @@ -42,6 +42,6 @@ $bass1 \ /* percussion track */ -{ wav "samples/amen1.wav" c1 c0 c2 } +{ wav "samples/amen1.wav" c1 } r1 ({ pitch_stretch c1 1 0.8 })*7 diff --git a/ss_ins.c b/ss_ins.c index e2eac29..6649031 100644 --- a/ss_ins.c +++ b/ss_ins.c @@ -171,47 +171,35 @@ void ss_ins_set_sustain(struct ss_ins * i, double sustain) /** - * ss_ins_note_on_by_freq - Plays a note by its desired frequency + * ss_ins_play - Plays a note given the desired wave. * @i: the instrument - * @freq: the frequency - * @vol: note volume + * @w: the wave + * @freq: frequency + * @vol: volume * @note_id: note id * - * Locates a layer to play a note, and starts generators to - * play it. The @note is expressed as a MIDI note and the - * desired volume (from 0 to 1) stored in @vol. The note @id - * should be a positive, unique identifier for this note; no two - * simultaneously playing notes should share this id. + * Orders the instrument to start playing a note, given a specific wave. + * The wave is usually one of the instrument's layers, but it doesn't + * have to. * - * Returns the number of generators that were activated. + * Returns zero if there were no free generators, or non-zero otherwise. */ -int ss_ins_note_on_by_freq(struct ss_ins * i, double freq, float vol, int note_id) +int ss_ins_play(struct ss_ins * i, struct ss_wave * w, double freq, + float vol, int note_id) { - int n=0; - struct ss_wave * w; - int notes=0; struct ss_gen * g; - while((w=ss_ins_find_layer(i, freq, &n)) != NULL) - { - /* get a free generator, or fail */ - if((g=ss_gen_alloc(&i->gens)) == NULL) - break; + /* get a free generator, or fail */ + if((g=ss_gen_alloc(&i->gens)) == NULL) + return(0); - /* start the generator */ - ss_gen_play(g, freq, vol, note_id, w); + /* start the generator */ + ss_gen_play(g, freq, vol, note_id, w); - /* set sustain */ - ss_gen_sustain(g, i->sustain); -#if 0 - /* TEST: portamento */ - if(i->trk_id == 2) - g->portamento=-0.000001; -#endif - notes++; - } + /* set sustain */ + ss_gen_sustain(g, i->sustain); - return(notes); + return(1); } @@ -232,7 +220,23 @@ int ss_ins_note_on_by_freq(struct ss_ins * i, double freq, float vol, int note_i */ int ss_ins_note_on(struct ss_ins * i, int note, float vol, int note_id) { - return(ss_ins_note_on_by_freq(i, ss_note_frequency(note), vol, note_id)); + int n=0; + struct ss_wave * w; + int notes=0; + struct ss_gen * g; + double freq; + + freq=ss_note_frequency(note); + + while((w=ss_ins_find_layer(i, freq, &n)) != NULL) + { + if(!ss_ins_play(i, w, freq, vol, note_id)) + break; + + notes++; + } + + return(notes); } diff --git a/ss_ins.h b/ss_ins.h index 6b486a4..9274bfd 100644 --- a/ss_ins.h +++ b/ss_ins.h @@ -41,7 +41,8 @@ void ss_ins_add_layer(struct ss_ins * i, struct ss_wave * w); struct ss_wave * ss_ins_find_layer(struct ss_ins * i, double freq, int * off); void ss_ins_set_channel(struct ss_ins * i, int channel, float vol); void ss_ins_set_sustain(struct ss_ins * i, double sustain); -int ss_ins_note_on_by_freq(struct ss_ins * i, double freq, float vol, int note_id); +int ss_ins_play(struct ss_ins * i, struct ss_wave * w, double freq, + float vol, int note_id); int ss_ins_note_on(struct ss_ins * i, int note, float vol, int note_id); void ss_ins_note_off(struct ss_ins * i, int note_id); void ss_ins_frame(struct ss_ins * i, float frame[]); diff --git a/ss_song.c b/ss_song.c index 128d619..7241d5b 100644 --- a/ss_song.c +++ b/ss_song.c @@ -566,8 +566,7 @@ int ss_song_render(void) freq=ss_pitch_from_tempo(w, tempo, e->ss_pitch_stretch.len); /* play the note */ - ss_ins_note_on_by_freq(i, freq, - e->ss_pitch_stretch.vol, + ss_ins_play(i, w, freq, e->ss_pitch_stretch.vol, e->ss_pitch_stretch.note_id); } -- 2.11.4.GIT