@@ -171,6 +171,7 @@ export interface IMeasure {
171
171
offset ?: number ;
172
172
type ?: OscillatorOptions [ 'type' ] ;
173
173
volume ?: number ;
174
+ loudness ?: number [ ] ;
174
175
}
175
176
176
177
export interface INote {
@@ -219,18 +220,21 @@ export default class Xylophone {
219
220
220
221
return ;
221
222
}
222
- let i = 0 ;
223
223
await Promise . all (
224
- measure . notes . map ( ( note ) => {
224
+ measure . notes . map ( ( note , i ) => {
225
225
let offset = delay ;
226
- if ( measure . offset ) offset += measure . offset * i ++ ;
226
+ if ( measure . offset ) offset += measure . offset * i ;
227
+ let volume = measure . volume ;
228
+ if ( volume && measure . loudness ) {
229
+ volume *= measure . loudness [ i ] ;
230
+ }
227
231
228
232
return this . playTone ( {
229
233
length : measure . length ,
230
234
note,
231
235
offset,
232
236
type : measure . type ,
233
- volume : measure . volume ,
237
+ volume,
234
238
} ) ;
235
239
} )
236
240
) ;
@@ -302,7 +306,16 @@ export default class Xylophone {
302
306
) ;
303
307
const gain = Math . min ( 1 , Math . pow ( volume ?? 1 , Math . E ) * freqGain ) * 0.5 ;
304
308
305
- this . oscillator . frequency . value = Xylophone . toHertz ( note ) ;
309
+ // this.oscillator.frequency.value = Xylophone.toHertz(note);
310
+ this . oscillator . frequency . setValueAtTime ( 0.5 * Xylophone . toHertz ( note ) , offset ) ;
311
+ this . oscillator . frequency . linearRampToValueAtTime (
312
+ 1 * Xylophone . toHertz ( note ) ,
313
+ offset + 0.05
314
+ ) ;
315
+ this . oscillator . frequency . exponentialRampToValueAtTime (
316
+ Xylophone . toHertz ( note ) + 5 ,
317
+ offset + length
318
+ ) ;
306
319
this . gainNode . gain . setValueAtTime ( 0 , offset ) ;
307
320
this . gainNode . gain . linearRampToValueAtTime ( 1 * gain , offset + 0.02 ) ;
308
321
0 commit comments