mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-11-23 04:33:24 +00:00
Added asc.c, and asc.h.
Don't stop sound if we don't have to.
This commit is contained in:
parent
eedf6880db
commit
ce68f366cb
51
BasiliskII/src/MacOSX/asc.cpp
Normal file
51
BasiliskII/src/MacOSX/asc.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <asc.h>
|
||||
#include "MacOSX_sound_if.h"
|
||||
|
||||
static OSXsoundOutput *soundOutput = NULL;
|
||||
|
||||
static int audioInt(void);
|
||||
|
||||
bool asc_init(int32 sample_rate) {
|
||||
if(soundOutput != NULL) {
|
||||
delete soundOutput;
|
||||
soundOutput = NULL;
|
||||
}
|
||||
|
||||
soundOutput = new OSXsoundOutput();
|
||||
soundOutput->start(8, 1, sample_rate);
|
||||
soundOutput->setCallback(audioInt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asc_process_samples(const uae_u8 *samples, int count) {
|
||||
if(soundOutput == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(soundOutput->sendAudioBuffer((const void *)samples, count) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int audioInt(void) {
|
||||
asc_callback();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 asc_get_buffer_size() {
|
||||
if(soundOutput == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int32) soundOutput->bufferSizeFrames();
|
||||
}
|
||||
|
||||
void asc_stop() {
|
||||
delete soundOutput;
|
||||
soundOutput = NULL;
|
||||
}
|
13
BasiliskII/src/include/asc.h
Normal file
13
BasiliskII/src/include/asc.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef ASC_H
|
||||
#define ASC_H
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include "cpu_emulation.h"
|
||||
|
||||
bool asc_init(int32 sample_rate);
|
||||
bool asc_process_samples(const uae_u8 *samples, int count);
|
||||
int32 asc_get_buffer_size();
|
||||
void asc_callback();
|
||||
void asc_stop();
|
||||
|
||||
#endif
|
@ -280,8 +280,8 @@ static uae_u8 fifoA[fifoCapacity];
|
||||
static uae_u8 fifoB[fifoCapacity];
|
||||
static int32 ascBufferSize = -1;
|
||||
static int soundRunning = 0;
|
||||
static int soundStop = 0;
|
||||
static uae_u8 zeros[1024] = {0};
|
||||
static uae_u8 lastMode = 0;
|
||||
|
||||
extern uae_u32 io_read(uaecptr addr, int width_bits) {
|
||||
if((addr & 0x00ff000) == 0x0014000) {
|
||||
@ -334,12 +334,6 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) {
|
||||
static int downsample = 0;
|
||||
|
||||
if((addr & 0x00ff000) == 0x0014000) {
|
||||
if(soundStop) {
|
||||
asc_stop();
|
||||
soundRunning = 0;
|
||||
soundStop = 0;
|
||||
}
|
||||
|
||||
// Apple Sound Chip
|
||||
if(width_bits > 8) {
|
||||
fprintf(stderr,
|
||||
@ -383,8 +377,8 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) {
|
||||
ascBufferSize = asc_get_buffer_size();
|
||||
soundRunning = 1;
|
||||
|
||||
while(((fifoWriteA - fifoOutA) < (ascBufferSize*2)) &&
|
||||
((fifoInA - fifoWriteA) > ascBufferSize) ){
|
||||
while( //((fifoWriteA - fifoOutA) < (ascBufferSize*2)) &&
|
||||
((fifoInA - fifoWriteA) > ascBufferSize) ) {
|
||||
asc_process_samples(&fifoA[fifoWriteA % fifoCapacity],
|
||||
ascBufferSize);
|
||||
fifoWriteA += ascBufferSize;
|
||||
@ -401,11 +395,22 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) {
|
||||
// MODE
|
||||
// 1 = FIFO mode, 2 = wavetable mode
|
||||
ASCRegs[0x801] = b & 0x03;
|
||||
if(b == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(ASCRegs[0x801] != lastMode) {
|
||||
asc_stop();
|
||||
soundRunning = 0;
|
||||
fifoWriteA = fifoInA;
|
||||
}
|
||||
lastMode = ASCRegs[0x801];
|
||||
break;
|
||||
|
||||
case 0x802:
|
||||
if(ASCRegs[0x802] == b) {
|
||||
break;
|
||||
}
|
||||
// CONTROL
|
||||
// bit 0: analog or PWM output
|
||||
// bit 1: stereo/mono
|
||||
@ -416,9 +421,9 @@ extern void io_write(uaecptr addr, uae_u32 b, int width_bits) {
|
||||
case 0x803:
|
||||
// FIFO Mode
|
||||
if(b & 0x80) {
|
||||
downsample = 0;
|
||||
asc_stop();
|
||||
soundRunning = 0;
|
||||
if(fifoInA > (fifoWriteA + ascBufferSize)) {
|
||||
fifoInA = fifoWriteA + ascBufferSize;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -463,7 +468,8 @@ void asc_callback() {
|
||||
|
||||
fifoOutA += ascBufferSize;
|
||||
|
||||
if((fifoInA - fifoWriteA) >= ascBufferSize) {
|
||||
if( ((fifoInA - fifoWriteA) >= ascBufferSize) &&
|
||||
(ASCRegs[0x801] == 1)) {
|
||||
asc_process_samples(&fifoA[fifoWriteA % fifoCapacity], ascBufferSize);
|
||||
fifoWriteA += ascBufferSize;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user