maxl0rd / standingwave3

Flash ActionScript3 dynamic audio library
http://www.noteflight.com
162 stars 28 forks source link

How to change the frequency using the ResamplingFilter? #20

Open mx2012 opened 12 years ago

mx2012 commented 12 years ago

I'm trying to change the frequency of a Wav file,but the ResamplingFilter doesn't work correctly. I made a simple case for test.I used the StandardizeFilter at first and then I used the ResamplingFilter. I tried and it worked at first,but it stopped soon.

Here's something about the error:

Error: Fill called beyond the bounds of an unresizable CacheFilter at com.noteflight.standingwave3.filters::CacheFilter/fill() at com.noteflight.standingwave3.filters::ResamplingFilter/getSampleRange() at com.noteflight.standingwave3.filters::ResamplingFilter/getSample() at com.noteflight.standingwave3.output::AudioSampleHandler/handleSampleData() at com.noteflight.standingwave3.output::AudioPlayer/handleSampleData()

and this is my code:

import com.noteflight.standingwave3.formats.WaveFile; import flash.events.Event; import flash.net.FileFilter; import flash.net.FileReference; import com.noteflight.standingwave3.output.AudioPlayer; import com.noteflight.standingwave3.filters.StandardizeFilter; import com.noteflight.standingwave3.filters.ResamplingFilter;

var file:FileReference; var player:AudioPlayer; function init() { file=new FileReference(); file.addEventListener(Event.COMPLETE,complete); file.addEventListener(Event.SELECT,select); file.browse(); } function select(e:Event):void { file.load(); } function complete(e:Event):void { player=new AudioPlayer(); var fil:StandardizeFilter = new StandardizeFilter(WaveFile.createSample(file.data)); var rfil:ResamplingFilter= new ResamplingFilter(fil,1.01); player.play(rfil); } init();

maxl0rd commented 12 years ago

This should work if you go

Sample -> ResamplingFilter -> StandardizeFilter

ResamplingFilter only works against a RandomAccessAudioSource, and so it is inserting a CacheFilter in there. Just swap the order and it should work.

StandardizeFilter is generally the absolute last item in the chain, and is only needed if the signal chain is not stereo/44.1k.

mx2012 commented 12 years ago

Thanks!

jbaudanza commented 12 years ago

@mx2012 Might want to checkout https://github.com/maxl0rd/standingwave3/pull/25 It looks like there was some problems with the ResamplingFilter for stereo samples.