Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions Source/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Audio/Audio.h"

#include "Application.h"
#include "Audio/Spu.h"
#include "Utils/Video.h"

using namespace Silent::Utils;
Expand All @@ -11,16 +12,16 @@ namespace Silent::Audio
constexpr int SAMPLE_RATE = 44100;
constexpr int BUFFER_SAMPLES = 4096;

struct Voice
struct VoiceTest
{
float phase;
float frequency;
float volumeLeft;
float volumeRight;
bool active;
float phase = 0.0f;
float frequency = 0.0f;
float volumeLeft = 0.0f;
float volumeRight = 0.0f;
bool active = false;
};

static Voice voice;
static VoiceTest voice;

void GenerateSamples(int16* buffer, int sampleCount)
{
Expand Down Expand Up @@ -76,12 +77,19 @@ namespace Silent::Audio
auto destSpec = SDL_AudioSpec{};
SDL_GetAudioDeviceFormat(_device, &destSpec, nullptr);

auto srcSpec = SDL_AudioSpec{ SDL_AUDIO_F32, 2, SAMPLE_RATE };
_stream = SDL_CreateAudioStream(&destSpec, &destSpec);
auto srcSpec = SDL_AudioSpec
{
.format = SDL_AUDIO_F32,
.channels = 2,
.freq = SAMPLE_RATE
};
_stream = SDL_CreateAudioStream(&destSpec, &destSpec);

SDL_BindAudioStream(_device, _stream);
SDL_ResumeAudioDevice(_device);

_spu.Initialize();

// Init fake voice.
voice.phase = 0.0f;
voice.frequency = 440.0f; // A4
Expand Down
3 changes: 3 additions & 0 deletions Source/Audio/Audio.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "Audio/Spu.h"

namespace Silent::Audio
{
/** @brief Audio manager. */
Expand All @@ -12,6 +14,7 @@ namespace Silent::Audio

SDL_AudioDeviceID _device = 0;
SDL_AudioStream* _stream = nullptr;
VirtualSpu _spu = VirtualSpu();

public:
// =============
Expand Down
Loading