Permalink
Browse files

Merge branch 'master' of github.com:purplecabbage/incubator-cordova-wp7

  • Loading branch information...
purplecabbage committed Nov 9, 2012
2 parents 7979288 + 502480b commit a481d7877ee025d9a61a3419c7e342bf20f6518c
View
@@ -1 +1 @@
-2.2.0rc2
+2.2.0
@@ -1,6 +1,6 @@
-// commit faea9fb423e7dffb60b10d378cf089cdb48c6cf0
+// commit 02b91c5313ff37d74a58f71775170afd360f4a1f
-// File generated at :: Fri Oct 26 2012 13:39:25 GMT-0700 (Pacific Daylight Time)
+// File generated at :: Wed Oct 31 2012 15:32:45 GMT-0700 (Pacific Daylight Time)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -2638,7 +2638,7 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
errorCallback(error);
};
- exec(win, errorCallback, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
+ exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
};
/**
@@ -86,6 +86,9 @@
<Compile Include="..\templates\standalone\cordovalib\Commands\Accelerometer.cs">
<Link>CordovaLib\Commands\Accelerometer.cs</Link>
</Compile>
+ <Compile Include="..\templates\standalone\cordovalib\Commands\AudioFormatsHelper.cs">
+ <Link>CordovaLib\Commands\AudioFormatsHelper.cs</Link>
+ </Compile>
<Compile Include="..\templates\standalone\cordovalib\Commands\AudioPlayer.cs">
<Link>CordovaLib\Commands\AudioPlayer.cs</Link>
</Compile>
View
@@ -1 +1 @@
-2.2.0rc2
+2.2.0
@@ -1,6 +1,6 @@
-// commit faea9fb423e7dffb60b10d378cf089cdb48c6cf0
+// commit 02b91c5313ff37d74a58f71775170afd360f4a1f
-// File generated at :: Fri Oct 26 2012 13:39:25 GMT-0700 (Pacific Daylight Time)
+// File generated at :: Wed Oct 31 2012 15:32:45 GMT-0700 (Pacific Daylight Time)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -2638,7 +2638,7 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
errorCallback(error);
};
- exec(win, errorCallback, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
+ exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
};
/**
@@ -87,6 +87,7 @@
<Compile Include="cordovalib\BrowserMouseHelper.cs" />
<Compile Include="cordovalib\CommandFactory.cs" />
<Compile Include="cordovalib\Commands\Accelerometer.cs" />
+ <Compile Include="cordovalib\Commands\AudioFormatsHelper.cs" />
<Compile Include="cordovalib\Commands\AudioPlayer.cs" />
<Compile Include="cordovalib\Commands\BaseCommand.cs" />
<Compile Include="cordovalib\Commands\Battery.cs" />
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is auto-generated, do not edit! -jm -->
<CordovaSourceDictionary>
+ <FilePath Value="www\cordova-2.2.0.js"/>
<FilePath Value="www\img\logo.png"/>
<FilePath Value="www\js\index.js"/>
- <FilePath Value="www\cordova-2.1.0.js"/>
<FilePath Value="www\css\index.css"/>
<FilePath Value="www\index.html"/>
</CordovaSourceDictionary>
@@ -1 +1 @@
-2.2.0rc2
+2.2.0
@@ -0,0 +1,89 @@
+/*
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+
+using System;
+using System.IO;
+
+namespace WP7CordovaClassLib.Cordova.Commands
+{
+ /// <summary>
+ /// Provides extra functionality to support different audio formats.
+ /// </summary>
+ public static class AudioFormatsHelper
+ {
+ #region Wav
+ /// <summary>
+ /// Adds wav file format header to the stream
+ /// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
+ /// </summary>
+ /// <param name="stream">The stream</param>
+ /// <param name="sampleRate">Sample Rate</param>
+ public static void InitializeWavStream(this Stream stream, int sampleRate)
+ {
+ #region args checking
+
+ if (stream == null)
+ {
+ throw new ArgumentNullException("stream can't be null or empty");
+ }
+
+ #endregion
+
+ int numBits = 16;
+ int numBytes = numBits / 8;
+
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"), 0, 4);
+ stream.Write(BitConverter.GetBytes(0), 0, 4);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"), 0, 4);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("fmt "), 0, 4);
+ stream.Write(BitConverter.GetBytes(16), 0, 4);
+ stream.Write(BitConverter.GetBytes((short)1), 0, 2);
+ stream.Write(BitConverter.GetBytes((short)1), 0, 2);
+ stream.Write(BitConverter.GetBytes(sampleRate), 0, 4);
+ stream.Write(BitConverter.GetBytes(sampleRate * numBytes), 0, 4);
+ stream.Write(BitConverter.GetBytes((short)(numBytes)), 0, 2);
+ stream.Write(BitConverter.GetBytes((short)(numBits)), 0, 2);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("data"), 0, 4);
+ stream.Write(BitConverter.GetBytes(0), 0, 4);
+ }
+
+ /// <summary>
+ /// Updates wav file format header
+ /// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
+ /// </summary>
+ /// <param name="stream">Wav stream</param>
+ public static void UpdateWavStream(this Stream stream)
+ {
+ #region args checking
+
+ if (stream == null)
+ {
+ throw new ArgumentNullException("stream can't be null or empty");
+ }
+
+ #endregion
+
+ var position = stream.Position;
+
+ stream.Seek(4, SeekOrigin.Begin);
+ stream.Write(BitConverter.GetBytes((int)stream.Length - 8), 0, 4);
+ stream.Seek(40, SeekOrigin.Begin);
+ stream.Write(BitConverter.GetBytes((int)stream.Length - 44), 0, 4);
+ stream.Seek(position, SeekOrigin.Begin);
+ }
+
+ #endregion
+ }
+}
@@ -168,7 +168,7 @@ public void startRecording(string filePath)
this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)];
this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady);
this.memoryStream = new MemoryStream();
- this.WriteWavHeader(this.memoryStream, this.recorder.SampleRate);
+ this.memoryStream.InitializeWavStream(this.recorder.SampleRate);
this.recorder.Start();
FrameworkDispatcher.Update();
this.SetState(PlayerState_Running);
@@ -495,7 +495,7 @@ private void SaveAudioClipToLocalStorage()
return;
}
- this.UpdateWavHeader(this.memoryStream);
+ this.memoryStream.UpdateWavStream();
try
{
@@ -521,88 +521,7 @@ private void SaveAudioClipToLocalStorage()
//TODO: log or do something else
throw;
}
- }
-
-
-
- #region Wav format
- // Original source http://damianblog.com/2011/02/07/storing-wp7-recorded-audio-as-wav-format-streams/
-
- /// <summary>
- /// Adds wav file format header to the stream
- /// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
- /// </summary>
- /// <param name="stream">Wav stream</param>
- /// <param name="sampleRate">Sample Rate</param>
- private void WriteWavHeader(Stream stream, int sampleRate)
- {
- const int bitsPerSample = 16;
- const int bytesPerSample = bitsPerSample / 8;
- var encoding = System.Text.Encoding.UTF8;
-
- // ChunkID Contains the letters "RIFF" in ASCII form (0x52494646 big-endian form).
- stream.Write(encoding.GetBytes("RIFF"), 0, 4);
-
- // NOTE this will be filled in later
- stream.Write(BitConverter.GetBytes(0), 0, 4);
-
- // Format Contains the letters "WAVE"(0x57415645 big-endian form).
- stream.Write(encoding.GetBytes("WAVE"), 0, 4);
-
- // Subchunk1ID Contains the letters "fmt " (0x666d7420 big-endian form).
- stream.Write(encoding.GetBytes("fmt "), 0, 4);
-
- // Subchunk1Size 16 for PCM. This is the size of therest of the Subchunk which follows this number.
- stream.Write(BitConverter.GetBytes(16), 0, 4);
-
- // AudioFormat PCM = 1 (i.e. Linear quantization) Values other than 1 indicate some form of compression.
- stream.Write(BitConverter.GetBytes((short)1), 0, 2);
-
- // NumChannels Mono = 1, Stereo = 2, etc.
- stream.Write(BitConverter.GetBytes((short)1), 0, 2);
-
- // SampleRate 8000, 44100, etc.
- stream.Write(BitConverter.GetBytes(sampleRate), 0, 4);
-
- // ByteRate = SampleRate * NumChannels * BitsPerSample/8
- stream.Write(BitConverter.GetBytes(sampleRate * bytesPerSample), 0, 4);
-
- // BlockAlign NumChannels * BitsPerSample/8 The number of bytes for one sample including all channels.
- stream.Write(BitConverter.GetBytes((short)(bytesPerSample)), 0, 2);
-
- // BitsPerSample 8 bits = 8, 16 bits = 16, etc.
- stream.Write(BitConverter.GetBytes((short)(bitsPerSample)), 0, 2);
-
- // Subchunk2ID Contains the letters "data" (0x64617461 big-endian form).
- stream.Write(encoding.GetBytes("data"), 0, 4);
-
- // NOTE to be filled in later
- stream.Write(BitConverter.GetBytes(0), 0, 4);
- }
-
- /// <summary>
- /// Updates wav file format header
- /// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
- /// </summary>
- /// <param name="stream">Wav stream</param>
- private void UpdateWavHeader(Stream stream)
- {
- if (!stream.CanSeek) throw new Exception("Can't seek stream to update wav header");
-
- var oldPos = stream.Position;
-
- // ChunkSize 36 + SubChunk2Size
- stream.Seek(4, SeekOrigin.Begin);
- stream.Write(BitConverter.GetBytes((int)stream.Length - 8), 0, 4);
-
- // Subchunk2Size == NumSamples * NumChannels * BitsPerSample/8 This is the number of bytes in the data.
- stream.Seek(40, SeekOrigin.Begin);
- stream.Write(BitConverter.GetBytes((int)stream.Length - 44), 0, 4);
-
- stream.Seek(oldPos, SeekOrigin.Begin);
- }
-
- #endregion
+ }
#region Xna loop
/// <summary>
@@ -622,8 +541,11 @@ private void InitializeXnaGameLoop()
private void FinalizeXnaGameLoop()
{
// Timer to simulate the XNA game loop (Microphone is from XNA)
- this.dtXna.Stop();
- this.dtXna = null;
+ if (this.dtXna != null)
+ {
+ this.dtXna.Stop();
+ this.dtXna = null;
+ }
}
#endregion
Oops, something went wrong.

0 comments on commit a481d78

Please sign in to comment.