Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,

I want to create this function in c sharp
The older version is as follows:
VB
Private Function ADDAUDIOFILE(ByRef F As ArrayList, ByVal Destination As String, Optional ByRef Duration As Long = 0)
Dim DEST As New NCTAUDIOFILELib.AudioFileClass
Dim File1 As New NCTAUDIOFILELib.AudioFileClass
Dim BufferSize As Long
Dim Wave1 As Array
Dim I As Integer
Dim Flg As Boolean
If File.Exists(Destination) = True Then
Try
File.Delete(Destination)
Catch ex As Exception
System.Threading.Thread.CurrentThread.Sleep(200)
File.Delete(Destination)
End Try
End If
BufferSize = 50000
File1.OpenFile(F(0))
DEST.SetFormatPCM(File1.ArrayFrequency, File1.ArrayChannels, NCTAUDIOFILELib.BitsPerSampleConstants.BPS_8_BIT)
DEST.CreateFile(Destination)
Flg = True
For I = 0 To F.Count - 1
File1.OpenFile(F(I))
While (Flg)
Wave1 = File1.ReadFile(BufferSize)
If UBound(Wave1) < 1 Then
Flg = False
Else
DEST.WriteFile(Wave1)
End If
End While
Flg = True
File1.CloseFile()
Next I
Duration = DEST.Duration()
DEST.CloseFile()
End Function


Please help me in this.

Thanks in Advance.
Posted
Updated 21-May-11 2:21am
v3
Comments
Abhinav S 21-May-11 7:50am    
Try something. Post any problem you run into here and someone will help you.

Hi Member 4671287,

Try this :

private object ADDAUDIOFILE(ref ArrayList F, string Destination, ref long Duration = 0)
{
	NCTAUDIOFILELib.AudioFileClass DEST = new NCTAUDIOFILELib.AudioFileClass();
	NCTAUDIOFILELib.AudioFileClass File1 = new NCTAUDIOFILELib.AudioFileClass();
	long BufferSize = 0;
	Array Wave1 = null;
	int I = 0;
	bool Flg = false;
	if (File.Exists(Destination) == true) {
		try {
			File.Delete(Destination);
		} catch (Exception ex) {
			System.Threading.Thread.CurrentThread.Sleep(200);
			File.Delete(Destination);
		}
	}
	BufferSize = 50000;
	File1.OpenFile(F[0]);
	DEST.SetFormatPCM(File1.ArrayFrequency, File1.ArrayChannels, NCTAUDIOFILELib.BitsPerSampleConstants.BPS_8_BIT);
	DEST.CreateFile(Destination);
	Flg = true;
	for (I = 0; I <= F.Count - 1; I++) {
		File1.OpenFile(F[I]);
		while ((Flg)) {
			Wave1 = File1.ReadFile(BufferSize);
			if (Information.UBound(Wave1) < 1) {
				Flg = false;
			} else {
				DEST.WriteFile(Wave1);
			}
		}
		Flg = true;
		File1.CloseFile();
	}
	Duration = DEST.Duration();
	DEST.CloseFile();
}


for any other conversions use this converter[^]

I hope this help,
:)
 
Share this answer
 
v2
Comments
Christian Graus 21-May-11 8:12am    
You did it a bit at a time ? I found the same one, but it threw an error when I passed the whole function
Michael Waguih 21-May-11 8:18am    
What is the error ?
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] can help, but I suspect you'll need to pass in a bit at a time, it throws an error when passed the whole function. you should try to do this your self and ask specific questions as you get stuck. You could also compile this in to a VB.NET DLL and call it from C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900