Skip to content
Browse files

Better Audio samples/second precision

Disable Audio Monitor if no sound capability
  • Loading branch information...
1 parent 94cd010 commit 09eb8deec07be391199bbaa40442110ab7c70ad8 @ppeccin committed
View
3 src/atari/tia/TIA.java
@@ -44,6 +44,7 @@ public AudioGenerator audioOutput() { // AudioSignal
public void videoStandard(VideoStandard standard) {
videoOutput.standard = standard;
+ audioOutput.videoStandard = standard;
palette = standard.equals(VideoStandard.NTSC) ? NTSCPalette.getPalette() : PALPalette.getPalette();
}
@@ -119,7 +120,7 @@ public void clockPulse() {
audioOutput.generateNextSamples(1);
} while (!videoOutputVSynched && powerOn);
if (powerOn) {
- audioOutput.sendGeneratedSamplesToMonitor(); // TODO Ensure right amount of samples / second
+ audioOutput.sendSamplesFrameToMonitor();
// If needed, synch with audio output after each frame
if (SYNC_WITH_AUDIO_MONITOR) audioOutput.monitor.synchOutput();
// If needed, synch with video output
View
26 src/atari/tia/audio/AudioGenerator.java
@@ -4,6 +4,7 @@
import general.av.audio.AudioMonitor;
import general.av.audio.AudioSignal;
+import general.av.video.VideoStandard;
import javax.sound.sampled.AudioFormat;
@@ -19,7 +20,10 @@ public void connectMonitor(AudioMonitor monitor) {
this.monitor = monitor;
}
- public abstract void generateNextSamples(int samples);
+ public void generateNextSamples(int samples) {
+ int remainingSamples = Math.max(desiredSamplesPerFrame() - generatedSamples, 0);
+ internalGenerateNextSamples(Math.min(samples, remainingSamples));
+ }
public ChannelStream channel0() {
return channel0;
@@ -29,20 +33,28 @@ public ChannelStream channel1() {
return channel1;
}
- public void sendGeneratedSamplesToMonitor() {
- if (monitor != null)
- monitor.nextSamples(samples, generatedSamples);
+ public void sendSamplesFrameToMonitor() {
+ int missingSamples = desiredSamplesPerFrame() - generatedSamples;
+ if (missingSamples > 0) generateNextSamples(missingSamples);
+ if (monitor != null) monitor.nextSamples(samples, generatedSamples);
generatedSamples = 0;
}
+ protected abstract void internalGenerateNextSamples(int min);
+
+ private int desiredSamplesPerFrame() {
+ return videoStandard.height * 2; // Perfect amount is 2 samples per scan line
+ }
+
protected final ChannelStream channel0 = new ChannelStream();
protected final ChannelStream channel1 = new ChannelStream();
public AudioMonitor monitor;
+ public VideoStandard videoStandard;
+
+ protected int generatedSamples = 0;
- public int generatedSamples = 0;
-
- protected final byte[] samples = new byte[1048];
+ protected final byte[] samples = new byte[1024]; // More than enough samples for a frame
protected static final float MAX_AMPLITUDE = Parameters.TIA_AUDIO_MAX_AMPLITUDE;
View
3 src/atari/tia/audio/AudioMonoGenerator.java
@@ -9,9 +9,8 @@
public final class AudioMonoGenerator extends AudioGenerator {
@Override
- public void generateNextSamples(int quant) {
+ protected void internalGenerateNextSamples(int quant) {
for (int i = 0; i < quant; i++) {
- if (generatedSamples >= samples.length) return;
float mixedSample = channel0.nextSample() * MAX_MONO_CHANNEL_AMPLITUDE + channel1.nextSample() * MAX_MONO_CHANNEL_AMPLITUDE;
samples[generatedSamples++] = ((byte) (mixedSample * (MAX_AMPLITUDE * 127)));
}
View
2 src/parameters/Parameters.java
@@ -159,7 +159,7 @@ private static void processProperties() {
public static double TIA_FORCED_CLOCK = 0; // 0 = No Forced Clock
public static double TIA_DEFAULT_CLOCK_NTSC = 60;
- public static double TIA_DEFAULT_CLOCK_PAL = 50.39;
+ public static double TIA_DEFAULT_CLOCK_PAL = 50.384615;
public static boolean TIA_SYNC_WITH_AUDIO_MONITOR = false;
public static boolean TIA_SYNC_WITH_VIDEO_MONITOR = false;
View
2 src/parameters/javatari.properties
@@ -1 +1 @@
-
+
View
2 src/parameters/javatari.single.properties
@@ -1 +1 @@
-
+
View
6 src/pc/speaker/Speaker.java
@@ -11,7 +11,6 @@
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import parameters.Parameters;
@@ -39,9 +38,8 @@ public void init() {
if (ADDED_THREAD_PRIORITY != 0) clock.setPriority(Thread.NORM_PRIORITY + ADDED_THREAD_PRIORITY);
System.out.println("Sound Mixer Line: " + dataLine);
System.out.println("Sound Output buffer: " + dataLine.getBufferSize());
- System.out.println("Sound Input buffer: " + inputBuffer.capacity());
- } catch (LineUnavailableException e) {
- System.out.println("Unable to acquire audio line");
+ } catch (Exception ex) {
+ System.out.println("Unable to acquire audio line:\n" + ex);
dataLine = null;
}
}

0 comments on commit 09eb8de

Please sign in to comment.
Something went wrong with that request. Please try again.