Skip to content

Commit

Permalink
fix: pitch/speed issue on devices with different sample rates
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Robinson <git@tomr.me>
  • Loading branch information
davwheat and t5r7 committed Nov 3, 2023
1 parent 0d14b93 commit 20e59a5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/crunker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Crunker {
* for the device being used.
*/
constructor({ sampleRate }: Partial<CrunkerConstructorOptions> = {}) {
this._context = this._createContext();
this._context = this._createContext(sampleRate);

sampleRate ||= this._context.sampleRate;

Expand All @@ -44,9 +44,9 @@ export default class Crunker {
*
* @internal
*/
private _createContext(): AudioContext {
private _createContext(sampleRate: number = 44_100): AudioContext {
window.AudioContext = window.AudioContext || (window as any).webkitAudioContext || (window as any).mozAudioContext;
return new AudioContext();
return new AudioContext({sampleRate});
}

/**
Expand Down

0 comments on commit 20e59a5

Please sign in to comment.