mirror of
https://github.com/trudnai/Steve2.git
synced 2025-02-09 09:31:57 +00:00
- spkr_switch renamed to spkr_toggle and moved to speaker.c
- Also some minor tweaks and cosmetics
This commit is contained in:
parent
ae5d8211fb
commit
bde4c4d941
@ -849,7 +849,6 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) {
|
|||||||
mhz = (double)MHz_6502 / M;
|
mhz = (double)MHz_6502 / M;
|
||||||
|
|
||||||
spkr_init();
|
spkr_init();
|
||||||
spkr_playStart();
|
|
||||||
|
|
||||||
unsigned long long saved_frm_set = clk_6502_per_frm_set;
|
unsigned long long saved_frm_set = clk_6502_per_frm_set;
|
||||||
clk_6502_per_frm =
|
clk_6502_per_frm =
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "../../src/dev/audio/speaker.h" // So we can access to speaker stuff from Swift
|
#include "../../src/dev/audio/speaker.h" // So we can access to speaker stuff from Swift
|
||||||
|
|
||||||
|
|
||||||
|
extern const unsigned long long default_MHz_6502;
|
||||||
extern unsigned long long MHz_6502;
|
extern unsigned long long MHz_6502;
|
||||||
extern unsigned long long clk_6502_per_frm;
|
extern unsigned long long clk_6502_per_frm;
|
||||||
extern unsigned long long clk_6502_per_frm_set;
|
extern unsigned long long clk_6502_per_frm_set;
|
||||||
|
@ -55,20 +55,8 @@ ALCcontext *ctx = NULL;
|
|||||||
ALuint spkr_buf = 0;
|
ALuint spkr_buf = 0;
|
||||||
ALuint spkr_src = 0;
|
ALuint spkr_src = 0;
|
||||||
|
|
||||||
// we start with the max, because otherwise the speaker clicks
|
|
||||||
int spkr_level = SPKR_LEVEL_MAX;
|
|
||||||
|
|
||||||
|
int spkr_level = SPKR_LEVEL_ZERO;
|
||||||
const int spkr_fps = fps;
|
|
||||||
const int spkr_seconds = 1;
|
|
||||||
const unsigned spkr_sample_rate = 44100;
|
|
||||||
unsigned spkr_extra_buf = 13; // TODO: Should it be a dynamic value calculated by how many bytes we overshot by the edge curve generator?
|
|
||||||
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate / spkr_fps;
|
|
||||||
char spkr_samples [ spkr_buf_size * spkr_fps * 2]; // 1s of sound
|
|
||||||
unsigned spkr_sample_idx = 0;
|
|
||||||
|
|
||||||
const unsigned spkr_play_timeout = 10;
|
|
||||||
unsigned spkr_play_time = 0;
|
|
||||||
|
|
||||||
|
|
||||||
#define BUFFER_COUNT 10
|
#define BUFFER_COUNT 10
|
||||||
@ -77,10 +65,25 @@ unsigned spkr_play_time = 0;
|
|||||||
ALuint spkr_buffers[BUFFER_COUNT];
|
ALuint spkr_buffers[BUFFER_COUNT];
|
||||||
|
|
||||||
|
|
||||||
|
const int spkr_fps = fps;
|
||||||
|
const int spkr_seconds = 1;
|
||||||
|
const unsigned spkr_sample_rate = 44100;
|
||||||
|
unsigned spkr_extra_buf = 13; // TODO: Should it be a dynamic value calculated by how many bytes we overshot by the edge curve generator?
|
||||||
|
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate / spkr_fps;
|
||||||
|
char spkr_samples [ spkr_buf_size * spkr_fps * BUFFER_COUNT];
|
||||||
|
unsigned spkr_sample_idx = 0;
|
||||||
|
|
||||||
|
const unsigned spkr_play_timeout = 10;
|
||||||
|
unsigned spkr_play_time = 0;
|
||||||
|
|
||||||
|
|
||||||
// initialize OpenAL
|
// initialize OpenAL
|
||||||
void spkr_init() {
|
void spkr_init() {
|
||||||
const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
|
const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||||
printf( "Default device: %s\n", defname );
|
printf( "Default device: %s\n", defname );
|
||||||
|
|
||||||
|
// restart OpenAL when restarting the virtual machine
|
||||||
|
spkr_exit();
|
||||||
|
|
||||||
dev = alcOpenDevice(defname);
|
dev = alcOpenDevice(defname);
|
||||||
ctx = alcCreateContext(dev, NULL);
|
ctx = alcCreateContext(dev, NULL);
|
||||||
@ -116,22 +119,65 @@ void spkr_init() {
|
|||||||
|
|
||||||
// Dealloc OpenAL
|
// Dealloc OpenAL
|
||||||
void spkr_exit() {
|
void spkr_exit() {
|
||||||
ALCdevice *dev = NULL;
|
if ( spkr_src ) {
|
||||||
ALCcontext *ctx = NULL;
|
ALCdevice *dev = NULL;
|
||||||
ctx = alcGetCurrentContext();
|
ALCcontext *ctx = NULL;
|
||||||
dev = alcGetContextsDevice(ctx);
|
ctx = alcGetCurrentContext();
|
||||||
|
dev = alcGetContextsDevice(ctx);
|
||||||
alcMakeContextCurrent(NULL);
|
|
||||||
alcDestroyContext(ctx);
|
alcMakeContextCurrent(NULL);
|
||||||
alcCloseDevice(dev);
|
alcDestroyContext(ctx);
|
||||||
|
alcCloseDevice(dev);
|
||||||
al_check_error();
|
|
||||||
|
al_check_error();
|
||||||
|
|
||||||
|
spkr_src = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spkr_playStart() {
|
|
||||||
|
void spkr_toggle() {
|
||||||
|
// TODO: This is very slow!
|
||||||
|
// printf("io_KBDSTRB\n");
|
||||||
|
|
||||||
|
spkr_play_time = spkr_play_timeout;
|
||||||
|
|
||||||
|
// push a click into the speaker buffer
|
||||||
|
// (we will play the entire buffer at the end of the frame)
|
||||||
|
spkr_sample_idx = clkfrm / (default_MHz_6502 / spkr_sample_rate);
|
||||||
|
|
||||||
|
if ( spkr_level > SPKR_LEVEL_MIN ) {
|
||||||
|
// down edge
|
||||||
|
while( (spkr_level -= (spkr_level - SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
|
||||||
|
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
||||||
|
}
|
||||||
|
spkr_level = SPKR_LEVEL_MIN;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// up edge
|
||||||
|
while( (spkr_level += (SPKR_LEVEL_MAX - spkr_level) / 2 ) < SPKR_LEVEL_MAX - 1 ) {
|
||||||
|
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
||||||
|
}
|
||||||
|
spkr_level = SPKR_LEVEL_MAX;
|
||||||
|
}
|
||||||
|
//spkr_samples[sample_idx] = spkr_level;
|
||||||
|
memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_size);
|
||||||
|
|
||||||
|
//ViewController_spk_up_play();
|
||||||
|
|
||||||
|
|
||||||
|
// case io_VID_CLR80VID:
|
||||||
|
// videoMode.col80 = 0;
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case io_VID_SET80VID:
|
||||||
|
// videoMode.col80 = 1;
|
||||||
|
// break;
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ALint freeBuffers = BUFFER_COUNT;
|
ALint freeBuffers = BUFFER_COUNT;
|
||||||
//ALuint alBuffers[BUFFER_COUNT];
|
//ALuint alBuffers[BUFFER_COUNT];
|
||||||
|
|
||||||
|
@ -15,9 +15,6 @@
|
|||||||
#define SPKR_LEVEL_MAX 255
|
#define SPKR_LEVEL_MAX 255
|
||||||
#define SPKR_LEVEL_ZERO ( SPKR_LEVEL_MIN + SPKR_LEVEL_MAX / 2 )
|
#define SPKR_LEVEL_ZERO ( SPKR_LEVEL_MIN + SPKR_LEVEL_MAX / 2 )
|
||||||
|
|
||||||
extern void spkr_init(void);
|
|
||||||
extern void spkr_exit(void);
|
|
||||||
extern void spkr_update(void);
|
|
||||||
|
|
||||||
extern const unsigned spkr_sample_rate;
|
extern const unsigned spkr_sample_rate;
|
||||||
extern const unsigned spkr_buf_size;
|
extern const unsigned spkr_buf_size;
|
||||||
@ -32,5 +29,10 @@ extern const unsigned spkr_play_timeout;
|
|||||||
extern unsigned spkr_play_time;
|
extern unsigned spkr_play_time;
|
||||||
|
|
||||||
|
|
||||||
|
extern void spkr_init(void);
|
||||||
|
extern void spkr_exit(void);
|
||||||
|
extern void spkr_update(void);
|
||||||
|
extern void spkr_toggle(void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* speaker_h */
|
#endif /* speaker_h */
|
||||||
|
@ -400,47 +400,6 @@ void auxMemorySelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INLINE void spkr_switch() {
|
|
||||||
// TODO: This is very slow!
|
|
||||||
// printf("io_KBDSTRB\n");
|
|
||||||
|
|
||||||
spkr_play_time = spkr_play_timeout;
|
|
||||||
|
|
||||||
// push a click into the speaker buffer
|
|
||||||
// (we will play the entire buffer at the end of the frame)
|
|
||||||
spkr_sample_idx = clkfrm / (default_MHz_6502 / spkr_sample_rate);
|
|
||||||
|
|
||||||
if ( spkr_level > SPKR_LEVEL_MIN ) {
|
|
||||||
// down edge
|
|
||||||
while( (spkr_level -= (spkr_level - SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
|
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
|
||||||
}
|
|
||||||
spkr_level = SPKR_LEVEL_MIN;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// up edge
|
|
||||||
while( (spkr_level += (SPKR_LEVEL_MAX - spkr_level) / 2 ) < SPKR_LEVEL_MAX - 1 ) {
|
|
||||||
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
|
|
||||||
}
|
|
||||||
spkr_level = SPKR_LEVEL_MAX;
|
|
||||||
}
|
|
||||||
//spkr_samples[sample_idx] = spkr_level;
|
|
||||||
memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_buf_size);
|
|
||||||
|
|
||||||
//ViewController_spk_up_play();
|
|
||||||
|
|
||||||
|
|
||||||
// case io_VID_CLR80VID:
|
|
||||||
// videoMode.col80 = 0;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
// case io_VID_SET80VID:
|
|
||||||
// videoMode.col80 = 1;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
INLINE uint8_t ioRead( uint16_t addr ) {
|
INLINE uint8_t ioRead( uint16_t addr ) {
|
||||||
// if (outdev) fprintf(outdev, "ioRead:%04X\n", addr);
|
// if (outdev) fprintf(outdev, "ioRead:%04X\n", addr);
|
||||||
// printf("ioRead:%04X (PC:%04X)\n", addr, m6502.PC);
|
// printf("ioRead:%04X (PC:%04X)\n", addr, m6502.PC);
|
||||||
@ -459,7 +418,7 @@ INLINE uint8_t ioRead( uint16_t addr ) {
|
|||||||
return Apple2_64K_RAM[io_KBDSTRB];
|
return Apple2_64K_RAM[io_KBDSTRB];
|
||||||
|
|
||||||
case (uint8_t)io_SPKR:
|
case (uint8_t)io_SPKR:
|
||||||
spkr_switch();
|
spkr_toggle();
|
||||||
return Apple2_64K_RAM[io_SPKR];
|
return Apple2_64K_RAM[io_SPKR];
|
||||||
|
|
||||||
case (uint8_t)io_VID_RDTEXT:
|
case (uint8_t)io_VID_RDTEXT:
|
||||||
@ -721,7 +680,7 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case io_SPKR:
|
case io_SPKR:
|
||||||
spkr_switch();
|
spkr_toggle();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case io_RDMAINRAM:
|
case io_RDMAINRAM:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user