Perfected Audio

This commit is contained in:
2023-01-17 19:34:47 -08:00
parent a4ad5a3ac4
commit 821074dfc4
18 changed files with 459 additions and 308 deletions

View File

@ -7,6 +7,7 @@
#include "Asset.hpp"
#include "util/array.hpp"
#include "assets/AudioAsset.hpp"
#include "assets/LanguageAsset.hpp"
#include "assets/TextureAsset.hpp"
#include "assets/TilesetAsset.hpp"

View File

@ -0,0 +1,77 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "AudioAsset.hpp"
using namespace Dawn;
AudioAsset::AudioAsset(AssetManager *man, std::string name) :
Asset(man, name),
loader(name + ".audio")
{
}
void AudioAsset::updateSync() {
if(this->state != 0x07) return;
// THIS WILL DEFINITELY CHANGE
this->state = 0x08;
this->loaded = true;
this->eventLoaded.invoke();
}
void AudioAsset::updateAsync() {
if(this->state != 0x00) return;
char *start, *end;
char buffer[1024];
// Open asset for reading
this->state = 0x01;
this->loader.open();
// Parse header data.
this->state = 0x02;
this->loader.read((uint8_t *)buffer, 1024);
// Channel count
this->state = 0x03;
start = buffer;
end = strchr(start, '|');
*end = '\0';
this->channelCount = atoi(start);
assertTrue(this->channelCount > 0);
// Sample Rate
this->state = 0x04;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
assertTrue(this->sampleRate > 0);
// Number of samples per channel
this->state = 0x05;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->samplesPerChannel = atoi(start);
assertTrue(this->samplesPerChannel > 0);
// Total Data Length
this->state = 0x06;
start = end + 1;
end = strchr(start, '|');
*end = '\0';
this->bufferSize = (size_t)atoll(start);
assertTrue(this->bufferSize > 0);
// Determine frame size
this->frameSize = sizeof(int16_t) * this->channelCount;
// Indicated start of data
this->state = 0x07;
this->bufferStart = end - buffer;
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../Asset.hpp"
#include "../AssetLoader.hpp"
namespace Dawn {
class AudioSource;
class AudioAsset : public Asset {
protected:
AssetLoader loader;
uint8_t state = 0x00;
int32_t channelCount;
uint32_t sampleRate;
int32_t samplesPerChannel;
size_t bufferSize;
size_t bufferStart;
size_t frameSize;
public:
AudioAsset(AssetManager *man, std::string name);
void updateSync() override;
void updateAsync() override;
friend class AudioSource;
};
}

View File

@ -6,6 +6,7 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
AudioAsset.cpp
LanguageAsset.cpp
TextureAsset.cpp
TilesetAsset.cpp

View File

@ -15,7 +15,7 @@ namespace Dawn {
void onSceneUnpausedUpdate();
public:
bool_t onlyUpdateUnpaused = true;
bool_t onlyUpdateUnpaused = false;
SubSceneController(SceneItem *item);