New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cut & Paste Audio #419
Comments
Without reading the whole stackoverflow post, can you state in one sentence what you'd like to see supported in wavesurfer.js? |
Sure. "A function that creates/fills an empty buffer source by creating a copy of the current buffer source that has a specific start and end point." Some of the code is in the stack post. |
This will take a wavesurfer buffer and will create a smaller version with Allan EXTRACTED FROM A PRIVATE PROJECT IF YOU NEED MORE INFO LET ME KNOW: var app = {
trimBlob : function(params){
/*
EXTRACTED FROM A PRIVATE PROJECT
IF YOU NEED MORE INFO LET ME KNOW:
allan.naranjo@gmail.com
---------------------------------------------
This method works with wavesurfer.
Make a selection, using wavesurfer api take the start and end.
---------------------------------------------
The function will take the buffer used to create the waveform and will
create
a new blob with the selected area from the original blob using the
offlineAudioContext
*/
var self = this;
var start = params.start;
var end = params.end;
var originalAudioBuffer;
originalAudioBuffer = params.wavesurfer.backend.buffer;
var lengthInSamples = Math.floor( (end - start) *
originalAudioBuffer.sampleRate );
var offlineAudioContext = new webkitOfflineAudioContext(1, 2,
originalAudioBuffer.sampleRate );
var
new_channel_data,empty_segment_data,original_channel_data,before_data,after_data;
var emptySegment = offlineAudioContext.createBuffer(
originalAudioBuffer.numberOfChannels,lengthInSamples,
originalAudioBuffer.sampleRate );
var newAudioBuffer = offlineAudioContext.createBuffer(
originalAudioBuffer.numberOfChannels,
(start === 0 ? (originalAudioBuffer.length - emptySegment.length) :
originalAudioBuffer.length)
, originalAudioBuffer.sampleRate);
for (var channel = 0; channel < originalAudioBuffer.numberOfChannels;
channel++) {
new_channel_data = newAudioBuffer.getChannelData(channel);
empty_segment_data = emptySegment.getChannelData(channel);
original_channel_data = originalAudioBuffer.getChannelData(channel);
before_data = original_channel_data.subarray(0, start *
originalAudioBuffer.sampleRate);
after_data = original_channel_data.subarray(Math.floor(end *
originalAudioBuffer.sampleRate), (originalAudioBuffer.length *
originalAudioBuffer.sampleRate));
if(start > 0){
new_channel_data.set(before_data);
new_channel_data.set(empty_segment_data,(start *
newAudioBuffer.sampleRate));
new_channel_data.set(after_data,(end * newAudioBuffer.sampleRate));
} else {
new_channel_data.set(after_data);
}
}
var arraybuffer = buffer2wav(newAudioBuffer);//Will create a new Blob with
the IntArray...
return (new Blob([arraybuffer], { type : 'audio/wav'}));
}
} On Thu, Mar 26, 2015 at 5:48 PM, Christopher Konopka <
|
Thanks! I will try it out in a little bit. Really appreciate the help. :) |
@cskonopka closing it now. Feel free to reopen if you have more questions. |
@allannaranjo Sorry about the delay, a bunch of stuff came up and haven't been able to focus on this idea. Is it possible to provide more information? I understand the logic but I can't quite implement it properly. |
@allannaranjo I'm trying to do the same thing as in the original issue and I'm trying to implement your code example however you haven't provided the code for the buffer2wav function. Any chance you could add that code to the example? Many thanks in advance. |
here is some script i found on the web that can replace thr buffer2wav function should be chance to the return value of this function
took me a whole day to get this to work, hope this will save other some time :) |
@moshedri thanks for this function. I'm assuming len is the length of the new buffer? Can you tell me where offset comes from in the context of the previous function? |
you're welcome , it was a long time ago and as i mentioned above the code , i found it online |
I would like to read my .file extension file with wavesurfer.js as .wav, but I could not find a solution. Can you help me please @katspaugh |
1 similar comment
I would like to read my .file extension file with wavesurfer.js as .wav, but I could not find a solution. Can you help me please @katspaugh |
Hi, I have implemented cut, copy, paste in wavesurfer. Please refer to this repo |
How would i implement this in my project? |
@johnlandish Here are the functions Happy to help...!!! |
I saw this post by katspaugh on stack and was curious if there are any examples of this floating around. There is a piece of potential example code I've tried to abstract but haven't had any luck.
http://stackoverflow.com/questions/24551854/cut-and-paste-audio-using-web-audio-api-and-wavesurfer-js
The text was updated successfully, but these errors were encountered: