├── .DS_Store ├── README ├── flash-fla ├── .DS_Store ├── AudioRecorderCS4-1.0.fla ├── AudioRecorderCS4.fla ├── AudioRecorderCS4.swf ├── Main.as └── org │ ├── .DS_Store │ ├── .svn │ ├── all-wcprops │ └── entries │ ├── as3wavsound │ ├── WavSound.as │ ├── WavSoundChannel.as │ ├── WavSoundPlayer.as │ └── sazameki │ │ ├── core │ │ ├── AudioSamples.as │ │ └── AudioSetting.as │ │ └── format │ │ ├── riff │ │ ├── Chunk.as │ │ ├── LIST.as │ │ └── RIFF.as │ │ └── wav │ │ ├── Wav.as │ │ └── chunk │ │ ├── WavdataChunk.as │ │ └── WavfmtChunk.as │ └── bytearray │ ├── .DS_Store │ ├── .svn │ ├── all-wcprops │ └── entries │ └── micrecorder │ ├── .DS_Store │ ├── .svn │ ├── all-wcprops │ ├── entries │ └── text-base │ │ ├── IEncoder.as.svn-base │ │ └── MicRecorder.as.svn-base │ ├── IEncoder.as │ ├── MicRecorder.as │ ├── encoder │ ├── .svn │ │ ├── all-wcprops │ │ ├── entries │ │ └── text-base │ │ │ └── WaveEncoder.as.svn-base │ └── WaveEncoder.as │ └── events │ ├── .svn │ ├── all-wcprops │ ├── entries │ └── text-base │ │ └── RecordingEvent.as.svn-base │ └── RecordingEvent.as ├── html ├── .DS_Store ├── acceptfile.php ├── example1.html ├── example2.html ├── jRecorder.js ├── jRecorder.swf └── jquery.min.js └── javascript ├── .DS_Store ├── jRecorder-1.0.js ├── jRecorder-1.1.js ├── jRecorder.js └── jquery.min.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/.DS_Store -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Author: Sajith Amma 2 | Description: jRecorder is a jQuery plugin to enable a flash recorder in your webpages. You DON'T need to have a flash streaming server or RED5 server to do this recording. 3 | 4 | Project Documentation: http://www.sajithmr.me/jrecorder/ 5 | 6 | Example Implementation: http://www.sajithmr.me/jrecorder/example1.html 7 | 8 | Author Domain: www.sajithmr.me -------------------------------------------------------------------------------- /flash-fla/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/.DS_Store -------------------------------------------------------------------------------- /flash-fla/AudioRecorderCS4-1.0.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/AudioRecorderCS4-1.0.fla -------------------------------------------------------------------------------- /flash-fla/AudioRecorderCS4.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/AudioRecorderCS4.fla -------------------------------------------------------------------------------- /flash-fla/AudioRecorderCS4.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/AudioRecorderCS4.swf -------------------------------------------------------------------------------- /flash-fla/Main.as: -------------------------------------------------------------------------------- 1 | package { import flash.display.Sprite; import flash.media.Microphone; import flash.system.Security; import org.bytearray.micrecorder.*; import org.bytearray.micrecorder.events.RecordingEvent; import org.bytearray.micrecorder.encoder.WaveEncoder; import flash.events.MouseEvent; import flash.events.Event; import flash.events.ActivityEvent; import fl.transitions.Tween; import fl.transitions.easing.Strong; import flash.net.FileReference; import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLRequestMethod; import flash.display.LoaderInfo; import flash.external.ExternalInterface; import flash.media.Sound; import org.as3wavsound.WavSound; import org.as3wavsound.WavSoundChannel; public class Main extends Sprite { private var mic:Microphone; private var waveEncoder:WaveEncoder = new WaveEncoder(); private var recorder:MicRecorder = new MicRecorder(waveEncoder); private var recBar:RecBar = new RecBar(); private var maxTime:Number = 30; private var tween:Tween; private var fileReference:FileReference = new FileReference(); private var tts:WavSound; public function Main():void { trace('recoding'); recButton.visible = false; activity.visible = false ; godText.visible = false; recBar.visible = false; mic = Microphone.getMicrophone(); mic.setSilenceLevel(5); mic.gain = 50; mic.setLoopBack(false); mic.setUseEchoSuppression(true); Security.showSettings("2"); addListeners(); } private function addListeners():void { recorder.addEventListener(RecordingEvent.RECORDING, recording); recorder.addEventListener(Event.COMPLETE, recordComplete); activity.addEventListener(Event.ENTER_FRAME, updateMeter); //accept call from javascript to start recording ExternalInterface.addCallback("jStartRecording", jStartRecording); ExternalInterface.addCallback("jStopRecording", jStopRecording); ExternalInterface.addCallback("jSendFileToServer", jSendFileToServer); } //external java script function call to start record public function jStartRecording(max_time):void { maxTime = max_time; if (mic != null) { recorder.record(); ExternalInterface.call("$.jRecorder.callback_started_recording"); } else { ExternalInterface.call("$.jRecorder.callback_error_recording", 0); } } //external javascript function to trigger stop recording public function jStopRecording():void { recorder.stop(); mic.setLoopBack(false); ExternalInterface.call("$.jRecorder.callback_stopped_recording"); //finalize_recording(); } public function jSendFileToServer():void { finalize_recording(); } public function jStopPreview():void { //no function is currently available; } private function updateMeter(e:Event):void { ExternalInterface.call("$.jRecorder.callback_activityLevel", mic.activityLevel); } private function recording(e:RecordingEvent):void { var currentTime:int = Math.floor(e.time / 1000); ExternalInterface.call("$.jRecorder.callback_activityTime", String(currentTime) ); if(currentTime == maxTime ) { jStopRecording(); } } private function recordComplete(e:Event):void { //fileReference.save(recorder.output, "recording.wav"); //finalize_recording(); preview_recording(); } private function preview_recording():void { tts = new WavSound(recorder.output); tts.play(); ExternalInterface.call("$.jRecorder.callback_started_preview"); } //functioon send data to server private function finalize_recording():void { var _var1:String= ''; var globalParam = LoaderInfo(this.root.loaderInfo).parameters; for (var element:String in globalParam) { if (element == 'host'){ _var1 = globalParam[element]; } } ExternalInterface.call("$.jRecorder.callback_finished_recording"); if(_var1 != '') { var req:URLRequest = new URLRequest(_var1); req.contentType = 'application/octet-stream'; req.method = URLRequestMethod.POST; req.data = recorder.output; var loader:URLLoader = new URLLoader(req); ExternalInterface.call("$.jRecorder.callback_finished_sending"); } } private function getFlashVars():Object { return Object( LoaderInfo( this.loaderInfo ).parameters ); } } } -------------------------------------------------------------------------------- /flash-fla/org/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/org/.DS_Store -------------------------------------------------------------------------------- /flash-fla/org/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 59 4 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org 5 | END 6 | -------------------------------------------------------------------------------- /flash-fla/org/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 20727 5 | http://sajith@10.2.30.40/muzicall/ringtagzfb/trunk/htdocs/images/org 6 | http://sajith@10.2.30.40/muzicall 7 | 8 | 9 | 10 | 2011-08-31T17:22:19.696868Z 11 | 20727 12 | sajith 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0013cf6a-2276-4056-9bbb-7e8f5601526d 28 | 29 | bytearray 30 | dir 31 | 32 | -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/WavSound.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound { 2 | import flash.events.SampleDataEvent; 3 | import flash.media.Sound; 4 | import flash.media.SoundChannel; 5 | import flash.media.SoundLoaderContext; 6 | import flash.media.SoundTransform; 7 | import flash.net.URLRequest; 8 | import flash.utils.ByteArray; 9 | import org.as3wavsound.sazameki.core.AudioSamples; 10 | import org.as3wavsound.sazameki.core.AudioSetting; 11 | import org.as3wavsound.sazameki.format.wav.Wav; 12 | 13 | /* 14 | * -------------------------------------- 15 | * b.bottema [Codemonkey] -- WavSound Sound adaption 16 | * http://blog.projectnibble.org/ 17 | * -------------------------------------- 18 | * sazameki -- audio manipulating library 19 | * http://sazameki.org/ 20 | * -------------------------------------- 21 | * 22 | * - developed by: 23 | * Benny Bottema (Codemonkey) 24 | * blog.projectnibble.org 25 | * hosted by: 26 | * Google Code (code.google.com) 27 | * code.google.com/p/as3wavsound/ 28 | * 29 | * - audio library in its original state developed by: 30 | * Takaaki Yamazaki 31 | * www.zkdesign.jp 32 | * hosted by: 33 | * Spark project (www.libspark.org) 34 | * www.libspark.org/svn/as3/sazameki/branches/fp10/ 35 | */ 36 | 37 | /* 38 | * Licensed under the MIT License 39 | * 40 | * Copyright (c) 2008 Takaaki Yamazaki 41 | * 42 | * Permission is hereby granted, free of charge, to any person obtaining a copy 43 | * of this software and associated documentation files (the "Software"), to deal 44 | * in the Software without restriction, including without limitation the rights 45 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | * copies of the Software, and to permit persons to whom the Software is 47 | * furnished to do so, subject to the following conditions: 48 | * 49 | * The above copyright notice and this permission notice shall be included in 50 | * all copies or substantial portions of the Software. 51 | * 52 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | * THE SOFTWARE. 59 | */ 60 | 61 | /** 62 | * Sound extension that directly plays WAVE data. Also backwards compatible with 63 | * MP3's played through the load() method. 64 | * 65 | * Simply embed .wav files as you would mp3's and play with this Sound class. 66 | * Make sure you provide mimetype 'application/octet-stream' when embedding to 67 | * ensure Flash embeds the data as ByteArray. 68 | * 69 | * Example: 70 | * [Embed(source = "drumloop.wav", mimeType = "application/octet-stream")] 71 | * public const DrumLoop:Class; 72 | * public const rain:Sound = new WavSound(new DrumLoop() as ByteArray); 73 | * 74 | * 75 | * @author b.bottema [Codemonkey] 76 | */ 77 | public class WavSound { 78 | 79 | // the master Sound player, which mixes all playing WavSound samples on any given moment 80 | private static const player:WavSoundPlayer = new WavSoundPlayer(); 81 | 82 | // length of the original encoded wav data 83 | private var _bytesTotal:Number; 84 | // extracted sound data for mixing 85 | private var _samples:AudioSamples; 86 | // each sound can be configured to be played mono/stereo using AudioSetting 87 | private var _playbackSettings:AudioSetting; 88 | // calculated length of the entire sound in milliseconds, made global to avoid recalculating all the time 89 | private var _length:Number; 90 | 91 | /** 92 | * Constructor: loads wavdata using loadWav(). 93 | * 94 | * @param wavData A ByteArray containing uncmopressed wav data. 95 | * @param audioSettings An optional playback configuration (mono/stereo, 96 | * sample rate and bit rate). 97 | */ 98 | public function WavSound(wavData:ByteArray, audioSettings:AudioSetting = null) { 99 | load(wavData, audioSettings); 100 | } 101 | 102 | /** 103 | * Loads WAVE data. 104 | * 105 | * Resets this WavSound and turns off legacy mode to act as a WavSound object. 106 | * 107 | * @param wavData 108 | * @param audioSettings 109 | */ 110 | internal function load(wavData:ByteArray, audioSettings:AudioSetting = null): void { 111 | this._bytesTotal = wavData.length; 112 | this._samples = new Wav().decode(wavData); 113 | this._playbackSettings = (audioSettings != null) ? audioSettings : new AudioSetting(); 114 | this._length = samples.length / samples.setting.sampleRate * 1000; 115 | } 116 | 117 | /** 118 | * Playback function that performs the following tasks: 119 | * 120 | * - calculates the startingPhase, bases on startTime in ms. 121 | * - initializes loopsLeft variable 122 | * - adds the playing channel in combination with its originating WavSound to the playingWavSounds 123 | * 124 | * @param startTime The starting time in milliseconds, applies to each loop (as with regular MP3 Sounds). 125 | * @param loops The number of loops to take in *addition* to the default playback (loops == 2 -> 3 playthroughs). 126 | * @param sndTransform An optional soundtransform to apply for playback that controls volume and panning. 127 | * @return The SoundChannel used for playing back the sound. 128 | */ 129 | public function play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null): WavSoundChannel { 130 | return player.play(this, startTime, loops, sndTransform); 131 | } 132 | 133 | /** 134 | * No idea if this works. Alpha state. Read up on Sound.extract(): 135 | * http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#extract() 136 | */ 137 | public function extract(target:ByteArray, length:Number, startPosition:Number = -1): Number { 138 | var start:Number = Math.max(startPosition, 0); 139 | var end:Number = Math.min(length, samples.length); 140 | 141 | for (var i:Number = start; i < end; i++) { 142 | target.writeFloat(samples.left[i]); 143 | if (samples.setting.channels == 2) { 144 | target.writeFloat(samples.right[i]); 145 | } else { 146 | target.writeFloat(samples.left[i]); 147 | } 148 | } 149 | 150 | return samples.length; 151 | } 152 | 153 | /** 154 | * Returns the total bytes of the wavData the current WavSound was created with. 155 | */ 156 | public function get bytesLoaded () : uint { 157 | return _bytesTotal; 158 | } 159 | 160 | /** 161 | * Returns the total bytes of the wavData the current WavSound was created with. 162 | */ 163 | public function get bytesTotal () : int { 164 | return _bytesTotal; 165 | } 166 | 167 | /** 168 | * Returns the total length of the sound in milliseconds. 169 | */ 170 | public function get length() : Number { 171 | return _length; 172 | } 173 | 174 | internal function get samples():AudioSamples { 175 | return _samples; 176 | } 177 | 178 | internal function get playbackSettings():AudioSetting { 179 | return _playbackSettings; 180 | } 181 | } 182 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/WavSoundChannel.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound { 2 | import flash.events.EventDispatcher; 3 | import flash.media.SoundChannel; 4 | import flash.events.Event; 5 | import flash.media.SoundTransform; 6 | import org.as3wavsound.sazameki.core.AudioSamples; 7 | import org.as3wavsound.WavSound; 8 | 9 | /** 10 | * Used to keep track of open channels during playback. Each channel represents 11 | * an 'instance' of a sound and so each channel is responsible for its own mixing. 12 | * 13 | * Also see buffer(). 14 | * 15 | * @author b.bottema [Codemonkey] 16 | */ 17 | public class WavSoundChannel extends EventDispatcher { 18 | 19 | /* 20 | * creation-time information 21 | */ 22 | 23 | // the player to delegate play() stop() requests to 24 | private var player:WavSoundPlayer; 25 | 26 | // a WavSound currently playing back on one or several channels 27 | private var _wavSound:WavSound; 28 | 29 | // works the same as SoundChannel.soundTransform 30 | private var _soundTransform:SoundTransform = new SoundTransform(); 31 | 32 | /* 33 | * play-time information *per WavSound* 34 | */ 35 | 36 | // starting phase if not at the beginning, made global to avoid recalculating all the time 37 | private var startPhase:Number; 38 | // current phase of the sound, basically matches a single current sample frame for each WavSound 39 | private var phase:Number = 0; 40 | // the current avarage volume of samples buffered to the left audiochannel 41 | private var _leftPeak:Number = 0; 42 | // the current avarage volume of samples buffered to the right audiochannel 43 | private var _rightPeak:Number = 0; 44 | // how many loops we need to buffer 45 | private var loopsLeft:Number; 46 | // indicates if the phase has reached total sample count and no loops are left 47 | private var finished:Boolean; 48 | 49 | /** 50 | * Constructor: pre-calculates starting phase (and performs some validation for this). 51 | */ 52 | public function WavSoundChannel(player:WavSoundPlayer, wavSound:WavSound, startTime:Number, loops:int, soundTransform:SoundTransform) { 53 | this.player = player; 54 | this._wavSound = wavSound; 55 | if (soundTransform != null) { 56 | this._soundTransform = soundTransform; 57 | } 58 | init(startTime, loops); 59 | } 60 | 61 | /** 62 | * Calculates and validates the starting time. Starting time in milliseconds is converted into 63 | * sample position and then marked as starting phase. 64 | */ 65 | internal function init(startTime:Number, loops:int):void { 66 | var startPositionInMillis:Number = Math.floor(startTime); 67 | var maxPositionInMillis:Number = Math.floor(_wavSound.length); 68 | if (startPositionInMillis > maxPositionInMillis) { 69 | throw new Error("startTime greater than sound's length, max startTime is " + maxPositionInMillis); 70 | } 71 | phase = startPhase = Math.floor(startPositionInMillis * _wavSound.samples.length / _wavSound.length); 72 | finished = false; 73 | loopsLeft = loops; 74 | } 75 | 76 | public function stop():void { 77 | player.stop(this); 78 | } 79 | 80 | /** 81 | * Fills a target samplebuffer with optionally transformed samples from the current 82 | * WavSound instance (which is the current channel). 83 | * 84 | * Keeps filling the buffer for each loop the sound should be mixed in the target buffer. 85 | * When the buffer is full, phase and loopsLeft keep track of how which and many samples 86 | * still need to be buffered in the next buffering cycle (when this method is called again). 87 | * 88 | * @param sampleBuffer The target buffer to mix in the current (transformed) samples. 89 | * @param soundTransform The soundtransform that belongs to a single channel being played 90 | * (containing volume, panning etc.). 91 | */ 92 | internal function buffer(sampleBuffer:AudioSamples):void { 93 | // calculate volume and panning 94 | var volume: Number = (_soundTransform.volume / 1); 95 | var volumeLeft: Number = volume * (1 - _soundTransform.pan) / 2; 96 | var volumeRight: Number = volume * (1 + _soundTransform.pan) / 2; 97 | // channel settings 98 | var needRightChannel:Boolean = _wavSound.playbackSettings.channels == 2; 99 | var hasRightChannel:Boolean = _wavSound.samples.setting.channels == 2; 100 | 101 | // extra references to avoid excessive getter calls in the following 102 | // for-loop (it appeares CPU is being hogged otherwise) 103 | var samplesLength:Number = _wavSound.samples.length; 104 | var samplesLeft:Vector. = _wavSound.samples.left; 105 | var samplesRight:Vector. = _wavSound.samples.right; 106 | var sampleBufferLength:Number = sampleBuffer.length; 107 | var sampleBufferLeft:Vector. = sampleBuffer.left; 108 | var sampleBufferRight:Vector. = sampleBuffer.right; 109 | 110 | var leftPeakRecord:Number = 0; 111 | var rightPeakRecord:Number = 0; 112 | 113 | // finally, mix the samples in the master sample buffer 114 | if (!finished) { 115 | for (var i:int = 0; i < sampleBufferLength; i++) { 116 | if (!finished) { 117 | // write (transformed) samples to buffer 118 | var sampleLeft:Number = samplesLeft[phase] * volumeLeft; 119 | sampleBufferLeft[i] += sampleLeft; 120 | leftPeakRecord += sampleLeft; 121 | var channelValue:Number = ((needRightChannel && hasRightChannel) ? samplesRight[phase] : samplesLeft[phase]); 122 | var sampleRight:Number = channelValue * volumeRight; 123 | sampleBufferRight[i] += sampleRight; 124 | rightPeakRecord += sampleRight; 125 | 126 | // check playing and looping state 127 | if (++phase >= samplesLength) { 128 | phase = startPhase; 129 | finished = loopsLeft-- == 0; 130 | } 131 | } 132 | } 133 | 134 | if (finished) { 135 | dispatchEvent(new Event(Event.SOUND_COMPLETE)); 136 | } 137 | } 138 | 139 | _leftPeak = leftPeakRecord / sampleBufferLength; 140 | _rightPeak = rightPeakRecord / sampleBufferLength 141 | } 142 | 143 | internal function get wavSound():WavSound { 144 | return _wavSound 145 | } 146 | 147 | public function get leftPeak(): Number { 148 | return _leftPeak; 149 | } 150 | 151 | public function get rightPeak(): Number { 152 | return _rightPeak; 153 | } 154 | 155 | public function get position(): Number { 156 | return phase * _wavSound.length / _wavSound.samples.length; 157 | } 158 | 159 | public function get soundTransform():SoundTransform { 160 | return _soundTransform; 161 | } 162 | } 163 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/WavSoundPlayer.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound { 2 | import flash.events.SampleDataEvent; 3 | import flash.media.Sound; 4 | import flash.media.SoundChannel; 5 | import flash.media.SoundTransform; 6 | import flash.net.URLRequest; 7 | import flash.utils.ByteArray; 8 | import org.as3wavsound.sazameki.core.AudioSamples; 9 | import org.as3wavsound.sazameki.core.AudioSetting; 10 | import org.as3wavsound.WavSoundChannel; 11 | 12 | /* 13 | * -------------------------------------- 14 | * b.bottema [Codemonkey] -- WavSound Sound adaption 15 | * http://blog.projectnibble.org/ 16 | * -------------------------------------- 17 | * sazameki -- audio manipulating library 18 | * http://sazameki.org/ 19 | * -------------------------------------- 20 | * 21 | * - developed by: 22 | * Benny Bottema (Codemonkey) 23 | * blog.projectnibble.org 24 | * hosted by: 25 | * Google Code (code.google.com) 26 | * code.google.com/p/as3wavsound/ 27 | * 28 | * - audio library in its original state developed by: 29 | * Takaaki Yamazaki 30 | * www.zkdesign.jp 31 | * hosted by: 32 | * Spark project (www.libspark.org) 33 | * www.libspark.org/svn/as3/sazameki/branches/fp10/ 34 | */ 35 | 36 | /* 37 | * Licensed under the MIT License 38 | * 39 | * Copyright (c) 2008 Takaaki Yamazaki 40 | * 41 | * Permission is hereby granted, free of charge, to any person obtaining a copy 42 | * of this software and associated documentation files (the "Software"), to deal 43 | * in the Software without restriction, including without limitation the rights 44 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 45 | * copies of the Software, and to permit persons to whom the Software is 46 | * furnished to do so, subject to the following conditions: 47 | * 48 | * The above copyright notice and this permission notice shall be included in 49 | * all copies or substantial portions of the Software. 50 | * 51 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 52 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 53 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 54 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 55 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 56 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 57 | * THE SOFTWARE. 58 | */ 59 | 60 | /** 61 | * Playback utility class contains a singular Sound for playback 62 | * and sample mixing. 63 | * 64 | * 65 | * @author b.bottema [Codemonkey] 66 | */ 67 | internal class WavSoundPlayer { 68 | public static var MAX_BUFFERSIZE:Number = 8192; 69 | 70 | // the master samples buffer in which all seperate Wavsounds are mixed into, always stereo at 44100Hz and bitrate 16 71 | private const sampleBuffer:AudioSamples = new AudioSamples(new AudioSetting(), MAX_BUFFERSIZE); 72 | // a list of all WavSound currenctly in playing mode 73 | private const playingWavSounds:Vector. = new Vector.(); 74 | // the singular playback SOund with which all other WavSounds are played back 75 | private const player:Sound = configurePlayer(); 76 | 77 | /** 78 | * Static initializer: creates, configures and run the singular sound player. 79 | * Until play() has been called on a WavSound, nothing is audible. 80 | */ 81 | private function configurePlayer():Sound { 82 | var player:Sound = new Sound(); 83 | player.addEventListener(SampleDataEvent.SAMPLE_DATA, onSamplesCallback); 84 | player.play(); 85 | return player; 86 | } 87 | 88 | /** 89 | * Creates WavSoundChannel and adds this to the list of playing currently playing (should be included in the master buffering process). 90 | * Also returns this instance for sound manipulation by the end-user (just like the traditional SoundChannel). 91 | */ 92 | internal function play(sound:WavSound, startTime:Number, loops:int, sndTransform:SoundTransform):WavSoundChannel { 93 | var channel:WavSoundChannel = new WavSoundChannel(this, sound, startTime, loops, sndTransform); 94 | playingWavSounds.push(channel); 95 | return channel; 96 | } 97 | 98 | /** 99 | * Remove a spific currently playing channel. 100 | */ 101 | internal function stop(channel:WavSoundChannel):void { 102 | for each (var playingWavSound:WavSoundChannel in playingWavSounds) { 103 | if (playingWavSound == channel) { 104 | playingWavSounds.splice(playingWavSounds.lastIndexOf(playingWavSound), 1); 105 | } 106 | } 107 | } 108 | 109 | /** 110 | * The heartbeat of the WavSound approach. 111 | * Invoked by the player appointed Sound object. 112 | * 113 | * Together with this callback all WavSound instances stored in the list 114 | * playingWavSounds are mixed together and then written to the outputstream 115 | * 116 | * @param event Contains the outputstream to mix sound samples into. 117 | */ 118 | private function onSamplesCallback(event:SampleDataEvent):void { 119 | // clear the buffer 120 | sampleBuffer.clearSamples(); 121 | // have all channels mix their into the master sample buffer 122 | for each (var playingWavSound:WavSoundChannel in playingWavSounds) { 123 | playingWavSound.buffer(sampleBuffer); 124 | } 125 | 126 | // extra references to avoid excessive getter calls in the following 127 | // for-loop (it appeares CPU is being hogged otherwise) 128 | var outputStream:ByteArray = event.data; 129 | var samplesLength:Number = sampleBuffer.length; 130 | var samplesLeft:Vector. = sampleBuffer.left; 131 | var samplesRight:Vector. = sampleBuffer.right; 132 | 133 | // write all mixed samples to the sound's outputstream 134 | for (var i:int = 0; i < samplesLength; i++) { 135 | outputStream.writeFloat(samplesLeft[i]); 136 | outputStream.writeFloat(samplesRight[i]); 137 | } 138 | } 139 | 140 | private function onSamplesMirrorCallback(event:SampleDataEvent):void { 141 | // write all mixed samples to the sound's outputstream 142 | var outputStream:ByteArray = event.data; 143 | for (var i:int = 0; i < 2048; i++) { 144 | outputStream.writeFloat(0); 145 | outputStream.writeFloat(0); 146 | } 147 | } 148 | } 149 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/core/AudioSamples.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.core { 2 | 3 | /** 4 | * Contains lists of samples -left and optionally right- decoded from a 5 | * WAVE ByteArray or manually mixed samples. 6 | * 7 | * Also contains a reference to an AudioSetting instance associated by 8 | * this samples container. 9 | * 10 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 11 | */ 12 | public class AudioSamples { 13 | public var _left:Vector.; 14 | public var _right:Vector.; 15 | private var _setting:AudioSetting; 16 | 17 | /** 18 | * @param length Can be zero when decoding WAVE data, or a fixed buffer 19 | * size when mixing to a Sound's outputstream. 20 | */ 21 | public function AudioSamples(setting:AudioSetting, length:Number = 0) { 22 | this._setting = setting; 23 | this._left = new Vector.(length, length > 0); 24 | if (setting.channels == 2) { 25 | this._right = new Vector.(length, length > 0); 26 | } 27 | } 28 | 29 | /** 30 | * Always resets length to its former state. Don't call this after creating 31 | * an instance of AudioSamples, or its length is always zero. 32 | */ 33 | public function clearSamples():void { 34 | _left = new Vector.(length, true); 35 | if (setting.channels == 2) { 36 | _right = new Vector.(length, true); 37 | } 38 | } 39 | 40 | public function get length():int { 41 | return left.length; 42 | } 43 | 44 | public function get setting():AudioSetting { 45 | return _setting; 46 | } 47 | 48 | public function get left():Vector. { 49 | return _left; 50 | } 51 | 52 | public function get right():Vector. { 53 | return _right; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/core/AudioSetting.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.core { 2 | 3 | /** 4 | * Contains a sound's playback configuration, such as mono / stereo, 5 | * sample rate and bit rate. 6 | * 7 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 8 | */ 9 | public class AudioSetting { 10 | // 1 or 2 11 | private var _channels:uint; 12 | // 11025, 22050 or 44100 13 | private var _sampleRate:uint; 14 | // 8 or 16 15 | private var _bitRate:uint; 16 | 17 | /** 18 | * Constructor: performs some validations on the values being passed in. 19 | */ 20 | public function AudioSetting(channels:uint = 2,sampleRate:uint = 44100,bitRate:uint = 16) { 21 | if (sampleRate != 44100 && sampleRate != 22050 && sampleRate != 11025) { 22 | throw new Error("bad sample rate. sample rate must be 44100, 22050 or 11025"); 23 | } 24 | if (channels != 1 && channels != 2) { 25 | throw new Error("channels must be 1 or 2"); 26 | } 27 | 28 | if (bitRate != 16 && bitRate != 8) { 29 | throw new Error("bitRate must be 8 or 16"); 30 | } 31 | 32 | _channels=channels; 33 | _sampleRate=sampleRate; 34 | _bitRate=bitRate; 35 | } 36 | 37 | public function get channels():uint{ 38 | return _channels; 39 | } 40 | 41 | public function get sampleRate():uint{ 42 | return _sampleRate; 43 | } 44 | 45 | public function get bitRate():uint{ 46 | return _bitRate; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/riff/Chunk.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.riff { 2 | import flash.utils.ByteArray; 3 | import flash.utils.Endian; 4 | 5 | /** 6 | * RIFF Chunk class 7 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 8 | */ 9 | public class Chunk { 10 | protected const ENDIAN:String = Endian.LITTLE_ENDIAN; 11 | protected var _id:String; 12 | 13 | public function Chunk(id:String) { 14 | this.id = id; 15 | } 16 | 17 | public function set id(value:String):void { 18 | if (value.length > 4) { 19 | value = value.substr(0, 4); 20 | } else if (value.length < 4) { 21 | while (value.length < 4) { 22 | value += " "; 23 | } 24 | } 25 | _id = value; 26 | } 27 | 28 | public function get id():String { 29 | return _id; 30 | } 31 | 32 | public function toByteArray():ByteArray { 33 | var result:ByteArray = new ByteArray(); 34 | result.endian = ENDIAN; 35 | result.writeUTFBytes(_id); 36 | var data:ByteArray = encodeData(); 37 | result.writeUnsignedInt(data.length); 38 | result.writeBytes(data); 39 | return result; 40 | } 41 | 42 | protected function encodeData():ByteArray { 43 | throw new Error("'encodeData()' method must be overriden"); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/riff/LIST.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.riff { 2 | import flash.utils.ByteArray; 3 | 4 | /** 5 | * ... 6 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 7 | */ 8 | public class LIST extends Chunk { 9 | protected var _type:String; 10 | protected var _chunks:Vector.; 11 | 12 | public function LIST(type:String) { 13 | this.type = type; 14 | super("LIST"); 15 | } 16 | 17 | public function set type(value:String):void { 18 | if (value.length > 4) { 19 | value = value.substr(0, 4); 20 | } else if (value.length < 4) { 21 | while (value.length < 4) { 22 | value += " "; 23 | } 24 | } 25 | _type = value; 26 | } 27 | 28 | public function get type():String { 29 | return _type; 30 | } 31 | 32 | override protected function encodeData():ByteArray { 33 | var result:ByteArray = new ByteArray(); 34 | result.writeUTFBytes(_type); 35 | for (var i:int = 0; i < _chunks.length; i++) { 36 | result.writeBytes(_chunks[i].toByteArray()); 37 | } 38 | return result; 39 | } 40 | 41 | protected function splitList(bytes:ByteArray):Object { 42 | bytes.position = 0; 43 | bytes.endian = ENDIAN; 44 | 45 | if (bytes.readUTFBytes(4) == 'RIFF') { 46 | bytes.readInt(); 47 | bytes.readUTFBytes(4);//type 48 | } else { 49 | bytes.position = 0; 50 | } 51 | 52 | var obj:Object = new Object(); 53 | while (bytes.position < bytes.length) { 54 | var currentName:String = bytes.readUTFBytes(4); 55 | var current:int = bytes.readInt(); 56 | 57 | if (currentName == 'LIST') { 58 | currentName = bytes.readUTFBytes(4); 59 | current -= 4; 60 | } 61 | 62 | var tmpByte:ByteArray = new ByteArray(); 63 | bytes.readBytes(tmpByte, 0, current); 64 | 65 | if (current % 2 == 1) { 66 | bytes.readByte(); 67 | } 68 | obj[currentName] = tmpByte; 69 | } 70 | return obj; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/riff/RIFF.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.riff { 2 | 3 | /** 4 | * ... 5 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 6 | */ 7 | public class RIFF extends LIST { 8 | public function RIFF(type:String) { 9 | super(type); 10 | id = 'RIFF'; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/wav/Wav.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.wav { 2 | import flash.utils.ByteArray; 3 | import flash.utils.Endian; 4 | import org.as3wavsound.sazameki.core.AudioSamples; 5 | import org.as3wavsound.sazameki.core.AudioSetting; 6 | import org.as3wavsound.sazameki.format.riff.Chunk; 7 | import org.as3wavsound.sazameki.format.riff.RIFF; 8 | import org.as3wavsound.sazameki.format.wav.chunk.WavdataChunk; 9 | import org.as3wavsound.sazameki.format.wav.chunk.WavfmtChunk; 10 | 11 | /** 12 | * The WAVE decoder used for playing back wav files. 13 | * 14 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 15 | */ 16 | public class Wav extends RIFF { 17 | 18 | public function Wav() { 19 | super('WAVE'); 20 | } 21 | 22 | public function encode(samples:AudioSamples):ByteArray { 23 | var fmt:WavfmtChunk = new WavfmtChunk(); 24 | var data:WavdataChunk = new WavdataChunk(); 25 | 26 | _chunks = new Vector.; 27 | _chunks.push(fmt); 28 | _chunks.push(data); 29 | 30 | data.setAudioData(samples); 31 | fmt.setSetting(samples.setting); 32 | 33 | return toByteArray(); 34 | } 35 | 36 | public function decode(wavData:ByteArray):AudioSamples { 37 | var obj:Object = splitList(wavData); 38 | if (obj['fmt '] && obj['data']) { 39 | var setting:AudioSetting = new WavfmtChunk().decodeData(obj['fmt '] as ByteArray); 40 | var data:AudioSamples = new WavdataChunk().decodeData(obj['data'] as ByteArray, setting); 41 | return data; 42 | } else { 43 | throw new Error('invalid wav file'); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/wav/chunk/WavdataChunk.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.wav.chunk { 2 | import flash.utils.ByteArray; 3 | import org.as3wavsound.sazameki.core.AudioSamples; 4 | import org.as3wavsound.sazameki.core.AudioSetting; 5 | import org.as3wavsound.sazameki.format.riff.Chunk; 6 | 7 | /** 8 | * ... 9 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 10 | */ 11 | public class WavdataChunk extends Chunk { 12 | private var _samples:AudioSamples; 13 | 14 | public function WavdataChunk() { 15 | super('data'); 16 | } 17 | 18 | public function setAudioData(samples:AudioSamples):void { 19 | _samples = samples; 20 | } 21 | 22 | override protected function encodeData():ByteArray { 23 | var bytes:ByteArray = new ByteArray(); 24 | bytes.endian = ENDIAN; 25 | 26 | var setting:AudioSetting = _samples.setting; 27 | var i:int; 28 | var sig:Number; 29 | var len:int = _samples.left.length; 30 | var left:Vector.; 31 | 32 | if (setting.channels == 2) { 33 | left=_samples.left; 34 | var right:Vector.=_samples.right; 35 | 36 | if (setting.bitRate == 16) { 37 | for (i = 0; i < len; i++) { 38 | sig = left[i]; 39 | if (sig < -1) bytes.writeShort( -32767); 40 | else if (sig > 1) bytes.writeShort( 32767); 41 | else bytes.writeShort(sig * 32767); 42 | 43 | sig = right[i]; 44 | if (sig < -1) bytes.writeShort(-32767); 45 | else if (sig > 1) bytes.writeShort(32767); 46 | else bytes.writeShort(sig * 32767); 47 | } 48 | } else { 49 | for (i = 0; i < len; i++) { 50 | sig = left[i]; 51 | if (sig<-1) bytes.writeByte(0); 52 | else if (sig>1) bytes.writeByte(255); 53 | else bytes.writeByte(sig*127+128); 54 | 55 | sig = right[i]; 56 | if (sig<-1) bytes.writeByte(0); 57 | else if (sig>1) bytes.writeByte(255); 58 | else bytes.writeByte(sig*127+128); 59 | } 60 | } 61 | } else { 62 | left = _samples.left; 63 | 64 | if (setting.bitRate == 16) { 65 | for (i = 0; i < len; i++) { 66 | sig = left[i]; 67 | if (sig < -1) bytes.writeShort(-32767); 68 | else if (sig > 1) bytes.writeShort(32767); 69 | else bytes.writeShort(sig * 32768); 70 | } 71 | } else { 72 | for (i = 0; i < len; i++) { 73 | sig = left[i]; 74 | if (sig<-1) bytes.writeByte(0); 75 | else if (sig>1) bytes.writeByte(255); 76 | else bytes.writeByte(sig*127+128); 77 | } 78 | } 79 | 80 | } 81 | return bytes; 82 | } 83 | 84 | public function decodeData(bytes:ByteArray,setting:AudioSetting):AudioSamples { 85 | bytes.position = 0; 86 | bytes.endian = ENDIAN; 87 | 88 | var samples:AudioSamples = new AudioSamples(setting); 89 | var length:int = bytes.length / (setting.bitRate / 8) / setting.channels; 90 | var i:int; 91 | var left:Vector.; 92 | 93 | if (setting.channels == 2) { 94 | left = samples.left; 95 | var right:Vector. = samples.right; 96 | if (setting.bitRate == 16) { 97 | for (i = 0; i < length; ++i) { 98 | left[i] = bytes.readShort() / 32767; 99 | right[i] = bytes.readShort() / 32767; 100 | } 101 | 102 | } else { 103 | for (i = 0; i < length; i++) 104 | { 105 | left[i] = bytes.readByte() / 255; 106 | right[i] = bytes.readByte() / 255; 107 | } 108 | } 109 | } else { 110 | left = samples.left; 111 | if (setting.bitRate == 16) { 112 | for (i = 0; i < length; i++) { 113 | left[i] = bytes.readShort() / 32767; 114 | } 115 | } else { 116 | for (i = 0; i < length; i++) { 117 | left[i] = bytes.readByte() / 255; 118 | } 119 | } 120 | } 121 | return samples; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /flash-fla/org/as3wavsound/sazameki/format/wav/chunk/WavfmtChunk.as: -------------------------------------------------------------------------------- 1 | package org.as3wavsound.sazameki.format.wav.chunk { 2 | import flash.utils.ByteArray; 3 | import org.as3wavsound.sazameki.core.AudioSetting; 4 | import org.as3wavsound.sazameki.format.riff.Chunk; 5 | 6 | /** 7 | * ... 8 | * @author Takaaki Yamazaki(zk design), modified by b.bottema [Codemonkey] 9 | */ 10 | public class WavfmtChunk extends Chunk { 11 | private var _setting:AudioSetting; 12 | 13 | public function WavfmtChunk() { 14 | super('fmt '); 15 | } 16 | 17 | public function setSetting(setting:AudioSetting):void { 18 | _setting = setting; 19 | } 20 | 21 | override protected function encodeData():ByteArray { 22 | var result:ByteArray = new ByteArray(); 23 | result.endian = ENDIAN; 24 | 25 | //fmt ID(2) 26 | result.writeShort(1); 27 | //channels(2) 28 | result.writeShort(_setting.channels); 29 | //sampling rate(4) 30 | result.writeInt(_setting.sampleRate); 31 | //data rate(4) 32 | result.writeInt(_setting.sampleRate * _setting.channels * (_setting.bitRate / 8)); 33 | //block size(2) 34 | result.writeShort((_setting.bitRate / 8) * _setting.channels); 35 | //bit rate(2) 36 | result.writeShort(_setting.bitRate); 37 | 38 | return result; 39 | } 40 | 41 | public function decodeData(bytes:ByteArray):AudioSetting { 42 | bytes.position = 0; 43 | bytes.endian = ENDIAN; 44 | bytes.readShort(); 45 | var channels:int = bytes.readShort(); 46 | var smplRate:int = bytes.readInt(); 47 | bytes.readInt(); 48 | bytes.readShort(); 49 | var bit:int = bytes.readShort(); 50 | _setting = new AudioSetting(channels, smplRate, bit); 51 | return _setting; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/org/bytearray/.DS_Store -------------------------------------------------------------------------------- /flash-fla/org/bytearray/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 69 4 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray 5 | END 6 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 20727 5 | http://sajith@10.2.30.40/muzicall/ringtagzfb/trunk/htdocs/images/org/bytearray 6 | http://sajith@10.2.30.40/muzicall 7 | 8 | 9 | 10 | 2011-08-31T17:22:19.696868Z 11 | 20727 12 | sajith 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0013cf6a-2276-4056-9bbb-7e8f5601526d 28 | 29 | micrecorder 30 | dir 31 | 32 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/flash-fla/org/bytearray/micrecorder/.DS_Store -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 81 4 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder 5 | END 6 | MicRecorder.as 7 | K 25 8 | svn:wc:ra_dav:version-url 9 | V 96 10 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/MicRecorder.as 11 | END 12 | IEncoder.as 13 | K 25 14 | svn:wc:ra_dav:version-url 15 | V 93 16 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/IEncoder.as 17 | END 18 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 20727 5 | http://sajith@10.2.30.40/muzicall/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder 6 | http://sajith@10.2.30.40/muzicall 7 | 8 | 9 | 10 | 2011-08-31T17:22:19.696868Z 11 | 20727 12 | sajith 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0013cf6a-2276-4056-9bbb-7e8f5601526d 28 | 29 | encoder 30 | dir 31 | 32 | MicRecorder.as 33 | file 34 | 35 | 36 | 37 | 38 | 2011-08-31T17:15:30.000000Z 39 | dd92877861891110f154c248579fe216 40 | 2011-08-31T17:22:19.696868Z 41 | 20727 42 | sajith 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 5261 65 | 66 | events 67 | dir 68 | 69 | IEncoder.as 70 | file 71 | 72 | 73 | 74 | 75 | 2011-08-31T17:15:30.000000Z 76 | 300f93575302c3547f27bbe4a5dc9c8f 77 | 2011-08-31T17:22:19.696868Z 78 | 20727 79 | sajith 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 195 102 | 103 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/.svn/text-base/IEncoder.as.svn-base: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder 2 | { 3 | import flash.utils.ByteArray; 4 | 5 | public interface IEncoder 6 | { 7 | function encode(samples:ByteArray, channels:int=2, bits:int=16, rate:int=44100):ByteArray; 8 | } 9 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/.svn/text-base/MicRecorder.as.svn-base: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder 2 | { 3 | import flash.events.Event; 4 | import flash.events.EventDispatcher; 5 | import flash.events.SampleDataEvent; 6 | import flash.events.StatusEvent; 7 | import flash.media.Microphone; 8 | import flash.utils.ByteArray; 9 | import flash.utils.getTimer; 10 | 11 | import org.bytearray.micrecorder.encoder.WaveEncoder; 12 | import org.bytearray.micrecorder.events.RecordingEvent; 13 | 14 | /** 15 | * Dispatched during the recording of the audio stream coming from the microphone. 16 | * 17 | * @eventType org.bytearray.micrecorder.RecordingEvent.RECORDING 18 | * 19 | * * @example 20 | * This example shows how to listen for such an event : 21 | *
22 | *
 23 | 	 *
 24 | 	 * recorder.addEventListener ( RecordingEvent.RECORDING, onRecording );
 25 | 	 * 
