File: mapsound.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 (39 lines) | stat: -rw-r--r-- 1,111 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
28
29
30
31
32
33
34
35
36
37
38
39
function mapsound (w,dt,fmin,fmax,simpl,rate)
// Plots a sound map for a sound.
// It does FFT at time increments dt.
// rate is the sampling rate.
// simpl points are collected for speed reasons.
// Copyright INRIA
[lhs,rhs]=argn(0);
	if ( rhs <= 5 ) then rate=0;end
	if ( rhs <= 4 ) then simpl=1; end ;
	if ( rhs <= 3 ) then fmax=1500; end ;
	if ( rhs <= 2 ) then fmin=100; end ;
	if ( rhs <= 1 ) then dt=0.1;  end ;
        n=prod(size(w));
	defaultrate=22050;
        if rate==0; rate=defaultrate; end;
        dp=dt*rate;
        points=2^floor(log(dp)/log(2));
        ind=fmin/rate*points/simpl:fmax/rate*points/simpl;
        f=abs(fft(w(1:points),1));
        f=sum(matrix(f,points/simpl,simpl),'c')';
        M=f(ind);
        i=1;
        i=i+dp;
	while i+points <= n;
                f=abs(fft(w(i:i+points-1),1));
                f=sum(matrix(f,points/simpl,simpl),'c')';
                M=[M;f(ind)];
		i=i+dp;
        end;
	[nl,nc]=size(M);
	if nl==1 ; return;end 
	x_abs= (0:(nl-1))*(n/rate)/(nl-1);
	y_abs= (0:(nc-1))/(nc-1);
	y_abs= fmin*(y_abs-1) + fmax*(y_abs)
	grayplot(x_abs,y_abs,-M)