Skip to content

Commit

Permalink
trying out blobs with chrome after using them in my screen capture ex…
Browse files Browse the repository at this point in the history
…tension -- stil crashes sometimes during piano contstruction though... -- http://updates.html5rocks.com/2012/06/Don-t-Build-Blobs-Construct-Them
  • Loading branch information
mrcoles committed Aug 8, 2012
1 parent 0c787c0 commit 049fdfa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
23 changes: 22 additions & 1 deletion audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ window.log = function f(){ log.history = log.history || []; log.history.push(arg

(function() {

// test if we can use blobs
var canBlob = false;
if ((window.URL || window.webkitURL) && window.Blob) {
try {
new Blob();
canBlob = true;
} catch(e) {}
}

function asBytes(value, bytes) {
// Convert value into little endian hex bytes
// value - the number as a decimal integer (representing bytes)
Expand Down Expand Up @@ -159,7 +168,19 @@ window.log = function f(){ log.history = log.history || []; log.history.push(arg
dataChunk
].join('');

return 'data:audio/wav;base64,' + btoa(data);
if (canBlob) {
// so chrome was blowing up, because it just blows up sometimes
// if you make dataURIs that are too large, but it lets you make
// really large blobs...
var view = new Uint8Array(data.length);
for (var i = 0; i < view.length; i++) {
view[i] = data.charCodeAt(i);
}
var blob = new Blob([view], {type: 'audio/wav'});
return (window.URL || window.webkitURL).createObjectURL(blob);
} else {
return 'data:audio/wav;base64,' + btoa(data);
}
}

function noteToFreq(stepsFromMiddleC) {
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ <h2>HTML5 Javascript Piano</h2>
– May 16, 2012
</p>
</div>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://mrcoles.com/piano/" data-text="HTML5 Piano - with a data URI synth" data-via="lethys">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<script src="jquery-1.7.1.min.js"></script>
<script src="audio.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions piano.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ h1 {
cursor: pointer;
}

.twitter-share-button {
position: absolute;
top: 0;
right: 0;
}

#top:hover {
color: red;
}
Expand Down
2 changes: 1 addition & 1 deletion piano.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

// delayed for-loop to stop browser from crashing :'(
// go slower on Chrome...
var i = -12, max = 14, addDelay = /Chrome/i.test(navigator.userAgent) ? 100 : 50;
var i = -12, max = 14, addDelay = /Chrome/i.test(navigator.userAgent) ? 80 : 0;
(function go() {
addKey(i + notesOffset);
if (++i < max) {
Expand Down

0 comments on commit 049fdfa

Please sign in to comment.