26 | *
27 | */ 28 | [Event(name='recording', type='org.bytearray.micrecorder.RecordingEvent')] 29 | 30 | /** 31 | * Dispatched when the creation of the output file is done. 32 | * 33 | * @eventType flash.events.Event.COMPLETE 34 | * 35 | * @example 36 | * This example shows how to listen for such an event : 37 | *
38 | *
 39 | 	 *
 40 | 	 * recorder.addEventListener ( Event.COMPLETE, onRecordComplete );
 41 | 	 * 
42 | *
43 | */ 44 | [Event(name='complete', type='flash.events.Event')] 45 | 46 | /** 47 | * This tiny helper class allows you to quickly record the audio stream coming from the Microphone and save this as a physical file. 48 | * A WavEncoder is bundled to save the audio stream as a WAV file 49 | * @author Thibault Imbert - bytearray.org 50 | * @version 1.2 51 | * 52 | */ 53 | public final class MicRecorder extends EventDispatcher 54 | { 55 | private var _gain:uint; 56 | private var _rate:uint; 57 | private var _silenceLevel:uint; 58 | private var _timeOut:uint; 59 | private var _difference:uint; 60 | private var _microphone:Microphone; 61 | private var _buffer:ByteArray = new ByteArray(); 62 | private var _output:ByteArray; 63 | private var _encoder:IEncoder; 64 | 65 | private var _completeEvent:Event = new Event ( Event.COMPLETE ); 66 | private var _recordingEvent:RecordingEvent = new RecordingEvent( RecordingEvent.RECORDING, 0 ); 67 | 68 | /** 69 | * 70 | * @param encoder The audio encoder to use 71 | * @param microphone The microphone device to use 72 | * @param gain The gain 73 | * @param rate Audio rate 74 | * @param silenceLevel The silence level 75 | * @param timeOut The timeout 76 | * 77 | */ 78 | public function MicRecorder(encoder:IEncoder, microphone:Microphone=null, gain:uint=100, rate:uint=44, silenceLevel:uint=0, timeOut:uint=4000) 79 | { 80 | _encoder = encoder; 81 | _microphone = microphone; 82 | _gain = gain; 83 | _rate = rate; 84 | _silenceLevel = silenceLevel; 85 | _timeOut = timeOut; 86 | } 87 | 88 | /** 89 | * Starts recording from the default or specified microphone. 90 | * The first time the record() method is called the settings manager may pop-up to request access to the Microphone. 91 | */ 92 | public function record():void 93 | { 94 | if ( _microphone == null ) 95 | _microphone = Microphone.getMicrophone(); 96 | 97 | _difference = getTimer(); 98 | 99 | _microphone.setSilenceLevel(_silenceLevel, _timeOut); 100 | _microphone.gain = _gain; 101 | _microphone.rate = _rate; 102 | _buffer.length = 0; 103 | 104 | _microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData); 105 | _microphone.addEventListener(StatusEvent.STATUS, onStatus); 106 | } 107 | 108 | private function onStatus(event:StatusEvent):void 109 | { 110 | _difference = getTimer(); 111 | } 112 | 113 | /** 114 | * Dispatched during the recording. 115 | * @param event 116 | */ 117 | private function onSampleData(event:SampleDataEvent):void 118 | { 119 | _recordingEvent.time = getTimer() - _difference; 120 | 121 | dispatchEvent( _recordingEvent ); 122 | 123 | while(event.data.bytesAvailable > 0) 124 | _buffer.writeFloat(event.data.readFloat()); 125 | } 126 | 127 | /** 128 | * Stop recording the audio stream and automatically starts the packaging of the output file. 129 | */ 130 | public function stop():void 131 | { 132 | _microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData); 133 | 134 | _buffer.position = 0; 135 | _output = _encoder.encode(_buffer, 1); 136 | 137 | dispatchEvent( _completeEvent ); 138 | } 139 | 140 | /** 141 | * 142 | * @return 143 | * 144 | */ 145 | public function get gain():uint 146 | { 147 | return _gain; 148 | } 149 | 150 | /** 151 | * 152 | * @param value 153 | * 154 | */ 155 | public function set gain(value:uint):void 156 | { 157 | _gain = value; 158 | } 159 | 160 | /** 161 | * 162 | * @return 163 | * 164 | */ 165 | public function get rate():uint 166 | { 167 | return _rate; 168 | } 169 | 170 | /** 171 | * 172 | * @param value 173 | * 174 | */ 175 | public function set rate(value:uint):void 176 | { 177 | _rate = value; 178 | } 179 | 180 | /** 181 | * 182 | * @return 183 | * 184 | */ 185 | public function get silenceLevel():uint 186 | { 187 | return _silenceLevel; 188 | } 189 | 190 | /** 191 | * 192 | * @param value 193 | * 194 | */ 195 | public function set silenceLevel(value:uint):void 196 | { 197 | _silenceLevel = value; 198 | } 199 | 200 | 201 | /** 202 | * 203 | * @return 204 | * 205 | */ 206 | public function get microphone():Microphone 207 | { 208 | return _microphone; 209 | } 210 | 211 | /** 212 | * 213 | * @param value 214 | * 215 | */ 216 | public function set microphone(value:Microphone):void 217 | { 218 | _microphone = value; 219 | } 220 | 221 | /** 222 | * 223 | * @return 224 | * 225 | */ 226 | public function get output():ByteArray 227 | { 228 | return _output; 229 | } 230 | 231 | /** 232 | * 233 | * @return 234 | * 235 | */ 236 | public override function toString():String 237 | { 238 | return "[MicRecorder gain=" + _gain + " rate=" + _rate + " silenceLevel=" + _silenceLevel + " timeOut=" + _timeOut + " microphone:" + _microphone + "]"; 239 | } 240 | } 241 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/IEncoder.as: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder 2 | { 3 | import flash.utils.ByteArray; 4 | 5 | public interface IEncoder 6 | { 7 | function encode(samples:ByteArray, channels:int=2, bits:int=16, rate:int=44100):ByteArray; 8 | } 9 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/MicRecorder.as: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder 2 | { 3 | import flash.events.Event; 4 | import flash.events.EventDispatcher; 5 | import flash.events.SampleDataEvent; 6 | import flash.events.StatusEvent; 7 | import flash.media.Microphone; 8 | import flash.utils.ByteArray; 9 | import flash.utils.getTimer; 10 | 11 | import org.bytearray.micrecorder.encoder.WaveEncoder; 12 | import org.bytearray.micrecorder.events.RecordingEvent; 13 | 14 | /** 15 | * Dispatched during the recording of the audio stream coming from the microphone. 16 | * 17 | * @eventType org.bytearray.micrecorder.RecordingEvent.RECORDING 18 | * 19 | * * @example 20 | * This example shows how to listen for such an event : 21 | *
22 | *
 23 | 	 *
 24 | 	 * recorder.addEventListener ( RecordingEvent.RECORDING, onRecording );
 25 | 	 * 
26 | *
27 | */ 28 | [Event(name='recording', type='org.bytearray.micrecorder.RecordingEvent')] 29 | 30 | /** 31 | * Dispatched when the creation of the output file is done. 32 | * 33 | * @eventType flash.events.Event.COMPLETE 34 | * 35 | * @example 36 | * This example shows how to listen for such an event : 37 | *
38 | *
 39 | 	 *
 40 | 	 * recorder.addEventListener ( Event.COMPLETE, onRecordComplete );
 41 | 	 * 
42 | *
43 | */ 44 | [Event(name='complete', type='flash.events.Event')] 45 | 46 | /** 47 | * This tiny helper class allows you to quickly record the audio stream coming from the Microphone and save this as a physical file. 48 | * A WavEncoder is bundled to save the audio stream as a WAV file 49 | * @author Thibault Imbert - bytearray.org 50 | * @version 1.2 51 | * 52 | */ 53 | public final class MicRecorder extends EventDispatcher 54 | { 55 | private var _gain:uint; 56 | private var _rate:uint; 57 | private var _silenceLevel:uint; 58 | private var _timeOut:uint; 59 | private var _difference:uint; 60 | private var _microphone:Microphone; 61 | private var _buffer:ByteArray = new ByteArray(); 62 | private var _output:ByteArray; 63 | private var _encoder:IEncoder; 64 | 65 | private var _completeEvent:Event = new Event ( Event.COMPLETE ); 66 | private var _recordingEvent:RecordingEvent = new RecordingEvent( RecordingEvent.RECORDING, 0 ); 67 | 68 | /** 69 | * 70 | * @param encoder The audio encoder to use 71 | * @param microphone The microphone device to use 72 | * @param gain The gain 73 | * @param rate Audio rate 74 | * @param silenceLevel The silence level 75 | * @param timeOut The timeout 76 | * 77 | */ 78 | public function MicRecorder(encoder:IEncoder, microphone:Microphone=null, gain:uint=100, rate:uint=44, silenceLevel:uint=0, timeOut:uint=4000) 79 | { 80 | _encoder = encoder; 81 | _microphone = microphone; 82 | _gain = gain; 83 | _rate = rate; 84 | _silenceLevel = silenceLevel; 85 | _timeOut = timeOut; 86 | } 87 | 88 | /** 89 | * Starts recording from the default or specified microphone. 90 | * The first time the record() method is called the settings manager may pop-up to request access to the Microphone. 91 | */ 92 | public function record():void 93 | { 94 | if ( _microphone == null ) 95 | _microphone = Microphone.getMicrophone(); 96 | 97 | _difference = getTimer(); 98 | 99 | _microphone.setSilenceLevel(_silenceLevel, _timeOut); 100 | _microphone.gain = _gain; 101 | _microphone.rate = _rate; 102 | _buffer.length = 0; 103 | 104 | _microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData); 105 | _microphone.addEventListener(StatusEvent.STATUS, onStatus); 106 | } 107 | 108 | private function onStatus(event:StatusEvent):void 109 | { 110 | _difference = getTimer(); 111 | } 112 | 113 | /** 114 | * Dispatched during the recording. 115 | * @param event 116 | */ 117 | private function onSampleData(event:SampleDataEvent):void 118 | { 119 | _recordingEvent.time = getTimer() - _difference; 120 | 121 | dispatchEvent( _recordingEvent ); 122 | 123 | while(event.data.bytesAvailable > 0) 124 | _buffer.writeFloat(event.data.readFloat()); 125 | } 126 | 127 | /** 128 | * Stop recording the audio stream and automatically starts the packaging of the output file. 129 | */ 130 | public function stop():void 131 | { 132 | _microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, onSampleData); 133 | 134 | _buffer.position = 0; 135 | _output = _encoder.encode(_buffer, 1); 136 | 137 | dispatchEvent( _completeEvent ); 138 | } 139 | 140 | /** 141 | * 142 | * @return 143 | * 144 | */ 145 | public function get gain():uint 146 | { 147 | return _gain; 148 | } 149 | 150 | /** 151 | * 152 | * @param value 153 | * 154 | */ 155 | public function set gain(value:uint):void 156 | { 157 | _gain = value; 158 | } 159 | 160 | /** 161 | * 162 | * @return 163 | * 164 | */ 165 | public function get rate():uint 166 | { 167 | return _rate; 168 | } 169 | 170 | /** 171 | * 172 | * @param value 173 | * 174 | */ 175 | public function set rate(value:uint):void 176 | { 177 | _rate = value; 178 | } 179 | 180 | /** 181 | * 182 | * @return 183 | * 184 | */ 185 | public function get silenceLevel():uint 186 | { 187 | return _silenceLevel; 188 | } 189 | 190 | /** 191 | * 192 | * @param value 193 | * 194 | */ 195 | public function set silenceLevel(value:uint):void 196 | { 197 | _silenceLevel = value; 198 | } 199 | 200 | 201 | /** 202 | * 203 | * @return 204 | * 205 | */ 206 | public function get microphone():Microphone 207 | { 208 | return _microphone; 209 | } 210 | 211 | /** 212 | * 213 | * @param value 214 | * 215 | */ 216 | public function set microphone(value:Microphone):void 217 | { 218 | _microphone = value; 219 | } 220 | 221 | /** 222 | * 223 | * @return 224 | * 225 | */ 226 | public function get output():ByteArray 227 | { 228 | return _output; 229 | } 230 | 231 | /** 232 | * 233 | * @return 234 | * 235 | */ 236 | public override function toString():String 237 | { 238 | return "[MicRecorder gain=" + _gain + " rate=" + _rate + " silenceLevel=" + _silenceLevel + " timeOut=" + _timeOut + " microphone:" + _microphone + "]"; 239 | } 240 | } 241 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/encoder/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 89 4 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/encoder 5 | END 6 | WaveEncoder.as 7 | K 25 8 | svn:wc:ra_dav:version-url 9 | V 104 10 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/encoder/WaveEncoder.as 11 | END 12 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/encoder/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 20727 5 | http://sajith@10.2.30.40/muzicall/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/encoder 6 | http://sajith@10.2.30.40/muzicall 7 | 8 | 9 | 10 | 2011-08-31T17:22:19.696868Z 11 | 20727 12 | sajith 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0013cf6a-2276-4056-9bbb-7e8f5601526d 28 | 29 | WaveEncoder.as 30 | file 31 | 32 | 33 | 34 | 35 | 2011-08-31T17:15:30.000000Z 36 | b8e5cfd5f16589ffb43735e504a22662 37 | 2011-08-31T17:22:19.696868Z 38 | 20727 39 | sajith 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 1915 62 | 63 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/encoder/.svn/text-base/WaveEncoder.as.svn-base: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder.encoder 2 | { 3 | import flash.events.Event; 4 | import flash.utils.ByteArray; 5 | import flash.utils.Endian; 6 | 7 | import org.bytearray.micrecorder.IEncoder; 8 | 9 | public class WaveEncoder implements IEncoder 10 | { 11 | private static const RIFF:String = "RIFF"; 12 | private static const WAVE:String = "WAVE"; 13 | private static const FMT:String = "fmt "; 14 | private static const DATA:String = "data"; 15 | 16 | private var _bytes:ByteArray = new ByteArray(); 17 | private var _buffer:ByteArray = new ByteArray(); 18 | private var _volume:Number; 19 | 20 | /** 21 | * 22 | * @param volume 23 | * 24 | */ 25 | public function WaveEncoder( volume:Number=1 ) 26 | { 27 | _volume = volume; 28 | } 29 | 30 | /** 31 | * 32 | * @param samples 33 | * @param channels 34 | * @param bits 35 | * @param rate 36 | * @return 37 | * 38 | */ 39 | public function encode( samples:ByteArray, channels:int=2, bits:int=16, rate:int=44100 ):ByteArray 40 | { 41 | var data:ByteArray = create( samples ); 42 | 43 | _bytes.length = 0; 44 | _bytes.endian = Endian.LITTLE_ENDIAN; 45 | 46 | _bytes.writeUTFBytes( WaveEncoder.RIFF ); 47 | _bytes.writeInt( uint( data.length + 44 ) ); 48 | _bytes.writeUTFBytes( WaveEncoder.WAVE ); 49 | _bytes.writeUTFBytes( WaveEncoder.FMT ); 50 | _bytes.writeInt( uint( 16 ) ); 51 | _bytes.writeShort( uint( 1 ) ); 52 | _bytes.writeShort( channels ); 53 | _bytes.writeInt( rate ); 54 | _bytes.writeInt( uint( rate * channels * ( bits >> 3 ) ) ); 55 | _bytes.writeShort( uint( channels * ( bits >> 3 ) ) ); 56 | _bytes.writeShort( bits ); 57 | _bytes.writeUTFBytes( WaveEncoder.DATA ); 58 | _bytes.writeInt( data.length ); 59 | _bytes.writeBytes( data ); 60 | _bytes.position = 0; 61 | 62 | return _bytes; 63 | } 64 | 65 | private function create( bytes:ByteArray ):ByteArray 66 | { 67 | _buffer.endian = Endian.LITTLE_ENDIAN; 68 | _buffer.length = 0; 69 | bytes.position = 0; 70 | 71 | while( bytes.bytesAvailable ) 72 | _buffer.writeShort( bytes.readFloat() * (0x7fff * _volume) ); 73 | return _buffer; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/encoder/WaveEncoder.as: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder.encoder 2 | { 3 | import flash.events.Event; 4 | import flash.utils.ByteArray; 5 | import flash.utils.Endian; 6 | 7 | import org.bytearray.micrecorder.IEncoder; 8 | 9 | public class WaveEncoder implements IEncoder 10 | { 11 | private static const RIFF:String = "RIFF"; 12 | private static const WAVE:String = "WAVE"; 13 | private static const FMT:String = "fmt "; 14 | private static const DATA:String = "data"; 15 | 16 | private var _bytes:ByteArray = new ByteArray(); 17 | private var _buffer:ByteArray = new ByteArray(); 18 | private var _volume:Number; 19 | 20 | /** 21 | * 22 | * @param volume 23 | * 24 | */ 25 | public function WaveEncoder( volume:Number=1 ) 26 | { 27 | _volume = volume; 28 | } 29 | 30 | /** 31 | * 32 | * @param samples 33 | * @param channels 34 | * @param bits 35 | * @param rate 36 | * @return 37 | * 38 | */ 39 | public function encode( samples:ByteArray, channels:int=2, bits:int=16, rate:int=44100 ):ByteArray 40 | { 41 | var data:ByteArray = create( samples ); 42 | 43 | _bytes.length = 0; 44 | _bytes.endian = Endian.LITTLE_ENDIAN; 45 | 46 | _bytes.writeUTFBytes( WaveEncoder.RIFF ); 47 | _bytes.writeInt( uint( data.length + 44 ) ); 48 | _bytes.writeUTFBytes( WaveEncoder.WAVE ); 49 | _bytes.writeUTFBytes( WaveEncoder.FMT ); 50 | _bytes.writeInt( uint( 16 ) ); 51 | _bytes.writeShort( uint( 1 ) ); 52 | _bytes.writeShort( channels ); 53 | _bytes.writeInt( rate ); 54 | _bytes.writeInt( uint( rate * channels * ( bits >> 3 ) ) ); 55 | _bytes.writeShort( uint( channels * ( bits >> 3 ) ) ); 56 | _bytes.writeShort( bits ); 57 | _bytes.writeUTFBytes( WaveEncoder.DATA ); 58 | _bytes.writeInt( data.length ); 59 | _bytes.writeBytes( data ); 60 | _bytes.position = 0; 61 | 62 | return _bytes; 63 | } 64 | 65 | private function create( bytes:ByteArray ):ByteArray 66 | { 67 | _buffer.endian = Endian.LITTLE_ENDIAN; 68 | _buffer.length = 0; 69 | bytes.position = 0; 70 | 71 | while( bytes.bytesAvailable ) 72 | _buffer.writeShort( bytes.readFloat() * (0x7fff * _volume) ); 73 | return _buffer; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/events/.svn/all-wcprops: -------------------------------------------------------------------------------- 1 | K 25 2 | svn:wc:ra_dav:version-url 3 | V 88 4 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/events 5 | END 6 | RecordingEvent.as 7 | K 25 8 | svn:wc:ra_dav:version-url 9 | V 106 10 | /muzicall/!svn/ver/20727/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/events/RecordingEvent.as 11 | END 12 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/events/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 20727 5 | http://sajith@10.2.30.40/muzicall/ringtagzfb/trunk/htdocs/images/org/bytearray/micrecorder/events 6 | http://sajith@10.2.30.40/muzicall 7 | 8 | 9 | 10 | 2011-08-31T17:22:19.696868Z 11 | 20727 12 | sajith 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 0013cf6a-2276-4056-9bbb-7e8f5601526d 28 | 29 | RecordingEvent.as 30 | file 31 | 32 | 33 | 34 | 35 | 2011-08-31T17:15:30.000000Z 36 | e337acd5afd21510e3fe4b5d12ee73fd 37 | 2011-08-31T17:22:19.696868Z 38 | 20727 39 | sajith 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 745 62 | 63 | -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/events/.svn/text-base/RecordingEvent.as.svn-base: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder.events 2 | { 3 | import flash.events.Event; 4 | 5 | public final class RecordingEvent extends Event 6 | { 7 | public static const RECORDING:String = "recording"; 8 | 9 | private var _time:Number; 10 | 11 | /** 12 | * 13 | * @param type 14 | * @param time 15 | * 16 | */ 17 | public function RecordingEvent(type:String, time:Number) 18 | { 19 | super(type, false, false); 20 | _time = time; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | * 27 | */ 28 | public function get time():Number 29 | { 30 | return _time; 31 | } 32 | 33 | /** 34 | * 35 | * @param value 36 | * 37 | */ 38 | public function set time(value:Number):void 39 | { 40 | _time = value; 41 | } 42 | 43 | /** 44 | * 45 | * @return 46 | * 47 | */ 48 | public override function clone(): Event 49 | { 50 | return new RecordingEvent(type, _time) 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /flash-fla/org/bytearray/micrecorder/events/RecordingEvent.as: -------------------------------------------------------------------------------- 1 | package org.bytearray.micrecorder.events 2 | { 3 | import flash.events.Event; 4 | 5 | public final class RecordingEvent extends Event 6 | { 7 | public static const RECORDING:String = "recording"; 8 | 9 | private var _time:Number; 10 | 11 | /** 12 | * 13 | * @param type 14 | * @param time 15 | * 16 | */ 17 | public function RecordingEvent(type:String, time:Number) 18 | { 19 | super(type, false, false); 20 | _time = time; 21 | } 22 | 23 | /** 24 | * 25 | * @return 26 | * 27 | */ 28 | public function get time():Number 29 | { 30 | return _time; 31 | } 32 | 33 | /** 34 | * 35 | * @param value 36 | * 37 | */ 38 | public function set time(value:Number):void 39 | { 40 | _time = value; 41 | } 42 | 43 | /** 44 | * 45 | * @return 46 | * 47 | */ 48 | public override function clone(): Event 49 | { 50 | return new RecordingEvent(type, _time) 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /html/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/html/.DS_Store -------------------------------------------------------------------------------- /html/acceptfile.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /html/example1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | jRecorder Example 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |

