Updating a few more things to state events, will probably stop here for now and revist the trailing things later.

This commit is contained in:
2023-03-01 14:16:50 -08:00
parent 3cd6d555d1
commit 91163cfcad
15 changed files with 397 additions and 405 deletions

View File

@ -1,77 +1,76 @@
// 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;
// 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;
}
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;
}