fixed audio buffer size overflow on long clips

This commit is contained in:
itsmattkc
2019-01-21 10:02:37 +11:00
parent 2746e727f6
commit ae4fdf4846
3 changed files with 9 additions and 7 deletions
+4 -4
View File
@@ -33,7 +33,7 @@ bool audio_rendering = false;
bool recording = false;
qint8 audio_ibuffer[audio_ibuffer_size];
int audio_ibuffer_read = 0;
unsigned long audio_ibuffer_read = 0;
long audio_ibuffer_frame = 0;
double audio_ibuffer_timecode = 0;
@@ -114,9 +114,9 @@ int current_audio_freq() {
return audio_rendering ? sequence->audio_frequency : audio_output->format().sampleRate();
}
int get_buffer_offset_from_frame(double framerate, long frame) {
unsigned long get_buffer_offset_from_frame(double framerate, long frame) {
if (frame >= audio_ibuffer_frame) {
return qFloor(((double) (frame - audio_ibuffer_frame)/framerate)*current_audio_freq())*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO);
return static_cast<unsigned long>(((double(frame - audio_ibuffer_frame)/framerate)*current_audio_freq())*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO));
} else {
qWarning() << "Invalid values passed to get_buffer_offset_from_frame";
return 0;
@@ -168,7 +168,7 @@ int AudioSenderThread::send_audio_to_output(int offset, int max) {
// send audio to device
int actual_write = audio_io_device->write((const char*) audio_ibuffer+offset, max);
int audio_ibuffer_limit = audio_ibuffer_read + actual_write;
unsigned long audio_ibuffer_limit = audio_ibuffer_read + actual_write;
// send samples to audio monitor cache
// TODO make this work for the footage viewer - currently, enabling it causes crash due to an ASSERT
+2 -2
View File
@@ -37,7 +37,7 @@ extern QMutex audio_write_lock;
#define audio_ibuffer_size 192000
extern qint8 audio_ibuffer[audio_ibuffer_size];
extern int audio_ibuffer_read;
extern unsigned long audio_ibuffer_read;
extern long audio_ibuffer_frame;
extern double audio_ibuffer_timecode;
extern bool audio_scrub;
@@ -51,7 +51,7 @@ bool is_audio_device_set();
void init_audio();
void stop_audio();
int get_buffer_offset_from_frame(double framerate, long frame);
unsigned long get_buffer_offset_from_frame(double framerate, long frame);
bool start_recording();
void stop_recording();
+3 -1
View File
@@ -364,7 +364,9 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector<Clip*>& nests) {
if (frame->nb_samples == 0) {
break;
} else {
long buffer_timeline_out = get_buffer_offset_from_frame(c->sequence->frame_rate, timeline_out);
unsigned long buffer_timeline_out = get_buffer_offset_from_frame(c->sequence->frame_rate, timeline_out);
qDebug() << "bto:" << buffer_timeline_out;
audio_write_lock.lock();
while (c->frame_sample_index < nb_bytes