Adjusted Audio Play

This commit is contained in:
tudnai 2020-05-17 22:08:23 -07:00
parent bde4c4d941
commit 9871cb3886
4 changed files with 29 additions and 19 deletions

View File

@ -41,11 +41,6 @@
</ContextState>
<ContextState
contextName = "spkr_playUpd:speaker.c">
<PersistentStrings>
<PersistentString
value = "freeBuffers">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "m6502_ColdReset:6502.c">
@ -147,6 +142,17 @@
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "spkr_toggle:speaker.c">
<PersistentStrings>
<PersistentString
value = "(clkfrm / (default_MHz_6502 / spkr_sample_rate))">
</PersistentString>
<PersistentString
value = "spkr_sample_idx">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "memread8:Apple2_mmio.h">
</ContextState>

View File

@ -921,7 +921,7 @@
<textField verticalHuggingPriority="750" fixedFrame="YES" id="SNE-lV-JXn" userLabel="SoundGap">
<rect key="frame" x="0.0" y="0.0" width="90" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" title="13" drawsBackground="YES" id="ZKd-sJ-O4U">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" title="26" drawsBackground="YES" id="ZKd-sJ-O4U">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -930,7 +930,7 @@
<stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" id="uQO-BN-oqa">
<rect key="frame" x="88" y="-2" width="19" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<stepperCell key="cell" continuous="YES" alignment="left" maxValue="256" doubleValue="13" id="h0r-W8-egl"/>
<stepperCell key="cell" continuous="YES" alignment="left" maxValue="256" doubleValue="26" id="h0r-W8-egl"/>
<connections>
<action selector="SoundGapChanged:" target="XfG-lQ-9wD" id="Y1Z-lh-l8u"/>
</connections>

View File

@ -68,12 +68,12 @@ 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_extra_buf = 26; // 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 * 2 / spkr_fps;
char spkr_samples [ spkr_buf_size * spkr_fps * BUFFER_COUNT * 2]; // stereo
unsigned spkr_sample_idx = 0;
const unsigned spkr_play_timeout = 10;
const unsigned spkr_play_timeout = 8;
unsigned spkr_play_time = 0;
@ -144,18 +144,20 @@ void spkr_toggle() {
// 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);
spkr_sample_idx = (clkfrm / (default_MHz_6502 / spkr_sample_rate)) * 2;
if ( spkr_level > SPKR_LEVEL_MIN ) {
// down edge
while( (spkr_level -= (spkr_level - SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
while( (spkr_level = (spkr_level + SPKR_LEVEL_MIN) / 2 ) > SPKR_LEVEL_MIN + 1 ) {
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
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 ) {
while( (spkr_level = (spkr_level + SPKR_LEVEL_MAX) / 2 ) < SPKR_LEVEL_MAX - 1 ) {
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
}
spkr_level = SPKR_LEVEL_MAX;
@ -247,15 +249,17 @@ void spkr_update() {
for ( spkr_sample_idx = 0; spkr_level != SPKR_LEVEL_ZERO; spkr_level += step) {
for ( int i = 0; i < 4; i++ ) {
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
}
}
spkr_level = SPKR_LEVEL_ZERO;
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
spkr_samples[ spkr_sample_idx++ ] = spkr_level;
//spkr_samples[sample_idx] = spkr_level;
memset(spkr_samples + spkr_sample_idx, spkr_level, spkr_extra_buf);
freeBuffers--;
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_MONO8, spkr_samples, spkr_sample_idx, spkr_sample_rate);
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO8, spkr_samples, spkr_sample_idx, spkr_sample_rate);
al_check_error();
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
al_check_error();
@ -263,7 +267,7 @@ void spkr_update() {
}
else {
freeBuffers--;
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_MONO8, spkr_samples, spkr_buf_size + spkr_extra_buf, spkr_sample_rate);
alBufferData(spkr_buffers[freeBuffers], AL_FORMAT_STEREO8, spkr_samples, spkr_buf_size + spkr_extra_buf, spkr_sample_rate);
al_check_error();
alSourceQueueBuffers(spkr_src, 1, &spkr_buffers[freeBuffers]);
al_check_error();

View File

@ -11,9 +11,9 @@
#include <stdio.h>
#define SPKR_LEVEL_MIN 0
#define SPKR_LEVEL_MAX 255
#define SPKR_LEVEL_ZERO ( SPKR_LEVEL_MIN + SPKR_LEVEL_MAX / 2 )
#define SPKR_LEVEL_MIN 32
#define SPKR_LEVEL_MAX 223
#define SPKR_LEVEL_ZERO 128 // as defined in OpenAL documentation for 8bit PCM
extern const unsigned spkr_sample_rate;