By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,665 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,665 IT Pros & Developers. It's quick & easy.

Can I use a byte array for sound files?

P: n/a
I am using MCI (winmm.dll) to read, record and playback sound. For
now, I am doing this with disk files instead of realtime doing it
straight from the memory. If I want to stream/relay/transmit this
sound (file) on a Windows socket (not using FTP but TCP), can I read
the file into a byte array? Because if it is possible then I can send
it on the socket but the problems I foresee are:

How will I repack it into the file. Will just reading back the byte
array into a file with the same extention work? I mean, say, I have a
..wav file and I read that into a byte array. Then I prefix some header
of my own containing the file name, the type and size etc. and send
this message on a socket, then at the other end, I read this header
and the following byte array and read it back into a file with the
same name and extention, will it be okay or it'll just be
gobbledegook?

How do they stream sound on the Internet otherwise?
Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sathyaish wrote:
I am using MCI (winmm.dll) to read, record and playback sound. For
now, I am doing this with disk files instead of realtime doing it
straight from the memory. If I want to stream/relay/transmit this
sound (file) on a Windows socket (not using FTP but TCP), can I read
the file into a byte array? Because if it is possible then I can send
it on the socket but the problems I foresee are:

How will I repack it into the file. Will just reading back the byte
array into a file with the same extention work? I mean, say, I have a
.wav file and I read that into a byte array. Then I prefix some header
of my own containing the file name, the type and size etc. and send
this message on a socket, then at the other end, I read this header
and the following byte array and read it back into a file with the
same name and extention, will it be okay or it'll just be
gobbledegook?

How do they stream sound on the Internet otherwise?


This has nothing do to with C FCOL. Use Google-degook before asking
questions.

Case

Nov 14 '05 #2

P: n/a
Sound and sockets are off-topic in comp.lang.c but there are some
issues here that are on-topic.
I am using MCI (winmm.dll) to read, record and playback sound. For
now, I am doing this with disk files instead of realtime doing it
straight from the memory. If I want to stream/relay/transmit this
sound (file) on a Windows socket (not using FTP but TCP), can I read
the file into a byte array?
You can read *ANY* readable file into a byte array (well, in C it's
called a char array) no matter what its format. What you do with
it after that is up to you.
Because if it is possible then I can send
it on the socket but the problems I foresee are:

How will I repack it into the file. Will just reading back the byte
array into a file with the same extention work?
Reading the file into a char array, then writing it back should
work to make a copy of the file, barring problems like running out
of disk space, permissions, bad sectors, etc. The extension is not
relevant to C. Nor is the fact that this file allegedly contains
sound.
etc. I mean, say, I have a
.wav file and I read that into a byte array. Then I prefix some header
of my own containing the file name, the type and size etc. and send
this message on a socket, then at the other end, I read this header
and the following byte array and read it back into a file with the
same name and extention, will it be okay or it'll just be
gobbledegook?
What's the format expected for the file? (Does the file have fields
in it that are byte-order-sensitive, like, say, a 24-bit field for
sampling frequency?) What's the format expected over the socket?
If you add a header before sending it you should be prepared to
remove it before writing the file. Treating the file as a byte
array shouldn't add any MORE platform-dependencies than there were
in the original file.

When transferring files over sockets (also true of reading blocks
of data from the keyboard, and disk files, but it may be a bit more
erratic with sockets): fread() may return chunks of data that are
not the same size as the chunks you wrote. (e.g. you wrote two
500-byte blocks; you might get them back as three 300-byte blocks
and one 100-byte block.) Be prepared to handle this situation.
*USE* the amount of data read that fread() returns, don't assume
you got all you asked for, and don't assume that if you got a short
block that it's the last one.
How do they stream sound on the Internet otherwise?


I don't know what format they use for streaming sound, but
you probably have to stream licenses at the same time, and
remove the CSS encryption.

Gordon L. Burditt
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.