Exponential signal edges for speaker

This commit is contained in:
tudnai 2020-05-13 20:40:54 -07:00
parent 260c09d8b8
commit 015a32c444
5 changed files with 44 additions and 8 deletions

View File

@ -675,6 +675,18 @@
<action selector="Disk1_Selected:" target="Voe-Tx-rLC" id="zhC-rp-mN0"/>
</connections>
</menuItem>
<menuItem title="Wavy Navy" identifier="Wavy Navy" id="GB7-kl-zHb">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="Disk1_Selected:" target="Voe-Tx-rLC" id="lcd-GR-OVR"/>
</connections>
</menuItem>
<menuItem title="Xonix" identifier="Xonix" id="242-uR-ubX">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="Disk1_Selected:" target="Voe-Tx-rLC" id="Ysg-X9-qeK"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>

View File

@ -772,10 +772,9 @@ void m6502_Run() {
clk_6502_per_frm = clk_6502_per_frm_set;
}
}
// play the entire sound buffer for this frame
spkr_play();
}
@ -851,6 +850,7 @@ void m6502_ColdReset( const char * bundlePath, const char * romFileName ) {
mhz = (double)MHz_6502 / M;
spkr_init();
// spkr_play();
unsigned long long saved_frm_set = clk_6502_per_frm_set;
clk_6502_per_frm =

View File

@ -119,6 +119,8 @@ void spkr_play() {
alSourcei(spkr_src, AL_BUFFER, spkr_buf);
alSourcei(spkr_src, AL_LOOPING, 0);
alSourcei( spkr_src, AL_BYTE_OFFSET, 0 );
al_check_error();
alSourcePlay(spkr_src);
ALint secoffset = 0;
@ -136,3 +138,23 @@ void spkr_play() {
alSourceStop(spkr_src);
}
}
void spkr_Update() {
if ( spkr_src && spkr_buf ) {
if ( spkr_src ) {
alSourcePause(spkr_src);
al_check_error();
alSourcei(spkr_src, AL_BUFFER, 0);
al_check_error();
}
// Download buffer to OpenAL
alBufferData(spkr_buf, AL_FORMAT_MONO8, spkr_samples, spkr_buf_size / spkr_fps, spkr_sample_rate);
al_check_error();
alSourcei( spkr_src, AL_BYTE_OFFSET, 0 );
al_check_error();
alSourcePlay(spkr_src);
}
}

View File

@ -11,13 +11,15 @@
#include <stdio.h>
#define SPKR_LEVEL_MIN 0
#define SPKR_LEVEL_MAX 255
#define SPKR_LEVEL_MIN 25
#define SPKR_LEVEL_MAX 200
extern void spkr_init(void);
extern void spkr_exit(void);
extern void spkr_play(void);
extern void spkr_Update(void);
extern const unsigned spkr_sample_rate;
extern const unsigned spkr_buf_size;
extern char spkr_samples [];
extern unsigned spkr_sample_idx;

View File

@ -406,18 +406,18 @@ INLINE void spkr_switch() {
// push a click into the speaker buffer
// (we will play the entire buffer at the end of the frame)
spkr_sample_idx = clkfrm / 22;
spkr_sample_idx = clkfrm / (default_MHz_6502 / spkr_sample_rate);
if ( spkr_level > SPKR_LEVEL_MIN ) {
// down edge
while( (spkr_level -= 16) > SPKR_LEVEL_MIN ) {
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 += 16) < SPKR_LEVEL_MAX ) {
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;