-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using NAudio.Dsp; | ||
|
||
namespace osu.Framework.Audio | ||
|
@@ -31,8 +30,8 @@ public double RelativeRate | |
/// <summary> | ||
/// Creates a new <see cref="ResamplingPlayer"/>. | ||
/// </summary> | ||
/// <param name="srcRate">Sampling rate of audio that's given from <see cref="GetRemainingRawFloats(float[], int, int)"/> or <see cref="GetRemainingRawBytes(byte[])"/></param> | ||
/// <param name="srcChannels">Channels of audio that's given from <see cref="GetRemainingRawFloats(float[], int, int)"/> or <see cref="GetRemainingRawBytes(byte[])"/></param> | ||
/// <param name="srcRate">Sampling rate of audio that's given from <see cref="GetRemainingRawFloats(float[], int, int)"/></param> | ||
/// <param name="srcChannels">Channels of audio that's given from <see cref="GetRemainingRawFloats(float[], int, int)"/></param> | ||
protected ResamplingPlayer(int srcRate, byte srcChannels) | ||
{ | ||
SrcRate = srcRate; | ||
|
@@ -105,32 +104,6 @@ public virtual int GetRemainingSamples(float[] data) | |
return 0; | ||
} | ||
|
||
// must implement either (preferably float one) | ||
|
||
private byte[]? bytes; | ||
|
||
protected virtual int GetRemainingRawFloats(float[] data, int offset, int needed) | ||
{ | ||
if (bytes == null || needed * 4 != bytes.Length) | ||
bytes = new byte[needed * 4]; | ||
|
||
int got = GetRemainingRawBytes(bytes); | ||
|
||
if (got > 0) Buffer.BlockCopy(bytes, 0, data, offset * 4, got); | ||
return got / 4; | ||
} | ||
|
||
private float[]? floats; | ||
|
||
protected virtual int GetRemainingRawBytes(byte[] data) | ||
{ | ||
if (floats == null || data.Length / 4 != floats.Length) | ||
floats = new float[data.Length / 4]; | ||
|
||
int got = GetRemainingRawFloats(floats, 0, floats.Length); | ||
|
||
if (got > 0) Buffer.BlockCopy(floats, 0, data, 0, got * 4); | ||
return got * 4; | ||
} | ||
protected abstract int GetRemainingRawFloats(float[] data, int offset, int needed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters