mirror of
https://github.com/trudnai/Steve2.git
synced 2025-01-02 18:32:37 +00:00
Speaker sound buffer to generate perfect square waves
This commit is contained in:
parent
cf2325e6fa
commit
b746b1ee5c
@ -427,8 +427,8 @@
|
|||||||
32A9F7472467B5DF004902A1 /* audio */ = {
|
32A9F7472467B5DF004902A1 /* audio */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
32A9F7492467B60B004902A1 /* speaker.c */,
|
|
||||||
32A9F7482467B60B004902A1 /* speaker.h */,
|
32A9F7482467B60B004902A1 /* speaker.h */,
|
||||||
|
32A9F7492467B60B004902A1 /* speaker.c */,
|
||||||
);
|
);
|
||||||
path = audio;
|
path = audio;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -713,10 +713,6 @@ void softReset() {
|
|||||||
|
|
||||||
void m6502_Run() {
|
void m6502_Run() {
|
||||||
|
|
||||||
// clear speaker buffer, so we can fill it up by new data
|
|
||||||
memset(spkr_samples, 127, spkr_buf_size);
|
|
||||||
|
|
||||||
|
|
||||||
// init time
|
// init time
|
||||||
//#ifdef CLK_WAIT
|
//#ifdef CLK_WAIT
|
||||||
// unsigned long long elpased = (unsigned long long)-1LL;
|
// unsigned long long elpased = (unsigned long long)-1LL;
|
||||||
@ -778,7 +774,11 @@ void m6502_Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
spkr_play();
|
spkr_play();
|
||||||
|
// clear speaker buffer, so we can fill it up by new data
|
||||||
|
memset(spkr_samples, spkr_level, spkr_buf_size);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_rom( const char * bundlePath, const char * filename, uint8_t * rom, const uint16_t addr ) {
|
void read_rom( const char * bundlePath, const char * filename, uint8_t * rom, const uint16_t addr ) {
|
||||||
|
@ -48,6 +48,10 @@ 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
|
||||||
|
uint8_t spkr_level = SPKR_LEVEL_MAX;
|
||||||
|
|
||||||
|
|
||||||
const int spkr_seconds = 1;
|
const int spkr_seconds = 1;
|
||||||
const unsigned spkr_sample_rate = 44100;
|
const unsigned spkr_sample_rate = 44100;
|
||||||
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate;
|
const unsigned spkr_buf_size = spkr_seconds * spkr_sample_rate;
|
||||||
@ -64,7 +68,7 @@ void spkr_init() {
|
|||||||
alcMakeContextCurrent(ctx);
|
alcMakeContextCurrent(ctx);
|
||||||
|
|
||||||
// Fill buffer with zeros
|
// Fill buffer with zeros
|
||||||
memset( spkr_samples, 127, spkr_buf_size );
|
memset( spkr_samples, spkr_level, spkr_buf_size );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,4 +116,6 @@ void spkr_play() {
|
|||||||
alSourcei(spkr_src, AL_LOOPING, 0);
|
alSourcei(spkr_src, AL_LOOPING, 0);
|
||||||
|
|
||||||
alSourcePlay(spkr_src);
|
alSourcePlay(spkr_src);
|
||||||
|
|
||||||
|
memset(spkr_samples, spkr_level, spkr_buf_size);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define SPKR_LEVEL_MIN 0
|
||||||
|
#define SPKR_LEVEL_MAX 127
|
||||||
|
|
||||||
extern void spkr_init(void);
|
extern void spkr_init(void);
|
||||||
extern void spkr_exit(void);
|
extern void spkr_exit(void);
|
||||||
@ -19,5 +21,8 @@ extern void spkr_play(void);
|
|||||||
extern const unsigned spkr_buf_size;
|
extern const unsigned spkr_buf_size;
|
||||||
extern char spkr_samples [];
|
extern char spkr_samples [];
|
||||||
|
|
||||||
|
extern uint8_t spkr_level;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* speaker_h */
|
#endif /* speaker_h */
|
||||||
|
@ -48,7 +48,6 @@ uint8_t * const RDHIMEM = Apple2_64K_MEM; // Pointer to the Shadow Memory
|
|||||||
uint8_t * const WRHIMEM = Apple2_Dummy_RAM; // Pointer to the Shadow Memory Map so we can use this from Swift
|
uint8_t * const WRHIMEM = Apple2_Dummy_RAM; // Pointer to the Shadow Memory Map so we can use this from Swift
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DEF_RAM_PAGE(mem,pg) \
|
#define DEF_RAM_PAGE(mem,pg) \
|
||||||
(mem) + ((pg) << 8)
|
(mem) + ((pg) << 8)
|
||||||
|
|
||||||
@ -401,6 +400,35 @@ void auxMemorySelect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INLINE void spkr_switch() {
|
||||||
|
// TODO: This is very slow!
|
||||||
|
// printf("io_KBDSTRB\n");
|
||||||
|
|
||||||
|
// push a click into the speaker buffer
|
||||||
|
// (we will play the entire buffer at the end of the frame)
|
||||||
|
int sample_idx = clkfrm / 22;
|
||||||
|
if ( spkr_level > SPKR_LEVEL_MIN ) {
|
||||||
|
spkr_level = SPKR_LEVEL_MIN;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spkr_level = SPKR_LEVEL_MAX;
|
||||||
|
}
|
||||||
|
//spkr_samples[sample_idx] = spkr_level;
|
||||||
|
memset(spkr_samples + sample_idx, spkr_level, spkr_buf_size - sample_idx);
|
||||||
|
|
||||||
|
//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);
|
||||||
@ -419,28 +447,10 @@ INLINE uint8_t ioRead( uint16_t addr ) {
|
|||||||
Apple2_64K_RAM[io_KBD] &= 0x7F;
|
Apple2_64K_RAM[io_KBD] &= 0x7F;
|
||||||
return Apple2_64K_RAM[io_KBDSTRB];
|
return Apple2_64K_RAM[io_KBDSTRB];
|
||||||
|
|
||||||
case (uint8_t)io_SPKR: {
|
case (uint8_t)io_SPKR:
|
||||||
// TODO: This is very slow!
|
spkr_switch();
|
||||||
// printf("io_KBDSTRB\n");
|
|
||||||
|
|
||||||
// push a click into the speaker buffer
|
|
||||||
// (we will play the entire buffer at the end of the frame)
|
|
||||||
int sample_idx = clkfrm / 22;
|
|
||||||
spkr_samples[sample_idx] = 0;
|
|
||||||
|
|
||||||
//ViewController_spk_up_play();
|
|
||||||
|
|
||||||
return Apple2_64K_RAM[io_SPKR];
|
return Apple2_64K_RAM[io_SPKR];
|
||||||
|
|
||||||
// case io_VID_CLR80VID:
|
|
||||||
// videoMode.col80 = 0;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
// case io_VID_SET80VID:
|
|
||||||
// videoMode.col80 = 1;
|
|
||||||
// break;
|
|
||||||
//
|
|
||||||
}
|
|
||||||
case (uint8_t)io_VID_RDTEXT:
|
case (uint8_t)io_VID_RDTEXT:
|
||||||
return videoMode.text << 7;
|
return videoMode.text << 7;
|
||||||
|
|
||||||
@ -699,6 +709,10 @@ INLINE void ioWrite( uint16_t addr, uint8_t val ) {
|
|||||||
Apple2_64K_RAM[io_KBD] &= 0x7F;
|
Apple2_64K_RAM[io_KBD] &= 0x7F;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case io_SPKR:
|
||||||
|
spkr_switch();
|
||||||
|
break;
|
||||||
|
|
||||||
case io_RDMAINRAM:
|
case io_RDMAINRAM:
|
||||||
// printf("io_RDMAINRAM\n");
|
// printf("io_RDMAINRAM\n");
|
||||||
MEMcfg.RD_AUX_MEM = 0;
|
MEMcfg.RD_AUX_MEM = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user