-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to SFML, started implementing audio
- Loading branch information
1 parent
746b7a5
commit add4fb6
Showing
9 changed files
with
318 additions
and
4,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "APU.h" | ||
#include "Memory.h" | ||
|
||
void APU::execute_one_cycle() | ||
{ | ||
static float phase = 0; | ||
static constexpr int w = 5000; | ||
clock_cycles++; | ||
if (clock_cycles % 23 == 0) // 1048576 / 44100 = 23 | ||
{ | ||
// generate 1 sound sample | ||
sound_buffer[(cur_pos + 1) % sound_buffer.size()] = 0; // 2000 * sin(phase); | ||
phase += w * 1.0 / BIT_RATE; | ||
if (phase > 2 * 3.1415) | ||
phase -= 2 * 3.1415; | ||
cur_pos = (cur_pos + 1) % sound_buffer.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <atomic> | ||
|
||
class Memory; | ||
|
||
class APU | ||
{ | ||
public: | ||
static constexpr size_t BIT_RATE = 44100; | ||
static constexpr size_t BUFFER_SIZE = 3 * BIT_RATE; | ||
private: | ||
Memory* mem; | ||
|
||
uint64_t clock_cycles = 0; | ||
|
||
std::array<int16_t, BUFFER_SIZE> sound_buffer; | ||
std::atomic_size_t cur_pos = 0; | ||
// change constant 23 in execute_one_cycle if you want to change bit rate | ||
public: | ||
APU(Memory* mem) : mem(mem) {}; | ||
void execute_one_cycle(); | ||
|
||
const std::array<int16_t, BUFFER_SIZE>& get_sound_buffer(); | ||
size_t get_cur_pos(); | ||
}; | ||
|
||
inline const std::array<int16_t, APU::BUFFER_SIZE>& APU::get_sound_buffer() | ||
{ | ||
return sound_buffer; | ||
} | ||
|
||
inline size_t APU::get_cur_pos() | ||
{ | ||
return cur_pos; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.