jRecorder Example 1 - Insert flash recorder inside the body tag

29 | 30 |

In this example, you add a flash recorder with some call back function. $.jRecorder function is called with all initial settings. 31 | If the second parameter for $.jRecorder is not there, plugin insert the flash recorder inside the body tag. You can specify where to insert 32 | the flash recorder with second parameter. See example2.html for this. 33 |

34 | 35 |

Download the plugin: jRecorder.zip

36 | 37 | 64 | 65 | 66 | 67 | 68 |
69 | 70 | Time: 00:00 71 | 72 |
73 | 74 | 75 |
76 | Level: 77 |
78 | 79 |
80 | 81 |
82 | 83 |
84 | 85 |
86 | Status: 87 |
88 | 89 | 90 |
91 | 92 | 93 |

This Record button trigger the record event. See the javascript example in the bottom of the page. (View Source in your browser). 94 | 95 |

 96 | $('#record').click(function(){
 97 |                     
 98 |     $.jRecorder.record(30); //record up to 30 sec and stops automatically
 99 |                    
100 |    })
101 | 
102 |

103 | 104 | 105 |
106 | 107 | 108 | 109 |

This Stop button trigger the stop record event. 110 | 111 |

112 |   Onclick of this button trigger  $.jRecorder.sendData() which send the data to the Server
113 |   
114 |
115 | 116 | 117 | 118 | 119 |

