mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 00:57:31 -05:00
Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -30,6 +30,16 @@ import javax.sound.sampled.AudioFormat;
|
||||
*/
|
||||
public abstract class AudioProvider
|
||||
{
|
||||
/**
|
||||
* Converts the audio sample to a 16-bit PCM sample, limiting out of range values instead of allowing them to wrap.
|
||||
* @param sample in range -1.0 to 1.0
|
||||
* @return PCM sample
|
||||
*/
|
||||
protected static short toPcm(float sample)
|
||||
{
|
||||
return (short)(Math.clamp(sample, -1.0f, 1.0f) * Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Audio format for this provider
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AudioProviderMono extends AudioProvider
|
||||
|
||||
for(int x = 0; x < AudioChannel.SAMPLES_PER_INTERVAL; x++)
|
||||
{
|
||||
shortBuffer.put((short) (audio[x] * Short.MAX_VALUE));
|
||||
shortBuffer.put(toPcm(audio[x]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
@@ -108,7 +108,7 @@ public class AudioProviderMultiChannel extends AudioProvider
|
||||
{
|
||||
for(int channelNumber = 0; channelNumber < mAudioChannels.size(); channelNumber++)
|
||||
{
|
||||
shortBuffer.put((short)(samples[channelNumber][sampleCounter] * Short.MAX_VALUE));
|
||||
shortBuffer.put(toPcm(samples[channelNumber][sampleCounter]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,8 +102,8 @@ public class AudioProviderStereo extends AudioProvider
|
||||
|
||||
for(int x = 0; x < AudioChannel.SAMPLES_PER_INTERVAL; x++)
|
||||
{
|
||||
shortBuffer.put((short)(left[x] * Short.MAX_VALUE));
|
||||
shortBuffer.put((short)(right[x] * Short.MAX_VALUE));
|
||||
shortBuffer.put(toPcm(left[x]));
|
||||
shortBuffer.put(toPcm(right[x]));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
Reference in New Issue
Block a user