mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-09-29 11:55:21 +00:00
Reworking sound bits
This commit is contained in:
parent
1d793f640a
commit
e7c702136c
@ -25,6 +25,7 @@ import jace.core.Device;
|
||||
import jace.core.Motherboard;
|
||||
import jace.core.RAMEvent;
|
||||
import jace.core.RAMListener;
|
||||
import jace.core.SoundGeneratorDevice;
|
||||
import jace.core.SoundMixer;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -44,7 +45,7 @@ import javax.sound.sampled.SourceDataLine;
|
||||
*
|
||||
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
||||
*/
|
||||
public class Speaker extends Device {
|
||||
public class Speaker extends SoundGeneratorDevice {
|
||||
|
||||
static boolean fileOutputActive = false;
|
||||
static OutputStream out;
|
||||
@ -126,10 +127,10 @@ public class Speaker extends Device {
|
||||
* Double-buffer used for playing processed sound -- as one is played the
|
||||
* other fills up.
|
||||
*/
|
||||
byte[] primaryBuffer;
|
||||
byte[] secondaryBuffer;
|
||||
int bufferPos = 0;
|
||||
Timer playbackTimer;
|
||||
private byte[] primaryBuffer;
|
||||
private byte[] secondaryBuffer;
|
||||
private int bufferPos = 0;
|
||||
private Timer playbackTimer;
|
||||
private final double TICKS_PER_SAMPLE = ((double) Motherboard.SPEED) / SoundMixer.RATE;
|
||||
private final double TICKS_PER_SAMPLE_FLOOR = Math.floor(TICKS_PER_SAMPLE);
|
||||
private RAMListener listener = null;
|
||||
@ -292,6 +293,8 @@ public class Speaker extends Device {
|
||||
|
||||
@Override
|
||||
public final void reconfigure() {
|
||||
super.reconfigure();
|
||||
|
||||
if (primaryBuffer != null && secondaryBuffer != null) {
|
||||
return;
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018 org.badvision.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package jace.core;
|
||||
|
||||
/**
|
||||
* Encapsulate a thread-managed sound device, abstracting aspects of buffer and device management
|
||||
*/
|
||||
public abstract class SoundGeneratorDevice extends Device {
|
||||
public SoundGeneratorDevice(Computer computer) {
|
||||
super(computer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconfigure() {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attach() {
|
||||
super.attach();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
super.detach();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -154,16 +154,14 @@ public class SoundMixer extends Device {
|
||||
sdl = availableLines.iterator().next();
|
||||
availableLines.remove(sdl);
|
||||
}
|
||||
activeLines.put(requester, sdl);
|
||||
sdl.start();
|
||||
activeLines.put(requester, sdl);
|
||||
return sdl;
|
||||
}
|
||||
|
||||
public void returnLine(Object requester) {
|
||||
if (activeLines.containsKey(requester)) {
|
||||
SourceDataLine sdl = activeLines.remove(requester);
|
||||
// Calling drain on pulse driver can cause it to freeze up (?)
|
||||
// sdl.drain();
|
||||
if (sdl.isRunning()) {
|
||||
sdl.flush();
|
||||
sdl.stop();
|
||||
@ -207,16 +205,18 @@ public class SoundMixer extends Device {
|
||||
|
||||
@Override
|
||||
public void attach() {
|
||||
// if (Motherboard.enableSpeaker)
|
||||
// Motherboard.speaker.attach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
availableLines.stream().forEach((line) -> {
|
||||
line.flush();
|
||||
line.stop();
|
||||
line.close();
|
||||
});
|
||||
});
|
||||
Set requesters = new HashSet(activeLines.keySet());
|
||||
availableLines.clear();
|
||||
activeLines.clear();
|
||||
requesters.stream().map((o) -> {
|
||||
if (o instanceof Device) {
|
||||
((Device) o).detach();
|
||||
@ -225,15 +225,6 @@ public class SoundMixer extends Device {
|
||||
}).filter((o) -> (o instanceof Card)).forEach((o) -> {
|
||||
((Reconfigurable) o).reconfigure();
|
||||
});
|
||||
if (theMixer != null) {
|
||||
for (Line l : theMixer.getSourceLines()) {
|
||||
// if (l.isOpen()) {
|
||||
// l.close();
|
||||
// }
|
||||
}
|
||||
}
|
||||
availableLines.clear();
|
||||
activeLines.clear();
|
||||
super.detach();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user