@@ -14,9 +14,9 @@ import processorNames from './audioWorklet/processorNames';
14
14
* @method sampleRate
15
15
* @return {Number } samplerate samples per second
16
16
*/
17
- p5 . prototype . sampleRate = function ( ) {
17
+ function sampleRate ( ) {
18
18
return p5sound . audiocontext . sampleRate ;
19
- } ;
19
+ }
20
20
21
21
/**
22
22
* Returns the closest MIDI note value for
@@ -27,11 +27,11 @@ p5.prototype.sampleRate = function () {
27
27
* above Middle C is 440Hz
28
28
* @return {Number } MIDI note value
29
29
*/
30
- export const freqToMidi = function ( f ) {
30
+ function freqToMidi ( f ) {
31
31
var mathlog2 = Math . log ( f / 440 ) / Math . log ( 2 ) ;
32
32
var m = Math . round ( 12 * mathlog2 ) + 69 ;
33
33
return m ;
34
- } ;
34
+ }
35
35
36
36
/**
37
37
* Returns the frequency value of a MIDI note value.
@@ -77,12 +77,12 @@ export const freqToMidi = function (f) {
77
77
* }
78
78
* </code></div>
79
79
*/
80
- export var midiToFreq = ( p5 . prototype . midiToFreq = function ( m ) {
80
+ function midiToFreq ( m ) {
81
81
return 440 * Math . pow ( 2 , ( m - 69 ) / 12.0 ) ;
82
- } ) ;
82
+ }
83
83
84
84
// This method converts ANSI notes specified as a string "C4", "Eb3" to a frequency
85
- export var noteToFreq = function ( note ) {
85
+ function noteToFreq ( note ) {
86
86
if ( typeof note !== 'string' ) {
87
87
return note ;
88
88
}
@@ -102,7 +102,7 @@ export var noteToFreq = function (note) {
102
102
break ;
103
103
}
104
104
return midiToFreq ( value ) ;
105
- } ;
105
+ }
106
106
107
107
/**
108
108
* List the SoundFile formats that you will include. LoadSound
@@ -133,7 +133,8 @@ export var noteToFreq = function (note) {
133
133
* }
134
134
* </code></div>
135
135
*/
136
- p5 . prototype . soundFormats = function ( ) {
136
+
137
+ function soundFormats ( ) {
137
138
// reset extensions array
138
139
p5sound . extensions = [ ] ;
139
140
// add extensions
@@ -145,19 +146,15 @@ p5.prototype.soundFormats = function () {
145
146
throw arguments [ i ] + ' is not a valid sound format!' ;
146
147
}
147
148
}
148
- } ;
149
+ }
149
150
150
- p5 . prototype . disposeSound = function ( ) {
151
+ function disposeSound ( ) {
151
152
for ( var i = 0 ; i < p5sound . soundArray . length ; i ++ ) {
152
153
p5sound . soundArray [ i ] . dispose ( ) ;
153
154
}
154
- } ;
155
-
156
- // register removeSound to dispose of p5sound SoundFiles, Convolvers,
157
- // Oscillators etc when sketch ends
158
- p5 . prototype . registerMethod ( 'remove' , p5 . prototype . disposeSound ) ;
155
+ }
159
156
160
- p5 . prototype . _checkFileFormats = function ( paths ) {
157
+ function _checkFileFormats ( paths ) {
161
158
var path ;
162
159
// if path is a single string, check to see if extension is provided
163
160
if ( typeof paths === 'string' ) {
@@ -215,12 +212,12 @@ p5.prototype._checkFileFormats = function (paths) {
215
212
}
216
213
}
217
214
return path ;
218
- } ;
215
+ }
219
216
220
217
/**
221
218
* Used by Osc and Envelope to chain signal math
222
219
*/
223
- p5 . prototype . _mathChain = function ( o , math , thisChain , nextChain , type ) {
220
+ function _mathChain ( o , math , thisChain , nextChain , type ) {
224
221
// if this type of math already exists in the chain, replace it
225
222
for ( var i in o . mathOps ) {
226
223
if ( o . mathOps [ i ] instanceof type ) {
@@ -236,13 +233,13 @@ p5.prototype._mathChain = function (o, math, thisChain, nextChain, type) {
236
233
math . connect ( nextChain ) ;
237
234
o . mathOps [ thisChain ] = math ;
238
235
return o ;
239
- } ;
236
+ }
240
237
241
238
// helper methods to convert audio file as .wav format,
242
239
// will use as saving .wav file and saving blob object
243
240
// Thank you to Matt Diamond's RecorderJS (MIT License)
244
241
// https://github.com/mattdiamond/Recorderjs
245
- export function convertToWav ( audioBuffer ) {
242
+ function convertToWav ( audioBuffer ) {
246
243
var leftChannel , rightChannel ;
247
244
leftChannel = audioBuffer . getChannelData ( 0 ) ;
248
245
@@ -314,7 +311,7 @@ function writeUTFBytes(view, offset, string) {
314
311
}
315
312
}
316
313
317
- export function safeBufferSize ( idealBufferSize ) {
314
+ function safeBufferSize ( idealBufferSize ) {
318
315
let bufferSize = idealBufferSize ;
319
316
320
317
// if the AudioWorkletNode is actually a ScriptProcessorNode created via polyfill,
@@ -334,6 +331,7 @@ export function safeBufferSize(idealBufferSize) {
334
331
return bufferSize ;
335
332
}
336
333
334
+
337
335
/**
338
336
* Save a p5.SoundFile as a .wav file. The browser will prompt the user
339
337
* to download the file to their device.
@@ -351,9 +349,19 @@ export function saveSound(soundFile, fileName) {
351
349
p5 . prototype . writeFile ( [ dataView ] , fileName , 'wav' ) ;
352
350
}
353
351
354
- // export default {
355
- // // convertToWav: convertToWav,
356
- // // midiToFreq: midiToFreq,
357
- // // noteToFreq: noteToFreq,
358
- // // safeBufferSize: safeBufferSize
359
- // };
352
+
353
+ export {
354
+ sampleRate ,
355
+ freqToMidi ,
356
+ midiToFreq ,
357
+ noteToFreq ,
358
+ soundFormats ,
359
+ disposeSound ,
360
+ _checkFileFormats ,
361
+ _mathChain ,
362
+ convertToWav ,
363
+ interleave ,
364
+ writeUTFBytes ,
365
+ safeBufferSize ,
366
+ saveSound
367
+ } ;
0 commit comments