tone 15.2.9 → 15.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,11 +74,13 @@ describe("Context", () => {
74
74
  latencyHint: "playback",
75
75
  lookAhead: 0.2,
76
76
  updateInterval: 0.1,
77
+ sampleRate: 32000,
77
78
  });
78
79
  expect(ctx.lookAhead).to.equal(0.2);
79
80
  expect(ctx.updateInterval).to.equal(0.1);
80
81
  expect(ctx.latencyHint).to.equal("playback");
81
82
  expect(ctx.clockSource).to.equal("timeout");
83
+ expect(ctx.sampleRate).to.equal(32000);
82
84
  ctx.dispose();
83
85
  return ctx.close();
84
86
  });
@@ -23,6 +23,7 @@ export interface ContextOptions {
23
23
  lookAhead: Seconds;
24
24
  updateInterval: Seconds;
25
25
  context: AnyAudioContext;
26
+ sampleRate: number;
26
27
  }
27
28
 
28
29
  export interface ContextTimeoutEvent {
@@ -116,7 +117,10 @@ export class Context extends BaseContext {
116
117
  // custom context provided, latencyHint unknown (unless explicitly provided in options)
117
118
  this._latencyHint = arguments[0]?.latencyHint || "";
118
119
  } else {
119
- this._context = createAudioContext({
120
+ this._context = createAudioContext(options.sampleRate ? {
121
+ latencyHint: options.latencyHint,
122
+ sampleRate: options.sampleRate,
123
+ } : {
120
124
  latencyHint: options.latencyHint,
121
125
  });
122
126
  this._latencyHint = options.latencyHint;
@@ -52,13 +52,43 @@ describe("MembraneSynth", () => {
52
52
 
53
53
  it("can get and set the octaves and pitch decay", () => {
54
54
  const drumSynth = new MembraneSynth();
55
- drumSynth.octaves = 12;
55
+ drumSynth.octaves = 8;
56
56
  drumSynth.pitchDecay = 0.2;
57
57
  expect(drumSynth.pitchDecay).to.equal(0.2);
58
- expect(drumSynth.octaves).to.equal(12);
58
+ expect(drumSynth.octaves).to.equal(8);
59
59
  drumSynth.dispose();
60
60
  });
61
61
 
62
+ it("validates octaves range", () => {
63
+ const drumSynth = new MembraneSynth();
64
+ // Test minimum boundary
65
+ drumSynth.octaves = 0.5;
66
+ expect(drumSynth.octaves).to.equal(0.5);
67
+ // Test maximum boundary
68
+ drumSynth.octaves = 8;
69
+ expect(drumSynth.octaves).to.equal(8);
70
+ drumSynth.dispose();
71
+ });
72
+
73
+ it("validates pitchDecay range", () => {
74
+ const drumSynth = new MembraneSynth();
75
+ drumSynth.pitchDecay = 0;
76
+ expect(drumSynth.pitchDecay).to.equal(0);
77
+ drumSynth.pitchDecay = 0.5;
78
+ expect(drumSynth.pitchDecay).to.equal(0.5);
79
+ drumSynth.dispose();
80
+ });
81
+
82
+ it("Finds correct maximum note frequency", () => {
83
+ const drumSynth = new MembraneSynth();
84
+ const hertz = 65.4; // C2
85
+ drumSynth.octaves = 8;
86
+ const maxNote = hertz * Math.pow(2, drumSynth.octaves);
87
+ expect(maxNote).to.equal(16742.4); // C2 + 8 octaves
88
+ drumSynth.dispose();
89
+ });
90
+
91
+
62
92
  it("can be constructed with an options object", () => {
63
93
  const drumSynth = new MembraneSynth({
64
94
  envelope: {
@@ -32,7 +32,7 @@ export class MembraneSynth extends Synth<MembraneSynthOptions> {
32
32
  * @min 0.5
33
33
  * @max 8
34
34
  */
35
- @range(0)
35
+ @range(0.5, 8)
36
36
  octaves: Positive;
37
37
 
38
38
  /**
@@ -40,7 +40,7 @@ export class MembraneSynth extends Synth<MembraneSynthOptions> {
40
40
  * @min 0
41
41
  * @max 0.5
42
42
  */
43
- @timeRange(0)
43
+ @timeRange(0, 0.5)
44
44
  pitchDecay: Time;
45
45
 
46
46
  /**
@@ -73,7 +73,7 @@ export class MembraneSynth extends Synth<MembraneSynthOptions> {
73
73
  release: 1.4,
74
74
  sustain: 0.01,
75
75
  },
76
- octaves: 10,
76
+ octaves: 8,
77
77
  oscillator: {
78
78
  type: "sine",
79
79
  },
@@ -86,7 +86,7 @@ export class MembraneSynth extends Synth<MembraneSynthOptions> {
86
86
  const hertz = this.toFrequency(
87
87
  note instanceof FrequencyClass ? note.toFrequency() : note
88
88
  );
89
- const maxNote = hertz * this.octaves;
89
+ const maxNote = hertz * Math.pow(2, this.octaves);
90
90
  this.oscillator.frequency.setValueAtTime(maxNote, seconds);
91
91
  this.oscillator.frequency.exponentialRampToValueAtTime(
92
92
  hertz,
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.2.9";
1
+ export const version: string = "15.2.11";