Skip to content

Commit 261ed0c

Browse files
committed
add soundfile.save example
1 parent dd0779e commit 261ed0c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/soundfile.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,14 +1643,31 @@ define(function (require) {
16431643

16441644
/**
16451645
* Save a p5.SoundFile as a .wav file. The browser will prompt the user
1646-
* to download the file to their device.
1646+
* to download the file to their device. To upload a file to a server, see
1647+
* <a href="/docs/reference/#/p5.SoundFile/getBlob">getBlob</a>
16471648
*
16481649
* @method save
16491650
* @param {String} [fileName] name of the resulting .wav file.
1651+
* @example
1652+
* <div><code>
1653+
* var inp, button, mySound;
1654+
* var fileName = 'cool';
1655+
* function setup() {
1656+
* mySound = loadSound('assets/doorbell.mp3');
1657+
*
1658+
* btn = createButton('click to save file');
1659+
* btn.position(0, 0);
1660+
* btn.mouseClicked(handleMouseClick);
1661+
* }
1662+
*
1663+
* function handleMouseClick() {
1664+
* mySound.save(fileName);
1665+
* }
1666+
* </code></div>
16501667
*/
16511668
p5.SoundFile.prototype.save = function(fileName) {
16521669
const dataView = convertToWav(this.buffer);
1653-
p5.prototype.writeFile([dataView], fileName, 'wav');
1670+
p5.prototype.saveSound([dataView], fileName, 'wav');
16541671
};
16551672

16561673
/**

0 commit comments

Comments
 (0)