Skip to content

Commit a96e0c1

Browse files
committed
Initial files
1 parent d2a5def commit a96e0c1

32 files changed

+4748
-1
lines changed

AviFile/AssemblyInfo.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
//
5+
// Allgemeine Informationen über eine Assembly werden über folgende Attribute
6+
// gesteuert. Ändern Sie diese Attributswerte, um die Informationen zu modifizieren,
7+
// die mit einer Assembly verknüpft sind.
8+
//
9+
[assembly: AssemblyTitle("")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("")]
14+
[assembly: AssemblyCopyright("")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
//
19+
// Versionsinformationen für eine Assembly bestehen aus folgenden vier Werten:
20+
//
21+
// Hauptversion
22+
// Nebenversion
23+
// Buildnummer
24+
// Revision
25+
//
26+
// Sie können alle Werte oder die standardmäßige Revision und Buildnummer
27+
// mit '*' angeben:
28+
29+
[assembly: AssemblyVersion("1.0.*")]
30+
31+
//
32+
// Um die Assembly zu signieren, müssen Sie einen Schlüssel angeben. Weitere Informationen
33+
// über die Assemblysignierung finden Sie in der Microsoft .NET Framework-Dokumentation.
34+
//
35+
// Verwenden Sie folgende Attribute, um festzulegen welcher Schlüssel verwendet wird.
36+
//
37+
// Hinweis:
38+
// (*) Wenn kein Schlüssel angegeben ist, wird die Assembly nicht signiert.
39+
// (*) KeyName verweist auf einen Schlüssel, der im CSP (Crypto Service
40+
// Provider) auf Ihrem Computer installiert wurde. KeyFile verweist auf eine Datei, die einen
41+
// Schlüssel enthält.
42+
// (*) Wenn die Werte für KeyFile und KeyName angegeben werden,
43+
// werden folgende Vorgänge ausgeführt:
44+
// (1) Wenn KeyName im CSP gefunden wird, wird dieser Schlüssel verwendet.
45+
// (2) Wenn KeyName nicht vorhanden ist und KeyFile vorhanden ist,
46+
// wird der Schlüssel in KeyFile im CSP installiert und verwendet.
47+
// (*) Um eine KeyFile zu erstellen, können Sie das Programm sn.exe (Strong Name) verwenden.
48+
// Wenn KeyFile angegeben wird, muss der Pfad von KeyFile
49+
// relativ zum Projektausgabeverzeichnis sein:
50+
// %Project Directory%\obj\<configuration>. Wenn sich KeyFile z.B.
51+
// im Projektverzeichnis befindet, geben Sie das AssemblyKeyFile-Attribut
52+
// wie folgt an: [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
53+
// (*) Das verzögern der Signierung ist eine erweiterte Option. Weitere Informationen finden Sie in der
54+
// Microsoft .NET Framework-Dokumentation.
55+
//
56+
[assembly: AssemblyDelaySign(false)]
57+
[assembly: AssemblyKeyFile("")]
58+
[assembly: AssemblyKeyName("")]

AviFile/AudioStream.cs

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* This class has been written by
2+
* Corinna John (Hannover, Germany)
3+
4+
*
5+
* You may do with this code whatever you like,
6+
* except selling it or claiming any rights/ownership.
7+
*
8+
* Please send me a little feedback about what you're
9+
* using this code for and what changes you'd like to
10+
* see in later versions. (And please excuse my bad english.)
11+
*
12+
* WARNING: This is experimental code.
13+
* Please do not expect "Release Quality".
14+
* */
15+
16+
using System;
17+
using System.IO;
18+
using System.Runtime.InteropServices;
19+
20+
namespace AviFile
21+
{
22+
public class AudioStream : AviStream{
23+
24+
public int CountBitsPerSample{
25+
get{ return waveFormat.wBitsPerSample; }
26+
}
27+
28+
public int CountSamplesPerSecond{
29+
get{ return waveFormat.nSamplesPerSec; }
30+
}
31+
32+
public int CountChannels{
33+
get{ return waveFormat.nChannels; }
34+
}
35+
36+
/// <summary>the stream's format</summary>
37+
private Avi.PCMWAVEFORMAT waveFormat = new Avi.PCMWAVEFORMAT();
38+
39+
/// <summary>Initialize an AudioStream for an existing stream</summary>
40+
/// <param name="aviFile">The file that contains the stream</param>
41+
/// <param name="aviStream">An IAVISTREAM from [aviFile]</param>
42+
public AudioStream(int aviFile, IntPtr aviStream){
43+
this.aviFile = aviFile;
44+
this.aviStream = aviStream;
45+
46+
int size = Marshal.SizeOf(waveFormat);
47+
Avi.AVIStreamReadFormat(aviStream, 0, ref waveFormat, ref size);
48+
Avi.AVISTREAMINFO streamInfo = GetStreamInfo(aviStream);
49+
}
50+
51+
/// <summary>Read the stream's header information</summary>
52+
/// <param name="aviStream">The IAVISTREAM to read from</param>
53+
/// <returns>AVISTREAMINFO</returns>
54+
private Avi.AVISTREAMINFO GetStreamInfo(IntPtr aviStream){
55+
Avi.AVISTREAMINFO streamInfo = new Avi.AVISTREAMINFO();
56+
int result = Avi.AVIStreamInfo(aviStream, ref streamInfo, Marshal.SizeOf(streamInfo));
57+
if(result != 0) {
58+
throw new Exception("Exception in AVIStreamInfo: "+result.ToString());
59+
}
60+
return streamInfo;
61+
}
62+
63+
/// <summary>Read the stream's header information</summary>
64+
/// <returns>AVISTREAMINFO</returns>
65+
public Avi.AVISTREAMINFO GetStreamInfo(){
66+
if(writeCompressed){
67+
return GetStreamInfo(compressedStream);
68+
}else{
69+
return GetStreamInfo(aviStream);
70+
}
71+
}
72+
73+
/// <summary>Read the stream's format information</summary>
74+
/// <returns>PCMWAVEFORMAT</returns>
75+
public Avi.PCMWAVEFORMAT GetFormat(){
76+
Avi.PCMWAVEFORMAT format = new Avi.PCMWAVEFORMAT();
77+
int size = Marshal.SizeOf(format);
78+
int result = Avi.AVIStreamReadFormat(aviStream, 0, ref format, ref size);
79+
return format;
80+
}
81+
82+
/// <summary>Returns all data needed to copy the stream</summary>
83+
/// <remarks>Do not forget to call Marshal.FreeHGlobal and release the raw data pointer</remarks>
84+
/// <param name="streamInfo">Receives the header information</param>
85+
/// <param name="format">Receives the format</param>
86+
/// <param name="streamLength">Receives the length of the stream</param>
87+
/// <returns>Pointer to the wave data</returns>
88+
public IntPtr GetStreamData(ref Avi.AVISTREAMINFO streamInfo, ref Avi.PCMWAVEFORMAT format, ref int streamLength){
89+
streamInfo = GetStreamInfo();
90+
91+
format = GetFormat();
92+
//length in bytes = length in samples * length of a sample
93+
streamLength = Avi.AVIStreamLength(aviStream.ToInt32()) * streamInfo.dwSampleSize;
94+
IntPtr waveData = Marshal.AllocHGlobal(streamLength);
95+
96+
int result = Avi.AVIStreamRead(aviStream, 0, streamLength, waveData, streamLength, 0, 0);
97+
if(result != 0){
98+
throw new Exception("Exception in AVIStreamRead: "+result.ToString());
99+
}
100+
101+
return waveData;
102+
}
103+
104+
/// <summary>Copy the stream into a new file</summary>
105+
/// <param name="fileName">Name of the new file</param>
106+
public override void ExportStream(String fileName){
107+
Avi.AVICOMPRESSOPTIONS_CLASS opts = new Avi.AVICOMPRESSOPTIONS_CLASS();
108+
opts.fccType = (UInt32)Avi.mmioStringToFOURCC("auds", 0);
109+
opts.fccHandler = (UInt32)Avi.mmioStringToFOURCC("CAUD", 0);
110+
opts.dwKeyFrameEvery = 0;
111+
opts.dwQuality = 0;
112+
opts.dwFlags = 0;
113+
opts.dwBytesPerSecond= 0;
114+
opts.lpFormat = new IntPtr(0);
115+
opts.cbFormat = 0;
116+
opts.lpParms = new IntPtr(0);
117+
opts.cbParms = 0;
118+
opts.dwInterleaveEvery = 0;
119+
120+
Avi.AVISaveV(fileName, 0, 0, 1, ref aviStream, ref opts);
121+
}
122+
123+
}
124+
}

0 commit comments

Comments
 (0)