Scrape

class in Clatter.Core

Inherits from AudioEvent

Generates scrape audio.

A Scrape is a series of continuous events. By repeatedly calling GetAudio(), the scrape event will continue.

Scrape events are automatically generated from collision data within AudioGenerator. You can also manually create a Scrape and use it to generate audio without needing to use an AudioGenerator. This can be useful if you want to generate audio without needing to create a physics simulation.

Constants

Name Type Description Default Value
SAMPLES_LENGTH int The length of the scrape samples. 4410

Static Fields

Name Type Description Default Value
scrapeAmp double When setting the amplitude for a scrape, multiply AudioEvent.simulationAmp by this factor. 1
maxSpeed double For the purposes of scrape audio generation, the collision speed is clamped to this maximum value in meters per second. 5
simulationAmp double The overall amplitude of the simulation. The amplitude of generated audio is scaled by this factor. Must be between 0 and 0.99 Inherited from AudioEvent. 0.9

Fields

Name Type Description Default Value
scrapeId int The ID of this scrape event. This is used to track an ongoing scrape. Readonly.
samples Samples The audio samples generated from this event. Readonly. Inherited from AudioEvent.
state EventState The current state of the AudioEvent. This is not the same thing as whether any audio is playing. An Impact ends when too much time has elapsed since the most recent impact collision. A Scrape ends when the object is moving too slowly. Inherited from AudioEvent. EventState.start

Static Methods

GetNumScrapeEvents

public static int GetNumScrapeEvents(double duration)

Returns the number of scrape events given a duration.

Name Type Description
duration double The duration of the scrape in seconds.

Methods

Scrape

public Scrape(ScrapeMaterial scrapeMaterial, ClatterObjectData primary, ClatterObjectData secondary, Random rng)

Name Type Description
scrapeMaterial ScrapeMaterial The scrape material.
primary ClatterObjectData The primary object (the smaller, moving object).
secondary ClatterObjectData The secondary object (the scrape surface).
rng Random The random number generator.

GetAudio

public override bool GetAudio(double speed)

Generate audio. Returns true if audio was generated. This will set the samples field.

Inherited from AudioEvent.

Name Type Description
speed double The collision speed in meters per second.

Code Examples

using System;
using Clatter.Core;

public class ScrapeAudioExample
{
    private static void Main(string[] args)
    {
        // Load the materials.
        ImpactMaterial primaryMaterial = ImpactMaterial.glass_1;
        ImpactMaterial secondaryMaterial = ImpactMaterial.stone_4;
        ScrapeMaterial scrapeMaterial = ScrapeMaterial.ceramic;
        ImpactMaterialData.Load(primaryMaterial);
        ImpactMaterialData.Load(secondaryMaterial);
        ScrapeMaterialData.Load(scrapeMaterial);
        // Set the objects.
        ClatterObjectData primary = new ClatterObjectData(0, primaryMaterial, 0.2, 0.2, 1);
        ClatterObjectData secondary = new ClatterObjectData(1, secondaryMaterial, 0.5, 0.1, 100, scrapeMaterial);
        // Initialize the scrape.
        Scrape scrape = new Scrape(scrapeMaterial, primary, secondary, new Random());
        // Start writing audio.
        WavWriter writer = new WavWriter("out.wav", overwrite: true);
        // Generate the scrape.
        int count = Scrape.GetNumScrapeEvents(0.5);
        for (int i = 0; i < count; i++)
        {
            scrape.GetAudio(1);
            writer.Write(scrape.samples.ToInt16Bytes());
        }
        writer.End();
    }
}