Csound Csound-dev Csound-tekno Search About

Re: +/- 90 degree phase shift of input WAV?

Date2007-08-01 08:45
FromVictor Lazzarini
SubjectRe: +/- 90 degree phase shift of input WAV?
what you are doing appears at a quick glance to
be SSB, rather than a straight phase shift.

The hilbert output will exhibit two signals which
are 90-degree apart, so you just use them directly.

Victor

>
>
> All,
>
> In an attempt to do a better job than the standard
> open-source tools (azid, BeSweet) with Dolby Pro Logic II
> 5.1-discrete-to-2-channel downmixing, I've found myself in
> need of the ability to take a mono WAV input and
> phase-shift it plus or minus 90 degrees (depending on
> which rear-channel input I'm processing).
>
> Knowing next to nothing about Csound except that it
> appears the only command-line tool for the job, I've
> hacked up the manual example a bit and come up with this
> (issues listed below):
>
> 
> 
> ; Select audio/midi flags here according to platform
> ; Audio out   Audio in    No messages
> ;-odac           -iadc     -d     ;;;RT audio I/O
> ; For Non-realtime ouput leave only the line below:
> -o hilbert.wav -W ;;; for file output any platform
> 
> 
>
> sr = 44100
> kr = 4410
> ksmps = 10
> nchnls = 1
>
> instr 1
>   idur = p3
>   ; Initial amount of frequency shift.
>   ; It can be positive or negative.
>   ibegshift = p4
>   ; Final amount of frequency shift.
>   ; It can be positive or negative.
>   iendshift = p5
>
>   ; A simple envelope for determining the
>   ; amount of frequency shift.
>   kfreq linseg ibegshift, idur, iendshift
>
>   ; Use the sound of your choice.
>   ain soundin "mary.wav"
>
>   ; Phase quadrature output derived from input signal.
>   areal, aimag hilbert ain
>
>   ; Quadrature oscillator.
>   asin oscili 1, kfreq, 1
>   acos oscili 1, kfreq, 1, .25
>
>   ; Use a trigonometric identity.
>   ; See the references for further details.
>   amod1 = areal * acos
>   amod2 = aimag * asin
>
>   ; Both sum and difference frequencies can be
>   ; output at once.
>   ; aupshift corresponds to the sum frequencies.
>   aupshift = (amod1 + amod2) * 0.7
>   ; adownshift corresponds to the difference frequencies.
>   adownshift = (amod1 - amod2) * 0.7
>
>   ; Notice that the adding of the two together is
>   ; identical to the output of ring modulation.
>
>   out amod1
> endin
>
> 
> 
>
> ; Sine table for quadrature oscillator.
> f 1 0 16384 10 1
>
> ; Starting with no shift, ending with all
> ; frequencies shifted up by 200 Hz.
> ;i 1 0 2 0 200
>
> ; Starting with no shift, ending with all
> ; frequencies shifted down by 200 Hz.
> ;i 1 2 2 0 -200
> i 1 0 99 0 0
> e
>
> 
> 
>
> Issues:
>
>     * Am I doing the right thing by making my out amod1
> (or amod2) and "short circuiting" the later logic from the
> example if in the end I simply want the output to sound
> identical to the input wav except phase-shifted 90
> degrees?
>     * Did I do the right thing in the score by eliminating
> the audible frequency shift (in other words, am I still
> phase-shifting)?
>     * Is there a way to simplify kfreq since I don't want
> to shift the audible frequencies up/down?
>     * How do I indicate to Csound that the score duration
> for instrument one should be whatever the length of the
> input wav sample is?
>
> Again, my end goal is to simply take a mono-channel,
> 48KHz/16 bit (I realize mary.wav isn't, hence my script
> example isn't either) Microsoft WAV file and output an
> identical-sounding 48KHz/16 bit WAV file that is
> phase-shifted either + or - 90 degrees (depending on
> whether I go with amod1/amod2 as out).
>
> Can anyone shed some light for the clueless?
>
> Rodney
> --
> View this message in context:
>
http://www.nabble.com/+---90-degree-phase-shift-of-input-WAV--tf4197587.html#a11938504
> Sent from the Csound - General mailing list archive at
> Nabble.com.
>
> --
> Send bugs reports to this list.
> To unsubscribe, send email to
> csound-unsubscribe@lists.bath.ac.uk

Date2007-08-01 15:20
Fromrhester
SubjectRe: +/- 90 degree phase shift of input WAV?
Victor Lazzarini wrote:
> 
> what you are doing appears at a quick glance to
> be SSB, rather than a straight phase shift.
> 
> The hilbert output will exhibit two signals which
> are 90-degree apart, so you just use them directly.

Understood.

So far, I sort of get what Csound is doing - it's basically applying a sine
(or cosine) wave to the WAV input to cause the 90-degree shift (thus doing a
Hilbert transform).  The challenge that I have is understanding the concept
of an instrument and score - since my intention is to simply apply the
transform to the entire duration of the input WAV, the duration of the input
is not necessarily known - so the duration parameter to linseg isn't known
(unless Csound has some way to derive it).

I am sure the solution must be reasonably simple, since Csound is advertised
as a tool well-suited to doing DSP on input files, but I can find few (well,
in truth, no) examples of how to do simple file-based input post-processing
(as opposed to the more traditional output synthesis method) with Csound.

Rodney
-- 
View this message in context: http://www.nabble.com/%2B---90-degree-phase-shift-of-input-WAV--tf4197587.html#a11946344
Sent from the Csound - General mailing list archive at Nabble.com.

Date2007-08-01 17:16
Fromrhester
SubjectRe: +/- 90 degree phase shift of input WAV?
Cribbing from several Csound examples, this is what I came up with that
appears to work (I still need to look at the output waveforms, but it at
least produces sane output) - replace "out acos" with "out asin" to reverse
the phase:


  
    -W
  
  
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    instr 1
      Sname strget 1
      ilen filelen Sname
      event_i "i", 2, 0, ilen
    endin

    instr 2
      Sname strget 1
      ain soundin Sname
      acos, asin hilbert ain
      out acos
    endin
  
  
    i1 0 1
  


Thanks for the pointer on stripping it down to hilbert only!

Rodney
-- 
View this message in context: http://www.nabble.com/%2B---90-degree-phase-shift-of-input-WAV--tf4197587.html#a11948760
Sent from the Csound - General mailing list archive at Nabble.com.