mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Made final switch to permit high-sampling rate Atari audio.
This commit is contained in:
parent
f95015c7f6
commit
ed6b135015
@ -44,6 +44,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
target[c] = 0;
|
target[c] = 0;
|
||||||
for(int channel = 0; channel < 2; channel++) {
|
for(int channel = 0; channel < 2; channel++) {
|
||||||
divider_counter_[channel] ++;
|
divider_counter_[channel] ++;
|
||||||
|
int divider_value = divider_counter_[channel] / (38 / CPUTicksPerAudioTick);
|
||||||
int level = 0;
|
int level = 0;
|
||||||
switch(control_[channel]) {
|
switch(control_[channel]) {
|
||||||
case 0x0: case 0xb: // constant 1
|
case 0x0: case 0xb: // constant 1
|
||||||
@ -51,24 +52,24 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x4: case 0x5: // div2 tone
|
case 0x4: case 0x5: // div2 tone
|
||||||
level = (divider_counter_[channel] / (divider_[channel]+1))&1;
|
level = (divider_value / (divider_[channel]+1))&1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xc: case 0xd: // div6 tone
|
case 0xc: case 0xd: // div6 tone
|
||||||
level = (divider_counter_[channel] / ((divider_[channel]+1)*3))&1;
|
level = (divider_value / ((divider_[channel]+1)*3))&1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x6: case 0xa: // div31 tone
|
case 0x6: case 0xa: // div31 tone
|
||||||
level = (divider_counter_[channel] / (divider_[channel]+1))%30 <= 18;
|
level = (divider_value / (divider_[channel]+1))%30 <= 18;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xe: // div93 tone
|
case 0xe: // div93 tone
|
||||||
level = (divider_counter_[channel] / ((divider_[channel]+1)*3))%30 <= 18;
|
level = (divider_value / ((divider_[channel]+1)*3))%30 <= 18;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1: // 4-bit poly
|
case 0x1: // 4-bit poly
|
||||||
level = poly4_counter_[channel]&1;
|
level = poly4_counter_[channel]&1;
|
||||||
if(divider_counter_[channel] == divider_[channel]+1) {
|
if(divider_value == divider_[channel]+1) {
|
||||||
divider_counter_[channel] = 0;
|
divider_counter_[channel] = 0;
|
||||||
advance_poly4(channel);
|
advance_poly4(channel);
|
||||||
}
|
}
|
||||||
@ -76,14 +77,14 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
|
|
||||||
case 0x2: // 4-bit poly div31
|
case 0x2: // 4-bit poly div31
|
||||||
level = poly4_counter_[channel]&1;
|
level = poly4_counter_[channel]&1;
|
||||||
if(divider_counter_[channel]%(30*(divider_[channel]+1)) == 18) {
|
if(divider_value%(30*(divider_[channel]+1)) == 18) {
|
||||||
advance_poly4(channel);
|
advance_poly4(channel);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x3: // 5/4-bit poly
|
case 0x3: // 5/4-bit poly
|
||||||
level = output_state_[channel];
|
level = output_state_[channel];
|
||||||
if(divider_counter_[channel] == divider_[channel]+1) {
|
if(divider_value == divider_[channel]+1) {
|
||||||
if(poly5_counter_[channel]&1) {
|
if(poly5_counter_[channel]&1) {
|
||||||
output_state_[channel] = poly4_counter_[channel]&1;
|
output_state_[channel] = poly4_counter_[channel]&1;
|
||||||
advance_poly4(channel);
|
advance_poly4(channel);
|
||||||
@ -94,7 +95,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
|
|
||||||
case 0x7: case 0x9: // 5-bit poly
|
case 0x7: case 0x9: // 5-bit poly
|
||||||
level = poly5_counter_[channel]&1;
|
level = poly5_counter_[channel]&1;
|
||||||
if(divider_counter_[channel] == divider_[channel]+1) {
|
if(divider_value == divider_[channel]+1) {
|
||||||
divider_counter_[channel] = 0;
|
divider_counter_[channel] = 0;
|
||||||
advance_poly5(channel);
|
advance_poly5(channel);
|
||||||
}
|
}
|
||||||
@ -102,7 +103,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
|
|
||||||
case 0xf: // 5-bit poly div6
|
case 0xf: // 5-bit poly div6
|
||||||
level = poly5_counter_[channel]&1;
|
level = poly5_counter_[channel]&1;
|
||||||
if(divider_counter_[channel] == (divider_[channel]+1)*3) {
|
if(divider_value == (divider_[channel]+1)*3) {
|
||||||
divider_counter_[channel] = 0;
|
divider_counter_[channel] = 0;
|
||||||
advance_poly5(channel);
|
advance_poly5(channel);
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *ta
|
|||||||
|
|
||||||
case 0x8: // 9-bit poly
|
case 0x8: // 9-bit poly
|
||||||
level = poly9_counter_[channel]&1;
|
level = poly9_counter_[channel]&1;
|
||||||
if(divider_counter_[channel] == divider_[channel]+1) {
|
if(divider_value == divider_[channel]+1) {
|
||||||
divider_counter_[channel] = 0;
|
divider_counter_[channel] = 0;
|
||||||
advance_poly9(channel);
|
advance_poly9(channel);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,9 @@
|
|||||||
|
|
||||||
namespace Atari2600 {
|
namespace Atari2600 {
|
||||||
|
|
||||||
const int CPUTicksPerAudioTick = 38;
|
// This should be a divisor of 38; audio counters are updated every 38 cycles — though lesser dividers
|
||||||
|
// will give greater resolution to changes in audio state. 1, 2 and 19 are the only divisors of 38.
|
||||||
|
const int CPUTicksPerAudioTick = 2;
|
||||||
|
|
||||||
class Speaker: public ::Outputs::Filter<Speaker> {
|
class Speaker: public ::Outputs::Filter<Speaker> {
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user