I'm trying to use an audio buffer composed of Float32Array
s (1 for each channel) as asset data to create a soundcloud track.
The audio buffer for a mono recording looks like this:
[Float32Array { 0=-0.0001220703125, 1=0.000579833984375, 2=0.000762939453125, ...}]
So I assume that I should convert it to a binary string. To know the correct encoding, I took a look at http://connect.soundcloud.com/examples/recording.html It's flash but at the end the following post is done:
audio.wav
--ievejmnijdgyooinchslwnpygpivapif
Content-Disposition: form-data; name="track[asset_data]"; filename="audio.wav"
Content-Type: application/octet-stream
RIFF(WAVEfmt D¬XdataÚÿÇÿÿ+ÿc]ÿ1&»ÿUÿ(1ÊÿEc&môã...
In order to turn my audio buffer into such, I used code similar to https://gist.github.com/kevincennis/9754325 so that now my process looks like:
worker.onmessage = function( e ) {
var blob = e.data;
var reader = new window.FileReader();
reader.onloadend = function() {
var binaryData = reader.result;
SC.post('/tracks', {
asset_data : binaryData,
title : 'recording'
});
};
reader.readAsText(blob);
});
Still, there should be some problem with the encoding. The above, produces the following post:
_status_code_map[302] 200
asset_data RIFF ���WAVEfmt �����D�������data����
format json
oauth_token 1....
title recording
but the response of Soundclound API is still: "NetworkError: 422 Unprocessable Entity - https://api.soundcloud.com/tracks"
Can anybody spot what's wrong?