Can I use a byte array for sound files?

S

Sathyaish

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?
 
C

Case

Sathyaish said:
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
 
G

Gordon Burditt

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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top