I have nessary chunk header bytes for a wave file stored in a text file. What I'd like to do is create a new .wav that will vary in data length and write into it 50ms/10kHz signals(which is stored in separate file). How can I accomplish with .NET/C#?
-Mickey
Use the System.IO.BinaryReader and System.IO.BinaryWriter streams to read data from your signals files, write binary datatypes to a file, as per the wav file specification.
Related
As title,
I want to encrypt 10 files into one file and the extension file can be customized. Once encrypted, I will automatically decrypt it to create 10 files as originally. Does anyone have any ideas?
Just as any other stream where you can't discern messages, you need a delimiter of some sorts. Prepending the length of stuff is a common way to do so.
So make up a file format specification, for example:
Start the file with an uint32 which specifies the number of files in the archive
Then, per file:
Write an uint32 specifying the file name length in bytes in the encoding you want to use (I'd go for UTF-8)
Write the file name's bytes
Write an uint32 specifying the file data length
Write the file data
Then when reading the file, read the uints and extract the next bytes.
But you generally don't want to invent your own file format.
Possbile solution
Encrypt all the files
Store the encrypted data (byte[]) in a List<byte[]> or store it separatly in temp-files (maybe file.oldext.newext.tmp)
Create a new XML file, write all the data to it (create a list within the XML file and store the data in the list elements; One element per file)
Save the XML file to the disk (newfilename.newext)
I'm receiving a .zip file from a server.
The .zip file is sent 64Base encoded and it contains an XML file.
After I decode the data to binary using Convert.FromBase64String, can I convert the byte array to XML?
I don't want to deal with unzipping.
I tried the following code: (that resulted in Gibberish that doesn't make any sense and doesn't look like XML at all)
XmlDocument doc = new XmlDocument();
string xml = Encoding.UTF8.GetString(buffer);
doc.LoadXml(xml);
Any ideas?
You say you don't want to unzip, but do you actually mean that you don't want to unzip to disc? Most zip libraries either allow you to unzip a file to a byte array directly or to a stream where you could pass it a MemoryStream.
There's no getting around having to uncompress. Unless you have control over the server side, then you could change the format to an uncompressed file (like a tar file). Then you wouldn't have to uncompress.
You say:
I'm receiving a .zip file from a server.
And:
I don't want to deal with unzipping.
Well. You have to. If the data is in a zip archive, you need to extract it first. You can't just ignore the fact.
There are plenty of zip libraries - sharpziplib is free and easy enough to use.
I'm doing a project in C# which requires me to encrypt a wave file. So, is there a straight forward process to convert a wave file into binary and back? I'll be applying an encryption algorithm on the binary data.
Sure, checkout the File.ReadAllBytes and File.WriteAllBytes methods. Or if the files are too large to fit in memory you could read/write in blocks using a FileStream.
You can use FileStream to read a binary file, such as WAV file and then another FileStream to write the encrypted version back out.
You need to read and write the files in blocks using a byte array.
Can someone give an example of how to record, play, save and also encode a .wav file in a pcm file (u-law encode for ex). I would like to create a rtp stream. THX
NAudio can be used to record audio, convert it to u-law and save it to a WAV file. The included NAudioDemo application demonstrates how to perform all three tasks.
For creating an RTP stream, you could try RTP.NET
It would be great if you could tell me how I could save a byte[] to a wav file. Sometimes I need to set different samplerate, number of bits and channels.
Thanks for your help.
You have to set up the wav header data which contains info about sample rate, file size, sample size, stereo or mono etc. Then write the actual audio data.
Then you just have to write it out as a binary file with '.wav' file extension.