This SendData button trigger the sendData event to flash to send the wav data to Server (configured in the host parameter). 120 | 121 | 122 |


123 | 124 |
125 | $('#stop').click(function(){
126 |                     
127 |     $.jRecorder.stop();
128 |                    
129 |    })
130 | 
131 |

132 | 133 | 134 |
135 | 136 | 137 |
138 | 139 | 140 | 141 | 142 |

143 | Time area is used to update the time. There is an event Listener which update the recording time dynamically. 144 |

145 |     
146 |     callback_activityTime:     function(time){callback_activityTime(time);  //see the initialisation
147 |     
148 |     //function callback
149 |     function callback_activityTime(time)
150 |      {
151 |       
152 |       
153 |        $('#time').html(time);
154 |        
155 |      }
156 |     
157 |   
158 |

159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 284 | 285 | -------------------------------------------------------------------------------- /html/example2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | jRecorder Example 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
  • Documentation
  • 19 |
  • Example
  • 20 |
  • Contact
  • 21 |
  • Download
  • 22 | 23 | 24 | 25 |

    jRecorder Example 2 - Insert flash recorder inside a particular element

    26 | 27 |

    In this example, you add a flash recorder with some call back function. $.jRecorder function is called with all initial settings and a second parameter 28 | indicate where to insert this recorder. Call the $.jRecorder script only after the div. (Better to use javascript at the bottom always, or you can use $(document).ready function) See example1.html for inserting this inside body tag. 29 |

    30 | 31 | 32 | 33 | 34 | 35 | 36 |
    37 | 38 | 39 | 40 |
    41 | 42 | 43 | 70 | 71 | 72 | 73 |
    74 | 75 | Time: 00:00 76 | 77 |
    78 | 79 | 80 |
    81 | Level: 82 |
    83 | 84 |
    85 | 86 |
    87 | 88 |
    89 | 90 |
    91 | Status: 92 |
    93 | 94 | 95 |
    96 | 97 | 98 |

    This Record button trigger the record event. See the javascript example in the bottom of the page. (View Source in your browser). 99 | 100 |

    101 | $('#record').click(function(){
    102 |                     
    103 |     $.jRecorder.record(30); //record up to 30 sec and stops automatically
    104 |                    
    105 |    })
    106 | 
    107 |

    108 | 109 | 110 |
    111 | 112 | 113 | 114 |

    This Stop button trigger the stop record event. 115 | 116 |

    117 | $('#stop').click(function(){
    118 |                     
    119 |     $.jRecorder.stop();
    120 |                    
    121 |    })
    122 | 
    123 |

    124 | 125 | 126 |
    127 | 128 | 129 |
    130 | 131 | 132 | 133 | 134 |

    135 | Time area is used to update the time. There is an event Listener which update the recording time dynamically. 136 |

    137 |     
    138 |     callback_activityTime:     function(time){callback_activityTime(time);  //see the initialisation
    139 |     
    140 |     //function callback
    141 |     function callback_activityTime(time)
    142 |      {
    143 |       
    144 |       
    145 |        $('#time').html(time);
    146 |        
    147 |      }
    148 |     
    149 |   
    150 |

    151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 267 | 268 | -------------------------------------------------------------------------------- /html/jRecorder.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jRecorder Plugin for jQuery JavaScript Library (Alpha) 3 | * http://www.sajithmr.me/jrecorder 4 | * 5 | * Copyright (c) 2011 - 2013 Sajithmr.ME 6 | * Dual licensed under the MIT and GPL licenses. 7 | * - http://www.opensource.org/licenses/mit-license.php 8 | * - http://www.gnu.org/copyleft/gpl.html 9 | * 10 | * Author: Sajith Amma 11 | * Version: 1.1 12 | * Date: 14 December 2011 13 | */ 14 | 15 | /* Code is not verified using http://www.jshint.com/ */ 16 | 17 | 18 | (function ($){ 19 | 20 | 21 | var methods = { 22 | play : function( options ) { 23 | 24 | alert(options); 25 | 26 | }, 27 | pause : function( ) { } 28 | 29 | }; 30 | 31 | 32 | var jRecorderSettings = {} ; 33 | 34 | $.jRecorder = function( options, element ) { 35 | // allow instantiation without initializing for simple inheritance 36 | 37 | 38 | if(typeof(options) == "string") 39 | { 40 | if ( methods[options] ) 41 | { 42 | return methods[ options ].apply( this, Array.prototype.slice.call( arguments, 1 )); 43 | 44 | } 45 | return false; 46 | } 47 | 48 | //if the element to be appended is not defind, append to body 49 | if(element == undefined) 50 | { 51 | element = $("body"); 52 | } 53 | 54 | //default settings 55 | var settings = { 56 | 57 | 'rec_width': '300', 58 | 'rec_height': '200', 59 | 'rec_top': '0px', 60 | 'rec_left': '0px', 61 | 'recorderlayout_id' : 'flashrecarea', 62 | 'recorder_id' : 'audiorecorder', 63 | 'recorder_name': 'audiorecorder', 64 | 'wmode' : 'transparent', 65 | 'bgcolor': '#ff0000', 66 | 'swf_path': 'jRecorder.swf', 67 | 'host': 'acceptfile.php?filename=hello.wav', 68 | 'callback_started_recording' : function(){}, 69 | 'callback_finished_recording' : function(){}, 70 | 'callback_stopped_recording': function(){}, 71 | 'callback_error_recording' : function(){}, 72 | 'callback_activityTime': function(time){}, 73 | 'callback_activityLevel' : function(level){} 74 | 75 | 76 | 77 | 78 | 79 | }; 80 | 81 | 82 | //if option array is passed, merget the values 83 | if ( options ) { 84 | $.extend( settings, options ); 85 | } 86 | 87 | jRecorderSettings = settings; 88 | 89 | 90 | 91 | if($.browser.msie && Number($.browser.version) <= 8) { 92 | var objStr = ''; 93 | 94 | var paramStr = [ 95 | '', 96 | 97 | '', 98 | '', 99 | '' 100 | ]; 101 | 102 | htmlObj = document.createElement(objStr); 103 | for(var i=0; i < paramStr.length; i++) { 104 | htmlObj.appendChild(document.createElement(paramStr[i])); 105 | } 106 | 107 | 108 | //var divStr = '
    '; 109 | //var divObj = document.createElement(divStr); 110 | 111 | 112 | } else { 113 | var createParam = function(el, n, v) { 114 | var p = document.createElement("param"); 115 | p.setAttribute("name", n); 116 | p.setAttribute("value", v); 117 | el.appendChild(p); 118 | }; 119 | 120 | htmlObj = document.createElement("object"); 121 | htmlObj.setAttribute("id", settings['recorder_id'] ); 122 | htmlObj.setAttribute("name", settings['recorder_name'] ); 123 | htmlObj.setAttribute("data", settings['swf_path'] + '?host=' + settings['host'] ); 124 | htmlObj.setAttribute("type", "application/x-shockwave-flash"); 125 | htmlObj.setAttribute("width", settings['rec_width']); // Non-zero 126 | htmlObj.setAttribute("height", settings['rec_height']); // Non-zero 127 | 128 | createParam(htmlObj, "allowscriptaccess", "always"); 129 | createParam(htmlObj, "bgcolor", settings['bgcolor']); 130 | createParam(htmlObj, "wmode", settings['wmode'] ); 131 | 132 | 133 | 134 | 135 | } 136 | 137 | 138 | var divObj = document.createElement("div"); 139 | 140 | divObj.setAttribute("id", settings['recorderlayout_id']); 141 | divObj.setAttribute("style", "position:absolute;top:"+ settings['rec_top'] +";left:"+ settings['rec_left'] +";z-index:-1"); 142 | 143 | divObj.appendChild(htmlObj); 144 | 145 | 146 | element.append(divObj); 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | }; 156 | 157 | //function call to start a recording 158 | $.jRecorder.record = function(max_time){ 159 | 160 | 161 | //change z-index to make it top 162 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', 1000); 163 | getFlashMovie(jRecorderSettings['recorder_name']).jStartRecording(max_time); 164 | 165 | 166 | 167 | } 168 | 169 | //function call to stop recording 170 | $.jRecorder.stop = function(){ 171 | 172 | getFlashMovie(jRecorderSettings['recorder_name']).jStopRecording(); 173 | 174 | } 175 | 176 | //function call to send wav data to server url from the init configuration 177 | $.jRecorder.sendData = function(){ 178 | 179 | getFlashMovie(jRecorderSettings['recorder_name']).jSendFileToServer(); 180 | 181 | } 182 | 183 | $.jRecorder.callback_started_recording = function(){ 184 | 185 | 186 | jRecorderSettings['callback_started_recording'](); 187 | 188 | } 189 | 190 | 191 | $.jRecorder.callback_finished_recording = function(){ 192 | 193 | jRecorderSettings['callback_finished_recording'](); 194 | 195 | } 196 | 197 | $.jRecorder.callback_error_recording = function(){ 198 | 199 | jRecorderSettings['callback_error_recording'](); 200 | 201 | } 202 | 203 | $.jRecorder.callback_stopped_recording = function(){ 204 | 205 | jRecorderSettings['callback_stopped_recording'](); 206 | } 207 | 208 | 209 | $.jRecorder.callback_finished_sending = function(){ 210 | 211 | jRecorderSettings['callback_finished_sending'](); 212 | 213 | } 214 | 215 | $.jRecorder.callback_activityLevel = function(level){ 216 | 217 | jRecorderSettings['callback_activityLevel'](level); 218 | 219 | } 220 | 221 | $.jRecorder.callback_activityTime = function(time){ 222 | 223 | //put back flash while recording 224 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', -1); 225 | 226 | jRecorderSettings['callback_activityTime'](time); 227 | 228 | } 229 | 230 | 231 | 232 | 233 | //function to return flash object from name 234 | function getFlashMovie(movieName) { 235 | var isIE = navigator.appName.indexOf("Microsoft") != -1; 236 | return (isIE) ? window[movieName] : document[movieName]; 237 | } 238 | 239 | 240 | 241 | })(jQuery); 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /html/jRecorder.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/html/jRecorder.swf -------------------------------------------------------------------------------- /javascript/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sythoos/jRecorder/8843f1fe7ac5d94550d56e3dfda398978fd9ca66/javascript/.DS_Store -------------------------------------------------------------------------------- /javascript/jRecorder-1.0.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jRecorder Plugin for jQuery JavaScript Library (Alpha) 3 | * http://www.sajithmr.me/jrecorder 4 | * 5 | * Copyright (c) 2011 - 2013 Sajithmr.ME 6 | * Dual licensed under the MIT and GPL licenses. 7 | * - http://www.opensource.org/licenses/mit-license.php 8 | * - http://www.gnu.org/copyleft/gpl.html 9 | * 10 | * Author: Sajith Amma 11 | * Version: 1.0 12 | * Date: 26 October 2011 13 | */ 14 | 15 | /* Code is not verified using http://www.jshint.com/ */ 16 | 17 | 18 | 19 | 20 | (function ($){ 21 | 22 | 23 | var methods = { 24 | play : function( options ) { 25 | 26 | alert(options); 27 | 28 | }, 29 | pause : function( ) { } 30 | 31 | }; 32 | 33 | 34 | var jRecorderSettings = {} ; 35 | 36 | $.jRecorder = function( options, element ) { 37 | // allow instantiation without initializing for simple inheritance 38 | 39 | 40 | if(typeof(options) == "string") 41 | { 42 | if ( methods[options] ) 43 | { 44 | return methods[ options ].apply( this, Array.prototype.slice.call( arguments, 1 )); 45 | 46 | } 47 | return false; 48 | } 49 | 50 | //if the element to be appended is not defind, append to body 51 | if(element == undefined) 52 | { 53 | element = $("body"); 54 | } 55 | 56 | //default settings 57 | var settings = { 58 | 59 | 'rec_width': '300', 60 | 'rec_height': '200', 61 | 'rec_top': '0px', 62 | 'rec_left': '0px', 63 | 'recorderlayout_id' : 'flashrecarea', 64 | 'recorder_id' : 'audiorecorder', 65 | 'recorder_name': 'audiorecorder', 66 | 'wmode' : 'transparent', 67 | 'bgcolor': '#ff0000', 68 | 'swf_path': 'jRecorder.swf', 69 | 'host': 'acceptfile.php?filename=hello.wav', 70 | 'callback_started_recording' : function(){}, 71 | 'callback_finished_recording' : function(){}, 72 | 'callback_stopped_recording': function(){}, 73 | 'callback_error_recording' : function(){}, 74 | 'callback_activityTime': function(time){}, 75 | 'callback_activityLevel' : function(level){} 76 | 77 | 78 | 79 | 80 | 81 | }; 82 | 83 | 84 | //if option array is passed, merget the values 85 | if ( options ) { 86 | $.extend( settings, options ); 87 | } 88 | 89 | jRecorderSettings = settings; 90 | 91 | 92 | 93 | if($.browser.msie && Number($.browser.version) <= 8) { 94 | var objStr = ''; 95 | 96 | var paramStr = [ 97 | '', 98 | 99 | '', 100 | '', 101 | '' 102 | ]; 103 | 104 | htmlObj = document.createElement(objStr); 105 | for(var i=0; i < paramStr.length; i++) { 106 | htmlObj.appendChild(document.createElement(paramStr[i])); 107 | } 108 | 109 | 110 | //var divStr = '
    '; 111 | //var divObj = document.createElement(divStr); 112 | 113 | 114 | } else { 115 | var createParam = function(el, n, v) { 116 | var p = document.createElement("param"); 117 | p.setAttribute("name", n); 118 | p.setAttribute("value", v); 119 | el.appendChild(p); 120 | }; 121 | 122 | htmlObj = document.createElement("object"); 123 | htmlObj.setAttribute("id", settings['recorder_id'] ); 124 | htmlObj.setAttribute("name", settings['recorder_name'] ); 125 | htmlObj.setAttribute("data", settings['swf_path'] + '?host=' + settings['host'] ); 126 | htmlObj.setAttribute("type", "application/x-shockwave-flash"); 127 | htmlObj.setAttribute("width", settings['rec_width']); // Non-zero 128 | htmlObj.setAttribute("height", settings['rec_height']); // Non-zero 129 | 130 | createParam(htmlObj, "allowscriptaccess", "always"); 131 | createParam(htmlObj, "bgcolor", settings['bgcolor']); 132 | createParam(htmlObj, "wmode", settings['wmode'] ); 133 | 134 | 135 | 136 | 137 | } 138 | 139 | 140 | var divObj = document.createElement("div"); 141 | 142 | divObj.setAttribute("id", settings['recorderlayout_id']); 143 | divObj.setAttribute("style", "position:absolute;top:"+ settings['rec_top'] +";left:"+ settings['rec_left'] +";z-index:-1"); 144 | 145 | divObj.appendChild(htmlObj); 146 | 147 | 148 | 149 | element.append(divObj); 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | }; 159 | 160 | //function call to start a recording 161 | $.jRecorder.record = function(max_time){ 162 | 163 | 164 | //change z-index to make it top 165 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', 1000); 166 | getFlashMovie(jRecorderSettings['recorder_name']).jStartRecording(max_time); 167 | 168 | 169 | 170 | } 171 | 172 | //function call to stop recording 173 | $.jRecorder.stop = function(){ 174 | 175 | getFlashMovie(jRecorderSettings['recorder_name']).jStopRecording(); 176 | 177 | } 178 | 179 | 180 | $.jRecorder.callback_started_recording = function(){ 181 | 182 | 183 | jRecorderSettings['callback_started_recording'](); 184 | 185 | } 186 | 187 | 188 | $.jRecorder.callback_finished_recording = function(){ 189 | 190 | jRecorderSettings['callback_finished_recording'](); 191 | 192 | } 193 | 194 | $.jRecorder.callback_error_recording = function(){ 195 | 196 | jRecorderSettings['callback_error_recording'](); 197 | 198 | } 199 | 200 | $.jRecorder.callback_stopped_recording = function(){ 201 | 202 | jRecorderSettings['callback_stopped_recording'](); 203 | } 204 | 205 | 206 | $.jRecorder.callback_finished_sending = function(){ 207 | 208 | jRecorderSettings['callback_finished_sending'](); 209 | 210 | } 211 | 212 | $.jRecorder.callback_activityLevel = function(level){ 213 | 214 | jRecorderSettings['callback_activityLevel'](level); 215 | 216 | } 217 | 218 | $.jRecorder.callback_activityTime = function(time){ 219 | 220 | //put back flash while recording 221 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', -1); 222 | 223 | jRecorderSettings['callback_activityTime'](time); 224 | 225 | } 226 | 227 | 228 | 229 | 230 | //function to return flash object from name 231 | function getFlashMovie(movieName) { 232 | var isIE = navigator.appName.indexOf("Microsoft") != -1; 233 | return (isIE) ? window[movieName] : document[movieName]; 234 | } 235 | 236 | 237 | 238 | })(jQuery); 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /javascript/jRecorder-1.1.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jRecorder Plugin for jQuery JavaScript Library (Alpha) 3 | * http://www.sajithmr.me/jrecorder 4 | * 5 | * Copyright (c) 2011 - 2013 Sajithmr.ME 6 | * Dual licensed under the MIT and GPL licenses. 7 | * - http://www.opensource.org/licenses/mit-license.php 8 | * - http://www.gnu.org/copyleft/gpl.html 9 | * 10 | * Author: Sajith Amma 11 | * Version: 1.1 12 | * Date: 14 December 2011 13 | */ 14 | 15 | /* Code is not verified using http://www.jshint.com/ */ 16 | 17 | 18 | (function ($){ 19 | 20 | 21 | var methods = { 22 | play : function( options ) { 23 | 24 | alert(options); 25 | 26 | }, 27 | pause : function( ) { } 28 | 29 | }; 30 | 31 | 32 | var jRecorderSettings = {} ; 33 | 34 | $.jRecorder = function( options, element ) { 35 | // allow instantiation without initializing for simple inheritance 36 | 37 | 38 | if(typeof(options) == "string") 39 | { 40 | if ( methods[options] ) 41 | { 42 | return methods[ options ].apply( this, Array.prototype.slice.call( arguments, 1 )); 43 | 44 | } 45 | return false; 46 | } 47 | 48 | //if the element to be appended is not defind, append to body 49 | if(element == undefined) 50 | { 51 | element = $("body"); 52 | } 53 | 54 | //default settings 55 | var settings = { 56 | 57 | 'rec_width': '300', 58 | 'rec_height': '200', 59 | 'rec_top': '0px', 60 | 'rec_left': '0px', 61 | 'recorderlayout_id' : 'flashrecarea', 62 | 'recorder_id' : 'audiorecorder', 63 | 'recorder_name': 'audiorecorder', 64 | 'wmode' : 'transparent', 65 | 'bgcolor': '#ff0000', 66 | 'swf_path': 'jRecorder.swf', 67 | 'host': 'acceptfile.php?filename=hello.wav', 68 | 'callback_started_recording' : function(){}, 69 | 'callback_finished_recording' : function(){}, 70 | 'callback_stopped_recording': function(){}, 71 | 'callback_error_recording' : function(){}, 72 | 'callback_activityTime': function(time){}, 73 | 'callback_activityLevel' : function(level){} 74 | 75 | 76 | 77 | 78 | 79 | }; 80 | 81 | 82 | //if option array is passed, merget the values 83 | if ( options ) { 84 | $.extend( settings, options ); 85 | } 86 | 87 | jRecorderSettings = settings; 88 | 89 | 90 | 91 | if($.browser.msie && Number($.browser.version) <= 8) { 92 | var objStr = ''; 93 | 94 | var paramStr = [ 95 | '', 96 | 97 | '', 98 | '', 99 | '' 100 | ]; 101 | 102 | htmlObj = document.createElement(objStr); 103 | for(var i=0; i < paramStr.length; i++) { 104 | htmlObj.appendChild(document.createElement(paramStr[i])); 105 | } 106 | 107 | 108 | //var divStr = '
    '; 109 | //var divObj = document.createElement(divStr); 110 | 111 | 112 | } else { 113 | var createParam = function(el, n, v) { 114 | var p = document.createElement("param"); 115 | p.setAttribute("name", n); 116 | p.setAttribute("value", v); 117 | el.appendChild(p); 118 | }; 119 | 120 | htmlObj = document.createElement("object"); 121 | htmlObj.setAttribute("id", settings['recorder_id'] ); 122 | htmlObj.setAttribute("name", settings['recorder_name'] ); 123 | htmlObj.setAttribute("data", settings['swf_path'] + '?host=' + settings['host'] ); 124 | htmlObj.setAttribute("type", "application/x-shockwave-flash"); 125 | htmlObj.setAttribute("width", settings['rec_width']); // Non-zero 126 | htmlObj.setAttribute("height", settings['rec_height']); // Non-zero 127 | 128 | createParam(htmlObj, "allowscriptaccess", "always"); 129 | createParam(htmlObj, "bgcolor", settings['bgcolor']); 130 | createParam(htmlObj, "wmode", settings['wmode'] ); 131 | 132 | 133 | 134 | 135 | } 136 | 137 | 138 | var divObj = document.createElement("div"); 139 | 140 | divObj.setAttribute("id", settings['recorderlayout_id']); 141 | divObj.setAttribute("style", "position:absolute;top:"+ settings['rec_top'] +";left:"+ settings['rec_left'] +";z-index:-1"); 142 | 143 | divObj.appendChild(htmlObj); 144 | 145 | 146 | element.append(divObj); 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | }; 156 | 157 | //function call to start a recording 158 | $.jRecorder.record = function(max_time){ 159 | 160 | 161 | //change z-index to make it top 162 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', 1000); 163 | getFlashMovie(jRecorderSettings['recorder_name']).jStartRecording(max_time); 164 | 165 | 166 | 167 | } 168 | 169 | //function call to stop recording 170 | $.jRecorder.stop = function(){ 171 | 172 | getFlashMovie(jRecorderSettings['recorder_name']).jStopRecording(); 173 | 174 | } 175 | 176 | //function call to send wav data to server url from the init configuration 177 | $.jRecorder.sendData = function(){ 178 | 179 | getFlashMovie(jRecorderSettings['recorder_name']).jSendFileToServer(); 180 | 181 | } 182 | 183 | $.jRecorder.callback_started_recording = function(){ 184 | 185 | 186 | jRecorderSettings['callback_started_recording'](); 187 | 188 | } 189 | 190 | 191 | $.jRecorder.callback_finished_recording = function(){ 192 | 193 | jRecorderSettings['callback_finished_recording'](); 194 | 195 | } 196 | 197 | $.jRecorder.callback_error_recording = function(){ 198 | 199 | jRecorderSettings['callback_error_recording'](); 200 | 201 | } 202 | 203 | $.jRecorder.callback_stopped_recording = function(){ 204 | 205 | jRecorderSettings['callback_stopped_recording'](); 206 | } 207 | 208 | 209 | $.jRecorder.callback_finished_sending = function(){ 210 | 211 | jRecorderSettings['callback_finished_sending'](); 212 | 213 | } 214 | 215 | $.jRecorder.callback_activityLevel = function(level){ 216 | 217 | jRecorderSettings['callback_activityLevel'](level); 218 | 219 | } 220 | 221 | $.jRecorder.callback_activityTime = function(time){ 222 | 223 | //put back flash while recording 224 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', -1); 225 | 226 | jRecorderSettings['callback_activityTime'](time); 227 | 228 | } 229 | 230 | 231 | 232 | 233 | //function to return flash object from name 234 | function getFlashMovie(movieName) { 235 | var isIE = navigator.appName.indexOf("Microsoft") != -1; 236 | return (isIE) ? window[movieName] : document[movieName]; 237 | } 238 | 239 | 240 | 241 | })(jQuery); 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /javascript/jRecorder.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jRecorder Plugin for jQuery JavaScript Library (Alpha) 3 | * http://www.sajithmr.me/jrecorder 4 | * 5 | * Copyright (c) 2011 - 2013 Sajithmr.ME 6 | * Dual licensed under the MIT and GPL licenses. 7 | * - http://www.opensource.org/licenses/mit-license.php 8 | * - http://www.gnu.org/copyleft/gpl.html 9 | * 10 | * Author: Sajith Amma 11 | * Version: 1.1 12 | * Date: 14 December 2011 13 | 14 | Version changes 15 | 16 | Added preview option right after recording. 17 | Added seperate function sendData to trigger to send data to server (it won't send automcatically to server) 18 | 19 | 20 | */ 21 | 22 | /* Code is not verified using http://www.jshint.com/ */ 23 | 24 | 25 | (function ($){ 26 | 27 | 28 | var methods = { 29 | play : function( options ) { 30 | 31 | alert(options); 32 | 33 | }, 34 | pause : function( ) { } 35 | 36 | }; 37 | 38 | 39 | var jRecorderSettings = {} ; 40 | 41 | $.jRecorder = function( options, element ) { 42 | // allow instantiation without initializing for simple inheritance 43 | 44 | 45 | if(typeof(options) == "string") 46 | { 47 | if ( methods[options] ) 48 | { 49 | return methods[ options ].apply( this, Array.prototype.slice.call( arguments, 1 )); 50 | 51 | } 52 | return false; 53 | } 54 | 55 | //if the element to be appended is not defind, append to body 56 | if(element == undefined) 57 | { 58 | element = $("body"); 59 | } 60 | 61 | //default settings 62 | var settings = { 63 | 64 | 'rec_width': '300', 65 | 'rec_height': '200', 66 | 'rec_top': '0px', 67 | 'rec_left': '0px', 68 | 'recorderlayout_id' : 'flashrecarea', 69 | 'recorder_id' : 'audiorecorder', 70 | 'recorder_name': 'audiorecorder', 71 | 'wmode' : 'transparent', 72 | 'bgcolor': '#ff0000', 73 | 'swf_path': 'jRecorder.swf', 74 | 'host': 'acceptfile.php?filename=hello.wav', 75 | 'callback_started_recording' : function(){}, 76 | 'callback_finished_recording' : function(){}, 77 | 'callback_stopped_recording': function(){}, 78 | 'callback_error_recording' : function(){}, 79 | 'callback_activityTime': function(time){}, 80 | 'callback_activityLevel' : function(level){} 81 | 82 | 83 | 84 | 85 | 86 | }; 87 | 88 | 89 | //if option array is passed, merget the values 90 | if ( options ) { 91 | $.extend( settings, options ); 92 | } 93 | 94 | jRecorderSettings = settings; 95 | 96 | 97 | 98 | if($.browser.msie && Number($.browser.version) <= 8) { 99 | var objStr = ''; 100 | 101 | var paramStr = [ 102 | '', 103 | 104 | '', 105 | '', 106 | '' 107 | ]; 108 | 109 | htmlObj = document.createElement(objStr); 110 | for(var i=0; i < paramStr.length; i++) { 111 | htmlObj.appendChild(document.createElement(paramStr[i])); 112 | } 113 | 114 | 115 | //var divStr = '
    '; 116 | //var divObj = document.createElement(divStr); 117 | 118 | 119 | } else { 120 | var createParam = function(el, n, v) { 121 | var p = document.createElement("param"); 122 | p.setAttribute("name", n); 123 | p.setAttribute("value", v); 124 | el.appendChild(p); 125 | }; 126 | 127 | htmlObj = document.createElement("object"); 128 | htmlObj.setAttribute("id", settings['recorder_id'] ); 129 | htmlObj.setAttribute("name", settings['recorder_name'] ); 130 | htmlObj.setAttribute("data", settings['swf_path'] + '?host=' + settings['host'] ); 131 | htmlObj.setAttribute("type", "application/x-shockwave-flash"); 132 | htmlObj.setAttribute("width", settings['rec_width']); // Non-zero 133 | htmlObj.setAttribute("height", settings['rec_height']); // Non-zero 134 | 135 | createParam(htmlObj, "allowscriptaccess", "always"); 136 | createParam(htmlObj, "bgcolor", settings['bgcolor']); 137 | createParam(htmlObj, "wmode", settings['wmode'] ); 138 | 139 | 140 | 141 | 142 | } 143 | 144 | 145 | var divObj = document.createElement("div"); 146 | 147 | divObj.setAttribute("id", settings['recorderlayout_id']); 148 | divObj.setAttribute("style", "position:absolute;top:"+ settings['rec_top'] +";left:"+ settings['rec_left'] +";z-index:-1"); 149 | 150 | divObj.appendChild(htmlObj); 151 | 152 | 153 | element.append(divObj); 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | }; 163 | 164 | //function call to start a recording 165 | $.jRecorder.record = function(max_time){ 166 | 167 | 168 | //change z-index to make it top 169 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', 1000); 170 | getFlashMovie(jRecorderSettings['recorder_name']).jStartRecording(max_time); 171 | 172 | 173 | 174 | } 175 | 176 | //function call to stop recording 177 | $.jRecorder.stop = function(){ 178 | 179 | getFlashMovie(jRecorderSettings['recorder_name']).jStopRecording(); 180 | 181 | } 182 | 183 | //function call to send wav data to server url from the init configuration 184 | $.jRecorder.sendData = function(){ 185 | 186 | getFlashMovie(jRecorderSettings['recorder_name']).jSendFileToServer(); 187 | 188 | } 189 | 190 | $.jRecorder.callback_started_recording = function(){ 191 | 192 | 193 | jRecorderSettings['callback_started_recording'](); 194 | 195 | } 196 | 197 | 198 | $.jRecorder.callback_finished_recording = function(){ 199 | 200 | jRecorderSettings['callback_finished_recording'](); 201 | 202 | } 203 | 204 | $.jRecorder.callback_error_recording = function(){ 205 | 206 | jRecorderSettings['callback_error_recording'](); 207 | 208 | } 209 | 210 | $.jRecorder.callback_stopped_recording = function(){ 211 | 212 | jRecorderSettings['callback_stopped_recording'](); 213 | } 214 | 215 | 216 | $.jRecorder.callback_finished_sending = function(){ 217 | 218 | jRecorderSettings['callback_finished_sending'](); 219 | 220 | } 221 | 222 | $.jRecorder.callback_activityLevel = function(level){ 223 | 224 | jRecorderSettings['callback_activityLevel'](level); 225 | 226 | } 227 | 228 | $.jRecorder.callback_activityTime = function(time){ 229 | 230 | //put back flash while recording 231 | $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', -1); 232 | 233 | jRecorderSettings['callback_activityTime'](time); 234 | 235 | } 236 | 237 | 238 | 239 | 240 | //function to return flash object from name 241 | function getFlashMovie(movieName) { 242 | var isIE = navigator.appName.indexOf("Microsoft") != -1; 243 | return (isIE) ? window[movieName] : document[movieName]; 244 | } 245 | 246 | 247 | 248 | })(jQuery); 249 | 250 | 251 | 252 | --------------------------------------------------------------------------------