Commit 9b967029 authored by Jack's avatar Jack
Browse files

fixed note pitch issues, now it's rendering properly

parent f6d4f293
......@@ -166,13 +166,13 @@ else
dest = { 0, 0, 320, 240 };
#endif
SDL_RenderCopy(renderer, _outputTexture, nullptr, &dest);
text(_path.c_str(), 10, 10);
char buffer[16];
sprintf(buffer, "%.0f/%c0", 1000.0f / manager->lastFrameTicks(), machine.code().require60fps() ? '6' : '3');
text(buffer, 10, 22);
SDL_RenderCopy(renderer, _outputTexture, nullptr, &dest);
#if DEBUGGER
{
/* sprite sheet */
......
......@@ -159,8 +159,6 @@ DSP dsp(44100);
constexpr float PULSE_WAVE_DEFAULT_DUTY = 1 / 3.0f;
constexpr float ORGAN_DEFAULT_COEFFICIENT = 0.5f;
size_t position = 0;
int16_t* rendered = nullptr;
void audio_callback(void* data, uint8_t* cbuffer, int length)
{
......@@ -168,32 +166,6 @@ void audio_callback(void* data, uint8_t* cbuffer, int length)
int16_t* buffer = reinterpret_cast<int16_t*>(cbuffer);
apu->renderSounds(buffer, length / sizeof(int16_t));
return;
if (!rendered)
{
rendered = new int16_t[44100 * 3];
dsp.squareWave(440, 4096, 0, 0, rendered, 44100 * 3);
dsp.fadeIn(4096, rendered, 44100);
dsp.fadeOut(4096, rendered + 88200, 44100);
}
//
//int16_t* buffer = reinterpret_cast<int16_t*>(cbuffer);
if (position < 44100 * 3)
{
size_t max = std::min((44100 * 3 - position) * 2, size_t(length));
memcpy(cbuffer, rendered + position, max);
position += max / sizeof(int16_t);
}
else
memset(cbuffer, 0, length);
//dsp.triangleWave(NoteTable[A]*2, 4096, 0, pos, buffer, length / sizeof(int16_t));
//dsp.noise(NoteTable[A] * 2, 4096, pos, buffer, length / sizeof(int16_t));
//pos += length / sizeof(int16_t);
return;
}
void APU::init()
......@@ -472,6 +444,8 @@ void APU::renderSounds(int16_t* dest, size_t totalSamples)
samples -= available;
buffer += available;
channel.position += available;
auto oldSampel = channel.sample;
channel.sample = channel.position / samplePerTick;
updateChannel(channel, music);
......
......@@ -38,13 +38,14 @@ namespace retro8
{
private:
constexpr static std::array<float, 12> frequencies = {
//16.35, 17.32f, 18.35f, 19.45f, 20.60f, 21.83f, 23.12f, 24.50f, 25.96f, 27.50f, 29.14f, 30.87f
130.81f, 138.59f, 146.83f, 155.56f, 164.81f, 174.61f, 185.00f, 196.00, 207.65, 220.0, 233.08, 246.94
};
public:
static pitch_t pitch(Tone tone, int32_t octave = 1) { return pitch_t(tone) + octave * 12; }
static frequency_t frequency(Tone tone, int32_t octave = 1) { return frequencies[size_t(tone)] * octave; };
static frequency_t frequency(pitch_t pitch) { return frequencies[pitch % 12] * (1 + pitch / 12); }
static frequency_t frequency(pitch_t pitch) { return frequencies[pitch % 12] / 2 * (1 << (pitch / 12)); }
};
struct SoundSample
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment