mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Incremental work.
This commit is contained in:
parent
35428add63
commit
fd69636743
@ -40,6 +40,7 @@ static const int BUFFER_SAMPLE_COUNT = 2048;
|
||||
static const int CHANNELS = 2;
|
||||
static const int SAMPLE_RATE = 44100;
|
||||
static const int SAMPLES_PER_MS = SAMPLE_RATE / 1000;
|
||||
static const int FADE_LENGTH_MS = 2000;
|
||||
static const float F_SHRT_MAX = (float) SHRT_MAX;
|
||||
|
||||
GmeDecoder::GmeDecoder() {
|
||||
@ -73,6 +74,9 @@ bool GmeDecoder::Open(musik::core::sdk::IDataStream *stream) {
|
||||
this->gme = nullptr;
|
||||
this->info = nullptr;
|
||||
}
|
||||
else {
|
||||
gme_set_fade(this->gme, this->info->play_length - FADE_LENGTH_MS, FADE_LENGTH_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] data;
|
||||
@ -97,15 +101,14 @@ double GmeDecoder::GetDuration() {
|
||||
|
||||
bool GmeDecoder::GetBuffer(IBuffer *target) {
|
||||
if (this->gme) {
|
||||
int remainMs = this->info->play_length - gme_tell(this->gme);
|
||||
int remainSamples = SAMPLES_PER_MS * remainMs;
|
||||
int samplesToDecode = BUFFER_SAMPLE_COUNT < remainSamples ? BUFFER_SAMPLE_COUNT : remainSamples;
|
||||
if (!gme_play(this->gme, samplesToDecode, this->buffer)) {
|
||||
if (!gme_track_ended(this->gme) &&
|
||||
!gme_play(this->gme, BUFFER_SAMPLE_COUNT, this->buffer))
|
||||
{
|
||||
target->SetChannels(CHANNELS);
|
||||
target->SetSampleRate(SAMPLE_RATE);
|
||||
target->SetSamples(samplesToDecode);
|
||||
target->SetSamples(BUFFER_SAMPLE_COUNT);
|
||||
float* dst = target->BufferPointer();
|
||||
for (size_t i = 0; i < samplesToDecode; i++) {
|
||||
for (size_t i = 0; i < BUFFER_SAMPLE_COUNT; i++) {
|
||||
dst[i] = (float) this->buffer[i] / F_SHRT_MAX;
|
||||
}
|
||||
return true;
|
||||
|
@ -76,13 +76,13 @@ static void updateMetadata(
|
||||
std::cerr << "error opening file: " << err << "\n";
|
||||
}
|
||||
else {
|
||||
std::string m3u = getM3uFor(fn);
|
||||
if (m3u.size()) {
|
||||
err = gme_load_m3u(data, m3u.c_str());
|
||||
if (err) {
|
||||
std::cerr << "m3u found, but load failed: " << err << "\n";
|
||||
}
|
||||
}
|
||||
// std::string m3u = getM3uFor(fn);
|
||||
// if (m3u.size()) {
|
||||
// err = gme_load_m3u(data, m3u.c_str());
|
||||
// if (err) {
|
||||
// std::cerr << "m3u found, but load failed: " << err << "\n";
|
||||
// }
|
||||
// }
|
||||
|
||||
for (int i = 0; i < gme_track_count(data); i++) {
|
||||
gme_info_t* info = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user