From 261ed0c464dd6e1c675a43f637522d1129ad61b7 Mon Sep 17 00:00:00 2001 From: therewasaguy Date: Sat, 8 Sep 2018 14:48:51 -0400 Subject: [PATCH] add soundfile.save example --- src/soundfile.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/soundfile.js b/src/soundfile.js index d77f17f4..b8c7faec 100644 --- a/src/soundfile.js +++ b/src/soundfile.js @@ -1643,14 +1643,31 @@ define(function (require) { /** * Save a p5.SoundFile as a .wav file. The browser will prompt the user - * to download the file to their device. + * to download the file to their device. To upload a file to a server, see + * getBlob * * @method save * @param {String} [fileName] name of the resulting .wav file. + * @example + *
+ * var inp, button, mySound; + * var fileName = 'cool'; + * function setup() { + * mySound = loadSound('assets/doorbell.mp3'); + * + * btn = createButton('click to save file'); + * btn.position(0, 0); + * btn.mouseClicked(handleMouseClick); + * } + * + * function handleMouseClick() { + * mySound.save(fileName); + * } + *
*/ p5.SoundFile.prototype.save = function(fileName) { const dataView = convertToWav(this.buffer); - p5.prototype.writeFile([dataView], fileName, 'wav'); + p5.prototype.saveSound([dataView], fileName, 'wav'); }; /**