Csound Csound-dev Csound-tekno Search About

Re: [Csnd] Csound for Real Time Spectral Processing?

Date1999-11-18 06:14
Fromrasmus ekman
SubjectRe: [Csnd] Csound for Real Time Spectral Processing?
Chris Graham wrote:
> 
> input, converting it to the spectral domain, processing 
> and then outputting it - ideally in real time.

Analyse *and* resynthesize in r/t? As you noted, no.

pvanal/lpanal opcodes use files, and there is no opcode for
converting spectral data type to sound.


I suppose some people may wonder about the spec* opcodes (the docs 
tell it all, but I didn't understand them until looking at the source 
some time ago...)

The spectral opcodes presently available are designed for viewing 
audio. They are somewhat better at that particular duty than dispfft. 
(Standard FFT output is not a good model of hearing, since the 
frequencies are equally spaced in Hertz: for each octave in range,
half as many frequencies are detected in the one below it. In effect 
50% of the info concerns the topmost octave (11 kHz-22 kHz for CD audio)
- desirable for hifi sound, but not always for viewing.)

> Also, can the internal components in a wsig block be accessed individually
> for computations, other than with the predefined opcodes?

Yes. You'll have to figure the data format, but that shouldn't be too hard.
See spectra.h and spectra.c.

> Maybe I would have to write some custom C code to do this?

Please! It would be worthwhile to at least try it.
Perhaps the downsampling filters affect the signal so that the 
author (Barry Vercoe) doesn't think it is useful for sound. 

> Assuming the above is possible, is it realistic for me to expect 
> to be able to do this on one channel in real time on a 500mhz PC?

I think so. Test if you can run two or more 120-freq spectrum 
opcodes at, say, 100 frames per second (iprd=0.01).
The spectrum opcode uses oct-by-oct downsampling combined with
frequency analysis the hard way: Multiplying each sample with the 
cos and sin. This means it is an O(N^2) operation (ie very expensive). 
For display, 120 freq bands total may be ok, but for many music apps 
you'd probably want at least some 30-40 bands per octave.

Actually additive resynthesis should be quite a bit faster than 
the spectrum opcode, since you just add the sines, not the cosines, 
and don't do any up/downsampling or high-Q filtering.

I could display 60 freqs at 10 frames per sec, with Q-value 30, 
or spectrum-analyze but not display 120 freqs at 100 fr/sec, Q=10.
On an AMD 200 = not so good float processor.

(BTW, display needs a minor fix before you can try this on Winsound.
Remove comments around cwin_paint() call on line 107 in Wincwin.c:
 /*   cwin_paint(); */
change this to:
    cwin_paint(); 
Didn't note that this breaks anything else, but will have to ask jpff.)

Cheers,

	re
--