// Here I read the wave file and I convert the result to a string
byte[] b = new byte[35000];
FileStream fs = File.OpenRead("test.wav");
int size = fs.Read(b, 0, b.Length);
string dataSample = Encoding.ASCII.GetString(b, 0, size);
// Here I generate a second wave file from the result but the generated file
contains noise and disturbances
FileStream f = File.Create("test2.wav");
f.Write(Encoding.ASCII.GetBytes(dataSample), 0, size);
I also tryied some other encoding types like UTF7, UTF8, Default and
ISO-8859-1 but the result is the same.
I'm using a function from an assembly which needs a String parameter as
input that should be a wave buffer.
Can somebody help me? What am I doing wrong? Is there another way to read a
binary file in a String object?
That's a very bad idea. Strings are for text data. Wave files are
binary data. Just keep it in byte array format.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
You can use Convert.ToBase64String & Convert.FromBase64String to correctly
encode and decode binary data in a string.
However, I suspect this is not really what you want to do. It looks like the
problem may be in the semantics of the method in the assembly you are trying
to call. Does this really expect a string? And if so, perhaps there is some
documentation somewhere which specifies what format this string should be. As
Jon said in the previous post, strings are not used to store binary data.
If there is still a problem, perhaps you can post some details of the method
& assembly you are trying to call.
Cheers,
Chris.
Why are you converting a wave file that is a BINARY file to text ?
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Marius Cabas" <marius...@hotmail.com> wrote in message
news:uReimd1t...@TK2MSFTNGP14.phx.gbl...
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:#jJH$22tEH...@TK2MSFTNGP14.phx.gbl...
"Jon Skeet [C# MVP]" <sk...@pobox.com> wrote in message
news:MPG.1be1a5a96...@msnews.microsoft.com...
Hmm... I would contact the third party and check this. SSL is designed
for streams really - there's no justifiable reason why you *should*
have to specify everything in terms of strings. It's just asking for
trouble.
Are you able to specify the encoding the SSL code will use?
No, I have no control. I can only connect to a remote host using a por
number and I can set the certificates. Afterwards, I can read and write data
from/to the socket.
And you can only read/write data from/to the socket in string form?
What a terrible interface.
Basically, you won't be able to transfer binary data correctly unless
you can use something like Base64 encoding at both ends. If you don't
have control over the other end, you're stuffed.
Is there any way you can ditch this library and use a different one? It
sounds awful...