diff --git a/404.html b/404.html index 0af4e8f7..b3424ac5 100644 --- a/404.html +++ b/404.html @@ -1037,7 +1037,7 @@
  • - Exporting and importing patches + Exporting and importing
  • @@ -1086,6 +1086,18 @@ + + + + + + + + + + + + @@ -1093,6 +1105,10 @@ diff --git a/buffer/access/index.html b/buffer/access/index.html new file mode 100644 index 00000000..a97ce682 --- /dev/null +++ b/buffer/access/index.html @@ -0,0 +1,1840 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Accessing a buffer's contents - SignalFlow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + Skip to content + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    + + + + + + + +

    Accessing in memory

    +

    The floating-point samples within a SignalFlow Buffer can be read and written directly from Python.

    +

    Using get and set methods

    +

    The get() and set() methods can be used to access individual samples, indexed by channel and frame offset.

    +
    # Create a 2-channel buffer
    +buf = Buffer(2, 256)
    +
    +# Set the sample in channel 1 at index 20 to 0.5
    +buf.set(1, 20, 0.5)
    +
    +# Confirm that the sample is set correctly
    +assert buf.get(1, 20) == 0.5
    +
    +

    As a numpy array

    +

    The .data property of a Buffer points to a numpy array of shape (num_channels, num_frames), which can be used to read or write the buffer's data in real time.

    +
    import time
    +
    +# Create and play a one-second silent buffer
    +buf = Buffer(2, graph.sample_rate)
    +player = BufferPlayer(buf, loop=True)
    +player.play()
    +
    +# Gradually add crackles to the buffer, which will be heard in real-time
    +while True:
    +    buf.data[0][np.random.randint(0, graph.sample_rate)] = 1.0
    +    buf.data[1][np.random.randint(0, graph.sample_rate)] = 1.0
    +    time.sleep(1)
    +
    +

    Filling a buffer with the result of a function

    +

    Just like when creating a buffer, an existing buffer can be filled with the output of a Python function.

    +
    +

    → Next: Arithmetic operators

    + +
    +
    + + + Last update: + 2024-01-14 + +
    + Created: + 2024-01-14 + + +
    +
    + + + + + + +
    +
    + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + \ No newline at end of file diff --git a/buffer/creating/index.html b/buffer/creating/index.html new file mode 100644 index 00000000..53c29f65 --- /dev/null +++ b/buffer/creating/index.html @@ -0,0 +1,1878 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Creating and loading - SignalFlow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + Skip to content + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + +
    +
    +
    + + + + + + + +
    +
    + + + + + + + +

    Creating a Buffer

    +

    A Buffer can be created from:

    + +

    Loading a buffer from a sound file

    +

    To load an audio buffer from a sound file, pass the file path to Buffer's constructor.

    +
    # Load and play a buffer
    +buf = Buffer("filename.wav")
    +player = BufferPlayer(buf)
    +player.play()
    +
    +

    The type of the audio file is automatically inferred from the type and contents. Supported formats include wav, aif, mp3, ogg, flac, and many other audio formats.

    +

    Interally, file I/O is handled by libsndfile. For a full list of supported files, see the libsndfile documentation.

    +
    +

    Creating a buffer from an array of samples

    +

    To create and initialise a buffer from an existing array of samples, pass the array to Buffer's constructor. Both native Python arrays and numpy arrays are supported.

    +

    Note that audio samples should always range between -1.0 and 1.0 to avoid distortion.

    +
    # Initialise a buffer from a native 1D array containing a sawtooth wave
    +samples = [(n % 100) / 100 - 0.5 for n in range(44100)]
    +buf = Buffer(samples)
    +player = BufferPlayer(buf)
    +player.play()
    +
    +

    If the array is 1D, a mono buffer will be created. If the array is 2D, a multichannel buffer will be created.

    +
    # Initialise a buffer from a numpy 2D array containing a stereo sine wave
    +import numpy as np
    +
    +t = np.linspace(0, 1, 44100)
    +stereo = np.array([np.sin(220 * t * np.pi * 2),
    +                   np.sin(225 * t * np.pi * 2)])
    +buf = Buffer(stereo * 0.1)
    +player = BufferPlayer(buf)
    +player.play()
    +
    +
    +

    Creating an empty buffer

    +

    An empty buffer can be initialised by specifying its dimensions. All samples will be initialised to zero.

    +
    # Create an empty buffer with 2 channels containing 44100 samples each.
    +buf = Buffer(2, 44100)
    +
    +
    +

    Initialising a buffer with the result of a function

    +

    A buffer can also be populated with the result of a Python function, which takes a single argument containing the index of the frame to be filled.

    +
    # Create a buffer containing a 440Hz ping
    +import numpy as np
    +buf = Buffer(1, graph.sample_rate,
    +             lambda frame: np.sin(frame * 440 * np.pi * 2 / graph.sample_rate) * (1 - frame / graph.sample_rate))
    +player = BufferPlayer(buf)
    +player.play()
    +
    +
    +

    → Next: Saving and exporting a buffer

    + +
    +
    + + + Last update: + 2024-01-14 + +
    + Created: + 2024-01-14 + + +
    +
    + + + + + + +
    +
    + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + \ No newline at end of file diff --git a/buffer/exporting/index.html b/buffer/exporting/index.html new file mode 100644 index 00000000..cf71889b --- /dev/null +++ b/buffer/exporting/index.html @@ -0,0 +1,1790 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Saving and exporting - SignalFlow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + Skip to content + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    + + + + + + + +

    Saving and exporting a buffer

    +

    Saving to a sound file

    +

    To export a buffer's audio contents to a sound file, use the save() method:

    +
    import numpy as np
    +buf = Buffer(np.sin(np.linspace(0, 1, graph.sample_rate) * 440 * np.pi * 2))
    +buf.save("buffer.wav")
    +
    +

    The output format will be automatically detected from the filename extension. Supported formats are presently wav, aif and flac.

    +
    +

    → Next: Passing a buffer as an input to a node or patch

    + +
    +
    + + + Last update: + 2024-01-14 + +
    + Created: + 2024-01-14 + + +
    +
    + + + + + + +
    +
    + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + \ No newline at end of file diff --git a/buffer/index.html b/buffer/index.html index 326602f1..d3ff2585 100644 --- a/buffer/index.html +++ b/buffer/index.html @@ -16,7 +16,7 @@ - + @@ -77,7 +77,7 @@
    - + Skip to content @@ -1052,7 +1052,7 @@
  • - Exporting and importing patches + Exporting and importing
  • @@ -1103,6 +1103,18 @@ + + + + + + + + + + + + @@ -1110,6 +1122,10 @@ @@ -1489,23 +1589,18 @@ -

    Buffer

    -
    -

    Warning

    -

    This documentation is a work-in-progress and may have sections that are missing or incomplete.

    -
    -

    A Buffer is an allocated area of memory that can be used to store single-channel or multi-channel data, which may represent an audio waveform or any other type of signal.

    +

    Buffers

    +

    A Buffer is an area of memory that stores single-channel or multi-channel data, which may represent an audio waveform or any other type of signal.


    @@ -1513,7 +1608,7 @@

    Buffer

    Last update: - 2023-01-03 + 2024-01-14
    Created: @@ -1564,13 +1659,13 @@

    Buffer

    -