From 6dc3021470fb8cb8204709670a5018e154433ac6 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 30 Apr 2009 01:03:06 +0000 Subject: [PATCH] initial checkin. svn path=/trunk/mooncodecs/; revision=133146 --- ChangeLog | 3 + Makefile | 9 + README | 15 + csadpcm/Makefile | 28 + csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs | 176 ++++++ csadpcm/MoonAdpcm/MoonAdpcm.csproj | 59 ++ csadpcm/MoonAdpcm/StringExtensions.cs | 101 +++ csadpcm/MoonAdpcm/WaveFormatExtensible.cs | 121 ++++ csadpcm/MoonAdpcmTest/App.xaml | 8 + csadpcm/MoonAdpcmTest/App.xaml.cs | 66 ++ csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj | 75 +++ csadpcm/MoonAdpcmTest/Page.xaml | 9 + csadpcm/MoonAdpcmTest/Page.xaml.cs | 33 + .../MoonAdpcmTest/Properties/AppManifest.xml | 6 + .../MoonAdpcmTest/Properties/AssemblyInfo.cs | 35 ++ csadpcm/README | 5 + csadpcm/csadpcm/.IMA_ADPCM~.cs | 299 +++++++++ csadpcm/csadpcm/ImaAdpcm.cs | 299 +++++++++ csadpcm/csadpcm/csadpcm.csproj | 37 ++ csadpcm/csadpcm/csadpcm.moonlight.csproj | 54 ++ csadpcm/moonadpcm.sln | 33 + csdirac/DiracStreamSource.cs | 97 +++ csdirac/DiractTest/ArithTest.cs | 59 ++ csdirac/DiractTest/DecoderTest.cs | 134 ++++ csdirac/DiractTest/DiractTest.csproj | 61 ++ csdirac/DiractTest/GeneralTest.cs | 89 +++ csdirac/DiractTest/Properties/AssemblyInfo.cs | 36 ++ csdirac/DiractTest/UnpackTest.cs | 114 ++++ csdirac/DiractTest/Wavelet2dTest.cs | 73 +++ csdirac/Makefile | 30 + csdirac/Math/Dimension.cs | 19 + csdirac/Math/Point.cs | 20 + csdirac/MoonDirac.csproj | 65 ++ csdirac/MoonDirac/DiracStreamSource.cs | 82 +++ csdirac/MoonDiracTest.csproj | 77 +++ csdirac/MoonDiracTest/App.xaml | 8 + csdirac/MoonDiracTest/App.xaml.cs | 66 ++ csdirac/MoonDiracTest/App.xaml.g.cs | 35 ++ csdirac/MoonDiracTest/Page.xaml | 9 + csdirac/MoonDiracTest/Page.xaml.cs | 33 + csdirac/MoonDiracTest/Page.xaml.g.cs | 38 ++ .../MoonDiracTest/Properties/AppManifest.xml | 6 + csdirac/Properties/AssemblyInfo.cs | 36 ++ csdirac/TestResult.xml | 39 ++ csdirac/csdirac.csproj | 76 +++ csdirac/csdirac.moonlight.csproj | 79 +++ csdirac/csdirac.sln | 26 + csdirac/csdirac/Arithmetic.cs | 260 ++++++++ csdirac/csdirac/Block.cs | 197 ++++++ csdirac/csdirac/Buffer.cs | 61 ++ csdirac/csdirac/Cache.cs | 64 ++ csdirac/csdirac/ColourSpace.cs | 75 +++ csdirac/csdirac/Decoder.cs | 114 ++++ csdirac/csdirac/Global.cs | 22 + csdirac/csdirac/Motion.cs | 514 ++++++++++++++++ csdirac/csdirac/Parameters.cs | 121 ++++ csdirac/csdirac/Picture.cs | 348 +++++++++++ csdirac/csdirac/Queue.cs | 137 +++++ csdirac/csdirac/Slice.cs | 11 + csdirac/csdirac/Stream.cs | 51 ++ csdirac/csdirac/SubBand.cs | 208 +++++++ csdirac/csdirac/Unpack.cs | 234 +++++++ csdirac/csdirac/Util.cs | 58 ++ csdirac/csdirac/Vector.cs | 70 +++ csdirac/csdirac/VideoFormat.cs | 280 +++++++++ csdirac/csdirac/Wavelet.cs | 297 +++++++++ csdirac/csiracTest.VisualState.xml | 120 ++++ csdirac/csiracTest.nunit | 7 + csdirac/moondirac.sln | 33 + csdirac/test/App.xaml | 8 + csdirac/test/App.xaml.cs | 66 ++ csdirac/test/App.xaml.g.cs | 35 ++ csdirac/test/AppManifest.xaml | 7 + csdirac/test/Page.xaml | 9 + csdirac/test/Page.xaml.cs | 33 + csdirac/test/Page.xaml.g.cs | 38 ++ csdirac/test/test.g.resources | Bin 0 -> 905 bytes csdirac/test/test.html | 74 +++ csvorbis/Makefile | 30 + csvorbis/Makefile.moon | 35 ++ csvorbis/MoonVorbis/MoonVorbis.csproj | 77 +++ csvorbis/MoonVorbis/OggMediaStreamSource.cs | 459 ++++++++++++++ csvorbis/MoonVorbis/StringExtensions.cs | 101 +++ csvorbis/MoonVorbis/WaveFormatExtensible.cs | 121 ++++ csvorbis/MoonVorbisTest/App.xaml | 8 + csvorbis/MoonVorbisTest/App.xaml.cs | 66 ++ csvorbis/MoonVorbisTest/MoonVorbisTest.csproj | 110 ++++ csvorbis/MoonVorbisTest/Page.xaml | 9 + csvorbis/MoonVorbisTest/Page.xaml.cs | 33 + .../MoonVorbisTest/Properties/AppManifest.xml | 6 + .../MoonVorbisTest/Properties/AssemblyInfo.cs | 35 ++ csvorbis/csogg/AssemblyInfo.cs | 82 +++ csvorbis/csogg/Buffer.cs | 302 +++++++++ csvorbis/csogg/Makefile | 10 + csvorbis/csogg/Packet.cs | 53 ++ csvorbis/csogg/Page.cs | 140 +++++ csvorbis/csogg/StreamState.cs | 581 ++++++++++++++++++ csvorbis/csogg/SyncState.cs | 289 +++++++++ csvorbis/csogg/csogg.csproj | 60 ++ csvorbis/csogg/csogg.moonlight.csproj | 62 ++ csvorbis/csvorbis.sln | 33 + csvorbis/moonvorbis.sln | 42 ++ 102 files changed, 9174 insertions(+) create mode 100644 ChangeLog create mode 100644 Makefile create mode 100644 README create mode 100644 csadpcm/Makefile create mode 100644 csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs create mode 100644 csadpcm/MoonAdpcm/MoonAdpcm.csproj create mode 100644 csadpcm/MoonAdpcm/StringExtensions.cs create mode 100644 csadpcm/MoonAdpcm/WaveFormatExtensible.cs create mode 100644 csadpcm/MoonAdpcmTest/App.xaml create mode 100644 csadpcm/MoonAdpcmTest/App.xaml.cs create mode 100644 csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj create mode 100644 csadpcm/MoonAdpcmTest/Page.xaml create mode 100644 csadpcm/MoonAdpcmTest/Page.xaml.cs create mode 100644 csadpcm/MoonAdpcmTest/Properties/AppManifest.xml create mode 100644 csadpcm/MoonAdpcmTest/Properties/AssemblyInfo.cs create mode 100644 csadpcm/README create mode 100644 csadpcm/csadpcm/.IMA_ADPCM~.cs create mode 100644 csadpcm/csadpcm/ImaAdpcm.cs create mode 100644 csadpcm/csadpcm/csadpcm.csproj create mode 100644 csadpcm/csadpcm/csadpcm.moonlight.csproj create mode 100644 csadpcm/moonadpcm.sln create mode 100644 csdirac/DiracStreamSource.cs create mode 100644 csdirac/DiractTest/ArithTest.cs create mode 100644 csdirac/DiractTest/DecoderTest.cs create mode 100644 csdirac/DiractTest/DiractTest.csproj create mode 100644 csdirac/DiractTest/GeneralTest.cs create mode 100644 csdirac/DiractTest/Properties/AssemblyInfo.cs create mode 100644 csdirac/DiractTest/UnpackTest.cs create mode 100644 csdirac/DiractTest/Wavelet2dTest.cs create mode 100644 csdirac/Makefile create mode 100644 csdirac/Math/Dimension.cs create mode 100644 csdirac/Math/Point.cs create mode 100644 csdirac/MoonDirac.csproj create mode 100644 csdirac/MoonDirac/DiracStreamSource.cs create mode 100644 csdirac/MoonDiracTest.csproj create mode 100644 csdirac/MoonDiracTest/App.xaml create mode 100644 csdirac/MoonDiracTest/App.xaml.cs create mode 100644 csdirac/MoonDiracTest/App.xaml.g.cs create mode 100644 csdirac/MoonDiracTest/Page.xaml create mode 100644 csdirac/MoonDiracTest/Page.xaml.cs create mode 100644 csdirac/MoonDiracTest/Page.xaml.g.cs create mode 100755 csdirac/MoonDiracTest/Properties/AppManifest.xml create mode 100644 csdirac/Properties/AssemblyInfo.cs create mode 100644 csdirac/TestResult.xml create mode 100644 csdirac/csdirac.csproj create mode 100644 csdirac/csdirac.moonlight.csproj create mode 100644 csdirac/csdirac.sln create mode 100644 csdirac/csdirac/Arithmetic.cs create mode 100644 csdirac/csdirac/Block.cs create mode 100644 csdirac/csdirac/Buffer.cs create mode 100644 csdirac/csdirac/Cache.cs create mode 100644 csdirac/csdirac/ColourSpace.cs create mode 100644 csdirac/csdirac/Decoder.cs create mode 100644 csdirac/csdirac/Global.cs create mode 100644 csdirac/csdirac/Motion.cs create mode 100644 csdirac/csdirac/Parameters.cs create mode 100644 csdirac/csdirac/Picture.cs create mode 100644 csdirac/csdirac/Queue.cs create mode 100644 csdirac/csdirac/Slice.cs create mode 100644 csdirac/csdirac/Stream.cs create mode 100644 csdirac/csdirac/SubBand.cs create mode 100644 csdirac/csdirac/Unpack.cs create mode 100644 csdirac/csdirac/Util.cs create mode 100644 csdirac/csdirac/Vector.cs create mode 100644 csdirac/csdirac/VideoFormat.cs create mode 100644 csdirac/csdirac/Wavelet.cs create mode 100644 csdirac/csiracTest.VisualState.xml create mode 100644 csdirac/csiracTest.nunit create mode 100644 csdirac/moondirac.sln create mode 100755 csdirac/test/App.xaml create mode 100755 csdirac/test/App.xaml.cs create mode 100644 csdirac/test/App.xaml.g.cs create mode 100644 csdirac/test/AppManifest.xaml create mode 100755 csdirac/test/Page.xaml create mode 100755 csdirac/test/Page.xaml.cs create mode 100644 csdirac/test/Page.xaml.g.cs create mode 100644 csdirac/test/test.g.resources create mode 100644 csdirac/test/test.html create mode 100644 csvorbis/Makefile create mode 100644 csvorbis/Makefile.moon create mode 100644 csvorbis/MoonVorbis/MoonVorbis.csproj create mode 100644 csvorbis/MoonVorbis/OggMediaStreamSource.cs create mode 100644 csvorbis/MoonVorbis/StringExtensions.cs create mode 100644 csvorbis/MoonVorbis/WaveFormatExtensible.cs create mode 100644 csvorbis/MoonVorbisTest/App.xaml create mode 100644 csvorbis/MoonVorbisTest/App.xaml.cs create mode 100644 csvorbis/MoonVorbisTest/MoonVorbisTest.csproj create mode 100644 csvorbis/MoonVorbisTest/Page.xaml create mode 100644 csvorbis/MoonVorbisTest/Page.xaml.cs create mode 100644 csvorbis/MoonVorbisTest/Properties/AppManifest.xml create mode 100644 csvorbis/MoonVorbisTest/Properties/AssemblyInfo.cs create mode 100644 csvorbis/csogg/AssemblyInfo.cs create mode 100644 csvorbis/csogg/Buffer.cs create mode 100644 csvorbis/csogg/Makefile create mode 100644 csvorbis/csogg/Packet.cs create mode 100644 csvorbis/csogg/Page.cs create mode 100644 csvorbis/csogg/StreamState.cs create mode 100644 csvorbis/csogg/SyncState.cs create mode 100644 csvorbis/csogg/csogg.csproj create mode 100644 csvorbis/csogg/csogg.moonlight.csproj create mode 100644 csvorbis/csvorbis.sln create mode 100644 csvorbis/moonvorbis.sln diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..373f0c9 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,3 @@ +2009-04-30 Atsushi Enomoto + + Initial checkin. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3affd0a --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: + (cd csvorbis; make -f Makefile.moon) || exit + (cd csadpcm; make) || exit + (cd csdirac; make) || exit + +clean: + (cd csvorbis; make -f Makefile.moon clean) || exit + (cd csadpcm; make clean) || exit + (cd csdirac; make clean) || exit diff --git a/README b/README new file mode 100644 index 0000000..e5e8e23 --- /dev/null +++ b/README @@ -0,0 +1,15 @@ +This is a collection of managed custom media codecs for Moonlight 2.0 +and Silverlight 3.0 (both not at final release in April 2009 yet.) + +There are three codecs so far: + + - Ogg Vorbis, based on csvorbis by Marc Crichton. + http://anonsvn.mono-project.com/viewvc/trunk/csvorbis/ + - Dirac, based on csdirac by Olivier Dufour. + http://anonsvn.mono-project.com/viewvc/trunk/csdirac/ + - IMA ADPCM, based on the work by n7shi + ( http://d.hatena.ne.jp/n7shi/20090329/1238322010 ) + +For moonlight custom media support details, see: +http://veritas-vos-liberabit.com/monogatari/2009/03/moonvorbis.html + diff --git a/csadpcm/Makefile b/csadpcm/Makefile new file mode 100644 index 0000000..b8819c9 --- /dev/null +++ b/csadpcm/Makefile @@ -0,0 +1,28 @@ + +ADPCM_SRC = \ + csadpcm/ImaAdpcm.cs \ + MoonAdpcm/AdpcmMediaStreamSource.cs \ + MoonAdpcm/WaveFormatExtensible.cs \ + MoonAdpcm/StringExtensions.cs + +ADPCM_TEST_SRC = \ + MoonAdpcmTest/App.xaml \ + MoonAdpcmTest/App.xaml.cs \ + MoonAdpcmTest/Page.xaml \ + MoonAdpcmTest/Page.xaml.cs + +all: build/MoonAdpcmTest.xap + +build/MoonAdpcmTest.xap: build/MoonAdpcm.dll $(ADPCM_TEST_SRC) + cp MoonAdpcmTest/*.xaml build + cp MoonAdpcmTest/*.xaml.cs build + cp MoonAdpcmTest/Properties/AppManifest.xml build/AppManifest.xaml + cd build; mxap --application-name=MoonAdpcmTest; cd .. + +build/MoonAdpcm.dll: $(ADPCM_SRC) + smcs -t:library -out:MoonAdpcm.dll -debug $(ADPCM_SRC) + mv MoonAdpcm.dll build + mv MoonAdpcm.dll.mdb build + +clean: + rm build/* diff --git a/csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs b/csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs new file mode 100644 index 0000000..d378bd0 --- /dev/null +++ b/csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs @@ -0,0 +1,176 @@ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Text; +using System.Windows.Media; +using MediaParsers; +using csadpcm; + +namespace MoonAdpcm +{ + class DebugWriter : TextWriter + { + public override Encoding Encoding + { + get { return Encoding.UTF8; } + } + + public override void WriteLine () + { + Debug.WriteLine (String.Empty); + } + + public override void WriteLine (string s) + { + Debug.WriteLine (s); + } + } + + public class AdpcmMediaStreamSource : MediaStreamSource + { + ImaAdpcm source; + +// int convsize=4096*2; + //byte[] convbuffer=new byte[convsize]; // take 8k out of the data segment, not the stack +// byte[] convbuffer; + + TextWriter s_err = new DebugWriter(); // Console.Error; +// Stream input; + + public AdpcmMediaStreamSource (Stream input) + { + /* + convbuffer=new byte[convsize]; + vb = new Block (vd); + if (input == null) + throw new ArgumentNullException ("input"); + this.input = input; + */ + source = new ImaAdpcm (input); + } + + IEnumerable DecodeSamples () + { + foreach (byte [] buf in source.DecodeSamples ()) + yield return new SampleBuffer (buf, 0, buf.Length); + } + + struct SampleBuffer + { + byte [] buf; + int index, count; + public SampleBuffer (byte [] buf, int index, int count) + { + this.buf = buf; + this.index = index; + this.count = count; + } + + public byte [] Data { get { return buf; } } + public int Index { get { return index; } } + public int Count { get { return count; } } + } + + protected override void CloseMedia () + { + this.sample_enumerator = null; + s_err.WriteLine("Done."); + } + + // FIXME: should be implemented, but can be done later. + protected override void SwitchMediaStreamAsync (MediaStreamDescription mediaStreamDescription) + { + throw new System.NotImplementedException(); + // ReportSwitchMediaStreamCompleted (mediaStreamDescription); + } + + // FIXME: should be implemented, but looks like it can be left as is + // just to run decoder so far. + protected override void SeekAsync (long seekToTime) + { + ReportSeekCompleted (seekToTime); + } + + MediaStreamDescription audioStreamDescription; + + protected override void OpenMediaAsync () + { + // Initialize data structures to pass to the Media pipeline via the MediaStreamSource + Dictionary mediaSourceAttributes = new Dictionary(); + Dictionary mediaStreamAttributes = new Dictionary(); + List mediaStreamDescriptions = new List(); + + // Initialize the Mp3 data structures used by the Media pipeline with state from the first frame. + WaveFormatExtensible wfx = new WaveFormatExtensible(); + wfx.FormatTag = 1; // PCM + wfx.Channels = (short) this.source.Channels; + wfx.SamplesPerSec = this.source.SamplesPerSec; + wfx.BlockAlign = (short) (this.source.Channels * 2); + wfx.BitsPerSample = 16; + wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * 2; + wfx.Size = 0; + + mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = wfx.ToHexString(); + this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, mediaStreamAttributes); + + mediaStreamDescriptions.Add(this.audioStreamDescription); + + // This part is mere copy of Mp3MediaStreamSource: + // Setting a 0 duration to avoid the math to calcualte the Mp3 file length in minutes and seconds. + // This was done just to simplify this initial version of the code for other people reading it. + mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromMinutes(0).Ticks.ToString (CultureInfo.InvariantCulture); + mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString (); + // + + sample_enumerator = this.DecodeSamples ().GetEnumerator (); + this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions); + } + + Dictionary emptyDict = new Dictionary(); + IEnumerator sample_enumerator; + + protected override void GetSampleAsync (MediaStreamType mediaStreamType) + { + MediaStreamSample audioSample = null; + + if (!sample_enumerator.MoveNext ()) + { + // If you are near the end of the file, return a null stream, which + // tells the MediaStreamSource and MediaElement to close down. + audioSample = new MediaStreamSample( + this.audioStreamDescription, + null, + 0, + 0, + 0, + emptyDict); + this.ReportGetSampleCompleted(audioSample); + } + else + { + // FIXME: Stream should not be created every time. + SampleBuffer buf = (SampleBuffer) sample_enumerator.Current; + audioSample = new MediaStreamSample( + this.audioStreamDescription, + new MemoryStream (buf.Data, buf.Index, buf.Count, false), + buf.Index, + buf.Count, + timePosition, + emptyDict); + timePosition += buf.Count * 10000000 / (44100 * 2 * 2); + this.ReportGetSampleCompleted(audioSample); + } + } + long timePosition; + + // FIXME: should be implemented, but can be done later. + protected override void GetDiagnosticAsync (MediaStreamSourceDiagnosticKind diagnosticKind) + { + throw new System.NotImplementedException(); + // ReportGetDiagnosticCompleted(diagnosticKind, diagnosticValue); + } + } +} diff --git a/csadpcm/MoonAdpcm/MoonAdpcm.csproj b/csadpcm/MoonAdpcm/MoonAdpcm.csproj new file mode 100644 index 0000000..dab0844 --- /dev/null +++ b/csadpcm/MoonAdpcm/MoonAdpcm.csproj @@ -0,0 +1,59 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {A4D1AB0C-25BA-4E7D-9510-76BB4BA1D78B} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + false + true + false + AdpcmMediaStreamSource + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + + + none + false + bin\Release + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {1F3AC0CD-1994-4D37-BF94-C2359C3B5E68} + csadpcm.moonlight + + + \ No newline at end of file diff --git a/csadpcm/MoonAdpcm/StringExtensions.cs b/csadpcm/MoonAdpcm/StringExtensions.cs new file mode 100644 index 0000000..13ee2b2 --- /dev/null +++ b/csadpcm/MoonAdpcm/StringExtensions.cs @@ -0,0 +1,101 @@ +//----------------------------------------------------------------------- +// +// (c) Copyright Larry Olson. +// This source is subject to the Microsoft Public License (Ms-PL) +// See http://code.msdn.microsoft.com/ManagedMediaHelpers/Project/License.aspx +// All other rights reserved. +// +//----------------------------------------------------------------------- + +// Supressing Code Analysis rule(s) +[module: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", + Scope = "namespace", + Target = "ExtensionMethods", + Justification = "This is appropriate as a separate namespace because it logically is separate from the ManagedMediaParsers namespace.")] + +[module: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", + Scope = "member", + Target = "ExtensionMethods.StringExtensions.#ToLittleEndian(System.String)", + Justification = "This is appropriate to make this method look like a first class member of string.")] + +namespace ExtensionMethods +{ + using System; + + /// + /// Extensions for the standard string class. + /// + public static class StringExtensions + { + /// + /// + /// Converts a string of characters from Big Endian byte order to + /// Little Endian byte order. + /// + /// + /// Assumptions this makes about the string. Every two characters + /// make up the smallest data unit (analogous to byte). The entire + /// string is the size of the systems natural unit of data (analogous + /// to a word). + /// + /// + /// + /// A string in Big Endian Byte order. + /// + /// + /// A string in Little Endian Byte order. + /// + /// + /// This function was designed to take in a Big Endian string of + /// hexadecimal digits. + /// + /// input: + /// DEADBEEF + /// output: + /// EFBEADDE + /// + /// + public static string ToLittleEndian(this string value) + { + // Guard + if (value == null) + { + throw new NullReferenceException(); + } + + char[] bigEndianChars = value.ToCharArray(); + + // Guard + if (bigEndianChars.Length % 2 != 0) + { + return string.Empty; + } + + int i, ai, bi, ci, di; + char a, b, c, d; + + for (i = 0; i < bigEndianChars.Length / 2; i += 2) + { + // front byte ( in hex ) + ai = i; + bi = i + 1; + + // back byte ( in hex ) + ci = bigEndianChars.Length - 2 - i; + di = bigEndianChars.Length - 1 - i; + + a = bigEndianChars[ai]; + b = bigEndianChars[bi]; + c = bigEndianChars[ci]; + d = bigEndianChars[di]; + + bigEndianChars[ci] = a; + bigEndianChars[di] = b; + bigEndianChars[ai] = c; + bigEndianChars[bi] = d; + } + + return new string(bigEndianChars); + } + } +} diff --git a/csadpcm/MoonAdpcm/WaveFormatExtensible.cs b/csadpcm/MoonAdpcm/WaveFormatExtensible.cs new file mode 100644 index 0000000..16b6d7d --- /dev/null +++ b/csadpcm/MoonAdpcm/WaveFormatExtensible.cs @@ -0,0 +1,121 @@ +//----------------------------------------------------------------------- +// +// (c) Copyright Larry Olson. +// This source is subject to the Microsoft Public License (Ms-PL) +// See http://code.msdn.microsoft.com/ManagedMediaHelpers/Project/License.aspx +// All other rights reserved. +// +//----------------------------------------------------------------------- + +namespace MediaParsers +{ + using System; + using System.Globalization; + using ExtensionMethods; + + /// + /// A managed representation of the multimedia WAVEFORMATEX structure + /// declared in mmreg.h. + /// + /// + /// This was designed for usage in an environment where PInvokes are not + /// allowed. + /// + public class WaveFormatExtensible + { + /// + /// Gets or sets the audio format type. A complete list of format tags can be + /// found in the Mmreg.h header file. + /// + /// + /// Silverlight 2 supports: + /// WMA 7,8,9 + /// WMA 10 Pro + /// Mp3 + /// WAVE_FORMAT_MPEGLAYER3 = 0x0055 + /// + public short FormatTag { get; set; } + + /// + /// Gets or sets the number of channels in the data. + /// Mono 1 + /// Stereo 2 + /// Dual 2 (2 Mono channels) + /// + /// + /// Silverlight 2 only supports stereo output and folds down higher + /// numbers of channels to stereo. + /// + public short Channels { get; set; } + + /// + /// Gets or sets the sampling rate in hertz (samples per second) + /// + public int SamplesPerSec { get; set; } + + /// + /// Gets or sets the average data-transfer rate, in bytes per second, for the format. + /// + public int AverageBytesPerSecond { get; set; } + + /// + /// Gets or sets the minimum size of a unit of data for the given format in Bytes. + /// + public short BlockAlign { get; set; } + + /// + /// Gets or sets the number of bits in a single sample of the format's data. + /// + public short BitsPerSample { get; set; } + + /// + /// Gets or sets the size in bytes of any extra format data added to the end of the + /// WAVEFORMATEX structure. + /// + public short Size { get; set; } + + /// + /// Returns a string representing the structure in little-endian + /// hexadecimal format. + /// + /// + /// The string generated here is intended to be passed as + /// CodecPrivateData for Silverlight 2's MediaStreamSource + /// + /// + /// A string representing the structure in little-endia hexadecimal + /// format. + /// + public string ToHexString() + { + string s = string.Format(CultureInfo.InvariantCulture, "{0:X4}", FormatTag).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X4}", Channels).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X8}", SamplesPerSec).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X8}", AverageBytesPerSecond).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X4}", BlockAlign).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X4}", BitsPerSample).ToLittleEndian(); + s += string.Format(CultureInfo.InvariantCulture, "{0:X4}", Size).ToLittleEndian(); + return s; + } + + /// + /// Returns a string representing all of the fields in the object. + /// + /// + /// A string representing all of the fields in the object. + /// + public override string ToString() + { + return string.Format( + CultureInfo.InvariantCulture, + "WAVEFORMATEX FormatTag: {0}, Channels: {1}, SamplesPerSec: {2}, AvgBytesPerSec: {3}, BlockAlign: {4}, BitsPerSample: {5}, Size: {6} ", + this.FormatTag, + this.Channels, + this.SamplesPerSec, + this.AverageBytesPerSecond, + this.BlockAlign, + this.BitsPerSample, + this.Size); + } + } +} diff --git a/csadpcm/MoonAdpcmTest/App.xaml b/csadpcm/MoonAdpcmTest/App.xaml new file mode 100644 index 0000000..10d7b99 --- /dev/null +++ b/csadpcm/MoonAdpcmTest/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/csadpcm/MoonAdpcmTest/App.xaml.cs b/csadpcm/MoonAdpcmTest/App.xaml.cs new file mode 100644 index 0000000..2978ec3 --- /dev/null +++ b/csadpcm/MoonAdpcmTest/App.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +namespace MoonAdpcmTest +{ + public partial class App : Application + { + + public App() + { + this.Startup += this.Application_Startup; + this.Exit += this.Application_Exit; + this.UnhandledException += this.Application_UnhandledException; + + InitializeComponent(); + } + + private void Application_Startup(object sender, StartupEventArgs e) + { + this.RootVisual = new Page(); + } + + private void Application_Exit(object sender, EventArgs e) + { + + } + private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) + { + // If the app is running outside of the debugger then report the exception using + // the browser's exception mechanism. On IE this will display it a yellow alert + // icon in the status bar and Firefox will display a script error. + if (!System.Diagnostics.Debugger.IsAttached) + { + + // NOTE: This will allow the application to continue running after an exception has been thrown + // but not handled. + // For production applications this error handling should be replaced with something that will + // report the error to the website and stop the application. + e.Handled = true; + Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); + } + } + private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) + { + try + { + string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; + errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); + + System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");"); + } + catch (Exception) + { + } + } + } +} diff --git a/csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj b/csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj new file mode 100644 index 0000000..afcc601 --- /dev/null +++ b/csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj @@ -0,0 +1,75 @@ + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {B7B1D392-5A7C-44F9-9537-FC77390BCEB9} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + false + true + true + AdpcmMediaStreamSourceTest.xap + true + true + AdpcmMediaStreamSourceTest + + + true + full + false + bin\Debug + DEBUG + prompt + 4 + + + none + false + bin\Release + prompt + 4 + + + + + + + + + + + + + Designer + MSBuild:MarkupCompilePass1 + + + Designer + MSBuild:MarkupCompilePass1 + + + + + App.xaml + + + Page.xaml + + + + + + + + + + + + {A4D1AB0C-25BA-4E7D-9510-76BB4BA1D78B} + MoonAdpcm + + + \ No newline at end of file diff --git a/csadpcm/MoonAdpcmTest/Page.xaml b/csadpcm/MoonAdpcmTest/Page.xaml new file mode 100644 index 0000000..9e4012f --- /dev/null +++ b/csadpcm/MoonAdpcmTest/Page.xaml @@ -0,0 +1,9 @@ + + +