Giter VIP home page Giter VIP logo

xenakis-workgroup's Introduction

xenakis-workgroup's People

Contributors

capital-g avatar telephon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

telephon

xenakis-workgroup's Issues

Issue on page /concert.html

"When a molecule rotates alone in space, it do not continue to do so forever."
should be
"When a molecule rotates alone in space, it does not continue to do so forever."

Add python example on random walk synthesis

from my bachelor thesis

import wave
import struct
import random
from decimal import Decimal, ROUND_HALF_UP
from numpy import interp, clip
import sys

SECONDS = 10
CHANNELS = 1
AMPLITUDE_MIN = 400
AMPLITUDE_MAX = 2000
FREQUENCY_MIN = 400
FREQUENCY_MAX = 4000

FRAME_RATE = 48000
SAMPLE_WIDTH = 2


class RandomWalk():
    def __init__(self, **kwargs):
        self.start_value = kwargs.get('start_value', 0)
        self.value = self.start_value
        self.possible_steps = kwargs.get('possible_steps', [1, -1])
        self.steps = kwargs.get('steps', 0)
        self.step_mode = kwargs.get('step_mode', 'normal')  # alternative: fixed
        self.hit_zero = kwargs.get('hit_zero', True) # possible obsolete with min/max value
        self.step_number = 0
        self.positions = ()
        self.min_value = kwargs.get('min_value', None)
        self.max_value = kwargs.get('max_value', None)
        self.second_order = kwargs.get('second_order', False)
        self.second_order_alpha = kwargs.get('second_order_alpha', 0.5)
        if self.min_value is None and self.max_value is None:
            self.barriers = False
        else:
            self.barriers = True
        if self.second_order:
            boundary = (self.max_value - self.min_value)*self.second_order_alpha
            self.primary_walk = RandomWalk(
                start_value=random.randint(-boundary, boundary),
                possible_steps=self.possible_steps,
                step_mode='normal',
                min_value=-boundary,
                max_value=boundary,
            )

    def one_step_forward(self):
        # select a valid step
        if self.second_order:
            step = self.primary_walk.one_step_forward()
        else:
            while True:
                step = random.choice(self.possible_steps)
                valid = True

                # check if random walk crosses or hits zero
                if self.hit_zero is False:
                    if self.value > 0 and self.value+step <= 0:
                        valid = False
                    elif self.value < 0 and self.value+step >= 0:
                        valid = False

                # check if mode is fixed and it hits a barrier
                if self.step_mode == 'fixed' and self.barriers:
                    if self.value+step > self.max_value or self.value+step < self.min_value:
                        valid = False

                if valid:
                    break

            # if we have a fixed random walk, remove the selected step from the possible steps
            if self.step_mode == 'fixed':
                self.possible_steps.remove(step)

        # mirror step if it hits barrier
        if self.barriers:
            if self.value+step > self.max_value:
                self.value -= step
            if self.value+step < self.min_value:
                self.value -= step
            else:
                self.value += step
        else:
            self.value += step

        self.step_number += 1
        self.positions += (self.value,)

        return self.value

    def show_random_walk(self, steps=None):
        if steps is None:
            steps = len(self.possible_steps)
        for i in range(0, steps):
            self.one_step_forward()
        return self.positions


def create_sound():
    # Init new wave File
    stream = wave.open('sound.wav', 'wb')
    stream.setnchannels(CHANNELS)
    stream.setsampwidth(SAMPLE_WIDTH)
    stream.setframerate(FRAME_RATE)

    # Init amplitude and pitch random walk
    amplitude_walk = RandomWalk(
        start_value=random.randint(AMPLITUDE_MIN, AMPLITUDE_MAX),
        possible_steps=[100, -100],
        step_mode='normal',
        min_value=AMPLITUDE_MIN,
        max_value=AMPLITUDE_MAX,
        second_order=True,
    )

    pitch_walk = RandomWalk(
        start_value=random.randint(FREQUENCY_MIN, FREQUENCY_MAX),
        possible_steps=[10, -10],
        step_mode='normal',
        min_value=FREQUENCY_MIN,
        max_value=FREQUENCY_MAX,
        second_order=True,
    )

    break_point_walk = RandomWalk(
        start_value=random.randint(3, 20),
        possible_steps=[0],
        step_mode='normal',
        min_value=3,
        max_value=20,
    )

    frame = 0
    while frame < FRAME_RATE * SECONDS * CHANNELS:
        # get a pitch, amplitude and breakpoint value
        pitch = pitch_walk.one_step_forward()
        amplitude = amplitude_walk.one_step_forward()
        break_points = break_point_walk.one_step_forward()
        frame_window = int(Decimal(FRAME_RATE/pitch).quantize(Decimal(1.0), rounding=ROUND_HALF_UP))
        # todo: round to even number?

        # start first half of period
        all_possible_steps = []
        for i in range(0, int(frame_window/4)):
            all_possible_steps.append(1)
            all_possible_steps.append(-1)

        random_walk = RandomWalk(
            start_value=1,
            possible_steps=all_possible_steps,
            step_mode='fixed',
            hit_zero=False,
        )
        steps = random_walk.show_random_walk()

        # start second half of period
        all_possible_steps = []
        for i in range(0, int(frame_window/4)):
            all_possible_steps.append(1)
            all_possible_steps.append(-1)

        random_walk = RandomWalk(
            start_value=-1,
            possible_steps=all_possible_steps,
            step_mode='fixed',
            hit_zero=False,
        )
        steps += random_walk.show_random_walk()

        break_point_y = []
        break_point_x = []
        # add a break at the beginning
        break_point_y.append(0)
        break_point_x.append(0)

        for i in range(0, break_points):
            if break_points % 2 == 0:
                break_point_y.append(int(((i+1)/(break_points+1))*len(steps)))
                break_point_x.append(steps[int(((i+1)/(break_points+1))*len(steps))])
            elif break_points == 1:
                break_point_y.append(int((1/2)*len(steps)))
                break_point_x.append(steps[int((1/2)*len(steps))])
            else:
                break_point_y.append(int((i/(break_points-1))*len(steps)))
                try:
                    break_point_x.append(steps[int((i/(break_points-1))*len(steps))])
                except IndexError:  # steps[len(steps)] will result in IndexError
                    break_point_x.append(steps[-1])
        # add a break point to the end
        break_point_y.append(len(steps)-1)
        break_point_x.append(0)

        for step_number, step in enumerate(steps):
            frame_value = interp(step_number, break_point_y, break_point_x)
            stream.writeframes(struct.pack('h', clip(int(frame_value*amplitude), -32767, 32767)))
            frame += 1


if __name__ == '__main__':
    create_sound()

Sounds like
synth_02.wav.zip

Add stochastic synthesis

Some fragments that need explanation and added to the repo

2 snippets from julian (which are also in the dropbox)

Ndef(\x, {

        var sig;

        sig = {
                var env;
                var levels, time;
                levels = { LFDNoise1.kr(MouseX.kr(0.01, 100, 1)) } ! 20;
                time = { LFDNoise1.kr(MouseY.kr(0.05, 100, 1)).range(1/200, 1/20000) } ! 19;
                env = Env(levels, time[1..]).circle(time[0]);
                EnvGen.ar(env, timeScale:1/10) * 0.1

        } ! 16;

        sig;

}).play(numChannels: 16);
Ndef(\x, {

        var sig, mx, my;
        var nLevels;
        mx = MouseX.kr(0, 1);
        my = MouseX.kr(0, 1);


        nLevels = 20;
        sig = {
                var env;
                var levels, time;
                levels = { LFDNoise1.kr(mx.linexp(0, 1, 0.01, 100, 1)) } ! nLevels;
                time = { LFDNoise1.kr(my.linexp(0, 1, 0.05, 100, 1)).exprange(1/100, 1/2000) } ! (nLevels - 1);
                env = Env(levels, time[1..]).circle(time[0]);
                EnvGen.ar(env, timeScale:1/10) * 0.1

        } ! 16;

        Splay.ar(sig)

}).play(numChannels: 16);

and something I wrote

Ndef(\gendy, {
	var freq = \freq.kr(50.0);

	// maybe this is just a too complicated way to
	// create a lo-res wavetable synth?
	// but at least it can do this w/ n channels

	// by increasing the steps of the env we can enrich overtones
	// how could one modulate this b/c this plays with
	// the number of channels in the ugen graph :?
	// can go up to 5000
	var steps = 140;
	var levels = steps.collect({
		// provide a function for each step of our env
		// !2 makes it stereo but could be increased beyond
		LFDNoise0.kr(6!4);
	});

	var env = EnvGen.ar(
		envelope: Env(
			levels: levels+1, // we need to offset as env seems to perform .min(0.0) on the levels
			times: 1/(freq*(levels.size-1)),
			// another parameter is to fluctuate the envelope times at each section
			// best is to distribute from something which sums up to 1 so its pitch is stable
			// times: (levels.size-1).collect({1/(freq*(levels.size-1))*LFDNoise1.kr(mul: 0.21)}),

			// another parameter is the steepness of each segment
			// this could be set globally for the env or for each step independently
			curve: LFDNoise0.ar(1.0)*0.2, // bigger values lead to more metallic sound
		).postcs,
		gate: Impulse.ar(freq),
	)-1; // remove the offset
	0.2*SplayAz.ar(4, env);
}).play(numChannels: 4);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.