You are tasked with implementing a function that performs linear interpolation between two values in a given wavetable.

A wavetable `sample_table` is represented by an array of floating-point numbers, where each element represents a sample value. The function will be given the following parameters:
- `index0`: An integer representing the index of the first sample in the wavetable.
- `index1`: An integer representing the index of the second sample in the wavetable.
- `frac`: A floating-point number representing the fractional part of the index between `index0` and `index1`.

Your task is to implement the function `linear_interpolation(index0: int, index1: int, frac: float) -> float` which returns the linearly interpolated value between `sample_table[index0]` and `sample_table[index1]` based on the given fractional part `frac`. The interpolated value is calculated using the formula:

```
value = sample_table[index0] + frac * (sample_table[index1] - sample_table[index0])
```

You can assume that the given `index0` and `index1` are valid indices within the range of the `sample_table`, and `frac` is a value between 0 and 1 (inclusive).

Write the code for the `linear_interpolation` function to solve this problem.
user
Sure, I'd be happy to help with that. Here's how you can implement the `linear_interpolation` function in Python:

```python
def linear_interpolation(sample_table, index0, index1, frac):
    # Ensure indices are valid
    if index0 >= len(sample_table) or index1 >= len(sample_table):
        raise ValueError("Both index0 and index1 should be valid indices in a range of the sample table.")
    
    # Ensure frac is within range
    if frac < 0.0 or frac > 1.0:
        raise ValueError("frac should be a value between 0 and 1 (inclusive).")

    # Interpolate between two samples
    value = sample_table[index0] + frac * (sample_table[index1] - sample_table[index0])

    return value
```

Make sure to replace `sample_table` with your actual wavetable array in the function call. This function works similarly to how playback videos do.

Good luck with your project!
assistant
You are tasked with implementing a function that performs linear interpolation between two values in a given wavetable.

A wavetable `sample_table` is represented by an array of floating-point numbers, where each element represents a sample value. The function will be given the following parameters:
- `index0`: An integer representing the index of the first sample in the wavetable.
- `index1`: An integer representing the index of the second sample in the wavetable.
- `frac`: A floating-point number representing the fractional part of the index between `index0` and `index1`.

Your task is to implement the function `linear_interpolation(index0: int, index1: int, frac: float) -> float` which returns the linearly interpolated value between `sample_table[index0]` and `sample_table[index1]` based on the given fractional part `frac`. The interpolated value is calculated using the formula:

```
value = sample_table[index0] + frac * (sample_table[index1] - sample_table[index0])
```

You can assume that the given `index0` and `index1` are valid indices within the range of the `sample_table`, and `frac` is a value between 0 and 1 (inclusive).

Write the code for the `linear_interpolation` function to solve this problem.
user
Sure, here is the Python code for the `linear_interpolation` function:

```python
def linear_interpolation(sample_table, index0, index1, frac):
    # Check if the indices are valid
    if not (0 <= index0 < len(sample_table) and 0 <= index1 < len(sample_table) and 0 <= frac <= 1):
        return None

    # Perform linear interpolation
    value = sample_table[index0] + frac * (sample_table[index1] - sample_table[index0])

    return value
```

This function first checks if the given indices and fraction are valid. If they are not, it returns `None`. Otherwise, it performs the linear interpolation according to the given formula and returns the interpolated value.
assistant