1
0
Fork 0

Add a signed integer ceiling divide function

This commit is contained in:
krcroft 2020-03-05 16:51:53 -08:00 committed by Patryk Obara
parent be643d66b1
commit 08c6fc10c1
5 changed files with 31 additions and 18 deletions

View file

@ -131,7 +131,7 @@ static int32_t MP3_open(Sound_Sample* const sample, const char* const ext)
// total_time needs milliseconds
internal->total_time = (num_frames != 0) ?
static_cast<int32_t>(ceil_divide(num_frames * 1000u, sample->actual.rate))
static_cast<int32_t>(ceil_udivide(num_frames * 1000u, sample->actual.rate))
: -1;
}
}
@ -161,7 +161,7 @@ static Sint32 MP3_seek(Sound_Sample* const sample, const Uint32 ms)
Sound_SampleInternal* const internal = static_cast<Sound_SampleInternal*>(sample->opaque);
mp3_t* p_mp3 = static_cast<mp3_t*>(internal->decoder_private);
const uint64_t sample_rate = sample->actual.rate;
const drmp3_uint64 pcm_frame = ceil_divide(sample_rate * ms, 1000u);
const drmp3_uint64 pcm_frame = ceil_udivide(sample_rate * ms, 1000u);
const drmp3_bool32 result = drmp3_seek_to_pcm_frame(p_mp3->p_dr, pcm_frame);
return (result == DRMP3_TRUE);
} /* MP3_seek */

View file

@ -204,7 +204,7 @@ Uint64 generate_new_seek_points(const char* filename,
// We also take into account the desired number of "FRAMES_PER_SEEK_POINT",
// which is defined above.
drmp3_uint32 num_seek_points = static_cast<drmp3_uint32>
(ceil_divide(mp3_frame_count, FRAMES_PER_SEEK_POINT));
(ceil_udivide(mp3_frame_count, FRAMES_PER_SEEK_POINT));
seek_points_vector.resize(num_seek_points);
result = drmp3_calculate_seek_points(p_dr,

View file

@ -257,14 +257,20 @@ static int32_t opus_open(Sound_Sample * sample, const char * ext)
const OpusHead* oh = op_head(of, -1);
output_opus_info(of, oh);
// Populate track properties
sample->actual.rate = OPUS_SAMPLE_RATE;
sample->actual.channels = static_cast<Uint8>(oh->channel_count);
sample->flags = op_seekable(of) ? SOUND_SAMPLEFLAG_CANSEEK: 0;
sample->actual.format = AUDIO_S16SYS;
int64_t pcm_result = op_pcm_total(of, -1); // If positive, holds total PCM samples
internal->total_time = pcm_result == OP_EINVAL ? -1 : // total milliseconds in the stream
static_cast<int32_t>
(ceil_divide(static_cast<uint64_t>(pcm_result), OPUS_SAMPLE_RATE_PER_MS));
// Populate the track's duration in milliseconds (or -1 if bad)
const auto pcm_result = static_cast<int32_t>(op_pcm_total(of, -1));
if (pcm_result == OP_EINVAL)
internal->total_time = -1;
else {
constexpr auto frames_per_ms = static_cast<int32_t>(OPUS_SAMPLE_RATE_PER_MS);
internal->total_time = ceil_sdivide(pcm_result, frames_per_ms);
}
return rcode;
} /* opus_open */
@ -310,7 +316,7 @@ static uint32_t opus_read(Sound_Sample * sample, void * buffer, uint32_t request
}
// Finally, we return the number of frames decoded
const uint32_t decoded_frames = ceil_divide(total_decoded_samples, channels);
const uint32_t decoded_frames = ceil_udivide(total_decoded_samples, channels);
return decoded_frames;
} /* opus_read */