# Function: vector-to-pitch

## Recommended Posts

Hi,

vector-to-pitch is a very useful function. I want something quite similar with but with a small change.

What it does now (from the doc):

(vector-to-pitch '(g3 g4) (gen-white-noise 10 :seed 89))(vector-to-pitch '(g3 g4) (gen-white-noise 10 :seed 89))

=> (ab3 g4 eb4 a3 b3 eb4 g4 g3 gb4 e4)

Instead of giving (low high) as the first argument, I would like to give, for example, a specific scale. Let us say that I want vector-to-pitch  to convert the generated white noise to pitches in Major Scale, with tonic of C4. Is this possible?

- Rangarajan

##### Share on other sites

```(tonality-map '(major) (vector-to-pitch '(g3 g4) (gen-white-noise 10 :seed 89)))
=> (a3 g4 d4 a3 b3 d4 g4 g3 g4 e4)```

or

```(harmonic-path '(major) (vector-to-pitch '(g3 g4) (gen-white-noise 10 :seed 89)))
=> (c3 d4 e4 f3 g3 a4 b4 c3 d4 e4)```

##### Share on other sites

Thanks Janusz. Let me experiment with it.

- Rangarajan

##### Share on other sites

Thanks to suggestion by Janusz, I have been able to solve my requirement thus:

```;; Returns a list of pitches from the given list, satisfying the supplied noise
;; pitch-list => arbitrary list of pitches
;; noise => Any noise

(defun noise-to-pitch-map (pitch-list noise)
(mapcar #'(lambda (n)
(nth n pitch-list))
(vector-round 0 (1- (length pitch-list)) noise)))

Examples:
(noise-to-pitch-map '(c4 d4 e4 f4) (gen-white-noise 10 :seed 89))
=> (c4 f4 e4 c4 d4 e4 f4 c4 f4 e4)

(noise-to-pitch-map '(c4 d4 e4 c5 d5) (gen-gaussian-noise 10 :seed 89))
=> (d5 d4 c4 e4 d4 e4 c4 d4 e4 d5)

(noise-to-pitch-map (expand-tonality '(c4 major)) (gen-pink-noise 10 :seed 89))
=> (c4 d4 d4 e4 e4 f4 g4 a4 b4 b4)```

- Rangarajan

##### Share on other sites

```(vector-map '(c4 d4 e4 c5 d5) (gen-gaussian-noise 10 :seed 89))
=> (d5 d4 c4 e4 d4 e4 c4 d4 e4 d5)```

##### Share on other sites

Super! I would have saved some time if you had posted this in response to my earlier query!

- Rangarajan

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
• #### Browser

• Video Gallery

• Lessons