[CM] Header srate and data-format not being written to file

e deleflie edeleflie@gmail.com
Wed, 23 May 2007 16:03:57 +1000


All,

In save-sound-as, I am setting the data-format to mus-l24int and the
srate to 44100. But when I re-open the written file in SND (and other
editors). Neither field is correctly written.

The code is attached below.

If I start with a 48kHz file, the srate in the header remains as 48000
(and hence the file plays back transposed up... since I resampled it
down to 44100).

The data-format also seems to remain as what it was in the source file...

Am I doing something wrong? (should I set some global variable sor something?)

Etienne

-----------------------------------------------------------------
#!/usr/bin/snd -b
!#
(use-modules (ice-9 format))
; set some global variables
(set! (sinc-width) 100); set the sync width to very high to get the
smaple rate conversion as accurate as possible
(if (not (= (length (script-args)) 3)) ;
        (display "usage: decode_to_square.sh file-name")
        (begin
                (let ((name (list-ref (script-args) (+ (script-arg) 1)) ))
                        (let ((index (open-sound name)))
                                (display (format #f "header is ~a (or
~a) \n" (header-type index) (mus-header-type-name (header-type index))
))
                                (display (format #f "data-format is ~a
(or ~a) \n" (data-format index) (mus-data-format-name (data-format
index) ) ))
                                (display (format #f "Resampling from
~D to 44100 \n" (srate index)))

                                ; resample
                                (src-sound (/ (srate index) 44100) 1.0 index)

                                ; apply LADSPA plugin that converts to
4 speaker feeds in a square
                                (apply-ladspa   (list
(make-sample-reader 0 0 0)  ; W

(make-sample-reader 0 0 1)  ; X

(make-sample-reader 0 0 2)  ; Y

(make-sample-reader 0 0 3)) ; Z
                                                (list "ambis1"
"Ambisonics-square-decoder" 0 1 1.4138 2 380 2.7)
                                                (mus-sound-frames name)
                                                "ambisonic file")

                                ; now convert the 4 channels into 4
mono wav files, and write to disk
                                (do ((i 0 (1+ i)))
                                           ((= i 4))
                                        (display (format #f "writing
channel ~D\n" i))
                                        (save-sound-as (format #f "~a.~a" name
                                                                (case i

 ((0) "LFront.wav")

 ((1) "RFront.wav")

 ((2) "RSurround.wav")

 ((3) "LSurround.wav")

 (else "lost")
                                                                )
                                                        )
                                                        index
                                                        :header-type
mus-riff ; (value= 3) RIFF header (for Microsoft WAVE)
                                                        :data-format
mus-l24int ; (value= 16) 24 Bit little endian int
                                                        :srate 44100 ;
the sound is already resampled, so lets set the appropriate file
header
                                                        :channel i)
                                )
                                (close-sound index)
                        )
              )
       )
)
(exit)