File: loadwave.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (27 lines) | stat: -rw-r--r-- 964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function [w]=loadwave (filename)
// Copyright INRIA
// Read a WAV file.
// The sample rate is stored to defaultrate.
	defaultrate=22050;
        mopen(filename,"rb");
        if mgetstr(4)<>"RIFF"; error("No Wave file!"); end;
        mget(1,"l");; // This is the total file length minus 8
        if mgetstr(8)<>"WAVEfmt "; error("No Wave file!"); end;
        mget(1,"l");; // ??? Is always 16.
        mget(1,"s"); // ??? Is always 1.
        if (mget(1,"s")<>1); error("Stereo sample!"); end;
        rate=mget(1,"l");; mget(1,"l");;
        byte=mget(1,"s");
        bits=mget(1,"s");
        if mgetstr(4)<>"data"; error("No Wave file!"); end;
        if byte==1;
		xx=mget(1,"l");
                w=mget(xx,"uc");
        elseif byte==2;
                w=mget(mget(1,"l")/2,"s");
        else error("Not 8 or 16 bit!");
        end;
        if prod(size(w))>0; 
		w=w-sum(w)/prod(size(w)); w=w/max(abs(w)); end;
        mclose();
        defaultrate=rate;