ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/csh
#-------------------------------------------------------------------------------
#
# This script takes pcm.hex and a sample rate and converts it to a wave file.
#
#-------------------------------------------------------------------------------
#--------------------------------------------------------------------------
#
# Verify that the sample rate option is supported
#
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#
# Part of the wave file header includes information about the file length
# Calculate the file length here and convert it to little endian
# The file length is in bytes.
# Verify pcm.hex has 4 characters per line.
#
#--------------------------------------------------------------------------
set pcm_lines = `cat ${FILENAME} | wc -l`
set pcm_chars = `cat ${FILENAME} | wc -c`
set pcm_bytes = `expr 5 \* ${pcm_lines}`
if ($pcm_bytes != $pcm_chars) then
echo "ERROR : Unrecognized file format. Expecting 4 hex chars per line"
exit(2)
endif
set file_length = `expr 2 \* ${pcm_lines}`
set hex_length = `echo $file_length | d2h -o30`
set byte0 = `echo $hex_length | cut -c7-8`
set byte1 = `echo $hex_length | cut -c5-6`
set byte2 = `echo $hex_length | cut -c3-4`
set byte3 = `echo $hex_length | cut -c1-2`
set lenstr = $byte0$byte1$byte2$byte3
set file_length_p36 = `expr 2 \* ${pcm_lines} + 36`
set hex_length_p36 = `echo $file_length_p36 | d2h -o30`
set byte0_p36 = `echo $hex_length_p36 | cut -c7-8`
set byte1_p36 = `echo $hex_length_p36 | cut -c5-6`
set byte2_p36 = `echo $hex_length_p36 | cut -c3-4`
set byte3_p36 = `echo $hex_length_p36 | cut -c1-2`
set lp36str = $byte0_p36$byte1_p36$byte2_p36$byte3_p36
#--------------------------------------------------------------------------
#
# Part of the wave file header includes information about the sample rate
#
#--------------------------------------------------------------------------
if ($FS == "32") then
set fs_str = "007d0000" # Samples per second
set bs_str = "00f40100" # Bytes per second -- assume 16-bit stereo
else if ($FS == "44") then
set fs_str = "44ac0000"
set bs_str = "10b10200"
else
set fs_str = "80bb0000"
set bs_str = "00ee0200"
endif
#--------------------------------------------------------------------------
#
# Output RIFF header information
#
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#
# Output data header information
#
#--------------------------------------------------------------------------
echo "64617461" >> $ofile_ascii # data 0- 3
echo $lenstr >> $ofile_ascii # length 4- 7
#--------------------------------------------------------------------------
#
# Output data section -- convert to little endian data
#
#--------------------------------------------------------------------------
setenv is a command, yes. The thing is that its not a binary, but a shell builtin. Now, sofar as much I tested a simple setenv shellscript, it worked just fine, found the builtin setenv, so im not sure what the prblem is..
Make sure you have csh installed and located under /bin/csh and that its not just a symlink to some other shell..
Your command is great !!!!! I have tried by : cat cnvtPcm2Wav -vets|head
And the result is : #!/bin/csh^M$
I raise 3 questions with this result :
1) Is '^M$' a new line character ?
2) The first line of the file (#!/bin/csh) is a comment line. Is it important whether or not it has ^M$ at the end of the line ?
3) Does the first line hint me that this file is written for a shell (In this case , the shell used for this script is csh) ? If this script is written for csh , why don't I see any C syntax here ?
in widndows or DOS, any end of line in a text file is 0x0D and 0x0A
but in UNIX, the end of line if just 0x0A,
so when you get a script from windows, you need run:
the first commented line indeed tells the current shell what program the script wants to be executed in. csh isnt realy that good for shellscripts, but that one seems pretty lowlevel and perhaps then csh is a good choise, or not..
The line indeed is a comment, but it must be the first line, and everything after the ! is take character by character as the app to execute this code, even parameters can be given. So, an extra ^M is pretty destructive in a place like that.. (:
Thank you so much for your great explaination. I have tried "dos2unix" and successfully overcome the "setenv" issue. Now I need to write some of the extra scripts to run my program.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.