maxl0rd / standingwave3

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

Method readBytes #27

Closed georgiee closed 11 years ago

georgiee commented 11 years ago

I read that standingwave3 was developed before we were able to access the microphone bytes. That was a problem for me so I fixed it- which was easy as the microphone returns plain sample data just like a WAVE/RIFF file which is already included in the current SW3 source.

As the class Sample is final I had to directly modify the source to be able to read in samples collected from a microphone. Now there is no need to convert you mic samples first to a WAV format anymore. Here a scenario which is possible now:

var BYTES_PER_SAMPLE:int= 4;
var CHANNELS:int = 2

/*
Get all samples collected from the microphone. Here a sample recorder class created by me.
IMPORTANT: ByteArray have to be set to flash.utils.Endian.LITTLE_ENDIAN;
*/
var bytes:ByteArray = _microphoneRecorder.getCircularBufferContent();

var sample:Sample=new Sample(new AudioDescriptor,bytes.length/(BYTES_PER_SAMPLE*CHANNELS));

// This is change, we are now able to read raw microphone
sample.readBytes(bytes); 

//Yeah, now play the mic input with all the cool magic you can do with Standingwave3
_audioPlayer.play(sample) 
maxl0rd commented 11 years ago

Good deal. Thanks for the pull request.

kenvunz commented 10 years ago

hi @georgiee,

are you able posting the source code of your MicrophoneRecorder class?

I'm having trouble to get my own implementation to play nice with AudioPlayer

cheers

georgiee commented 10 years ago

Hi kenvunz, I used my fork of standwingwave to provide you with all classes related to recording. You have to use standwingwave master which includes my pull request. I also included as3 signals in folder /lib. AS3 Signals is used in some classes.

Here you can find my recorder https://github.com/georgiee/standingwave3/tree/master/recording

record/AbstractMicrophoneRecorder is the core to record record/StandardMicrophoneRecorder is the concrete implementation record/VoiceRecorder is using StandardMicrophoneRecorder

all other classes are related to record/EndlessMicrophoneRecorder. This class incorporates a circular buffer which is used to override earlier samples recorded. So you can create a recorder for 5 seconds and record as long as you want. when you stop you get the latest 5 seconds. It's working but was done quick and dirty.

And forgive me for using TweenMax in AbstractRecorder :) I think you can safely remove all occurrences as this dirty dirty delay mechanism is only used in TalkBackRecorder.

I hope this will help you.

kenvunz commented 10 years ago

@georgiee yes it does help and yes you are forgiven :)

thanks heaps