Added a sinewave audio test source

- Added a test audio sinewave test source that should just play a sine
   wave of the middle C note.  Using unsigned 8 bit mono to test
   ffmpeg's audio resampler, seems to work pretty good.

 - Fixed a boolean trap in threading.h for the event_init function, it
   now uses enum event_type, which can be EVENT_TYPE_MANUAL or
   EVENT_TYPE_AUTO, to specify whether the event is automatically reset
   or not.

 - Changed display names of test sources to something a little less
   vague.

 - Removed te whole "if timestamp is 0 just use current system time"
   when outputting source audio, if you want to use system time you
   should just use system time yourself.  Using 0 as some sort of
   "indicator" like that just makes things confusing, and prevents you
   from legitimately using 0 as a timestamp for your audio data.
This commit is contained in:
jp9000
2014-01-09 22:04:25 -07:00
parent e891b3fae8
commit f827ba38ef
12 changed files with 146 additions and 24 deletions

View File

@@ -38,8 +38,8 @@ struct audio_line {
* buffer is depleted, it's destroyed */
bool alive;
struct audio_line **prev_next;
struct audio_line *next;
struct audio_line **prev_next;
struct audio_line *next;
};
static inline void audio_line_destroy_data(struct audio_line *line)
@@ -130,7 +130,7 @@ static void mix_audio_lines(struct audio_output *audio, uint64_t audio_time,
while (line) {
struct audio_line *next = line->next;
if (line->base_timestamp < prev_time) {
if (line->buffer.size && line->base_timestamp < prev_time) {
clear_excess_audio_data(line,
line->base_timestamp - prev_time);
line->base_timestamp = prev_time;
@@ -222,7 +222,7 @@ int audio_output_open(audio_t *audio, media_t media, struct audio_info *info)
goto fail;
if (pthread_mutex_init(&out->line_mutex, &attr) != 0)
goto fail;
if (event_init(&out->stop_event, true) != 0)
if (event_init(&out->stop_event, EVENT_TYPE_MANUAL) != 0)
goto fail;
if (!ao_add_to_media(out))
goto fail;
@@ -243,6 +243,7 @@ audio_line_t audio_output_createline(audio_t audio, const char *name)
struct audio_line *line = bmalloc(sizeof(struct audio_line));
memset(line, 0, sizeof(struct audio_line));
line->alive = true;
line->audio = audio;
if (pthread_mutex_init(&line->mutex, NULL) != 0) {
blog(LOG_ERROR, "audio_output_createline: Failed to create "
@@ -393,8 +394,8 @@ static inline void mul_vol_float(struct audio_line *line, float volume,
static void audio_line_place_data(struct audio_line *line,
const struct audio_data *data, size_t position)
{
size_t total_size = data->frames * line->audio->block_size;
size_t total_num = data->frames * line->audio->channels;
size_t total_size = data->frames * line->audio->block_size;
da_copy_array(line->volume_buffer, data->data, total_size);

View File

@@ -115,9 +115,9 @@ int video_output_open(video_t *video, media_t media, struct video_info *info)
if (pthread_mutex_init(&out->data_mutex, NULL) != 0)
goto fail;
if (event_init(&out->stop_event, true) != 0)
if (event_init(&out->stop_event, EVENT_TYPE_MANUAL) != 0)
goto fail;
if (event_init(&out->update_event, false) != 0)
if (event_init(&out->update_event, EVENT_TYPE_AUTO) != 0)
goto fail;
if (!vo_add_to_media(out))
goto fail;

View File

@@ -332,14 +332,6 @@ static void source_output_audio_line(obs_source_t source,
{
struct audio_data in = *data;
if (!in.timestamp) {
in.timestamp = os_gettime_ns();
if (!source->timing_set) {
source->timing_set = true;
source->timing_adjust = 0;
}
}
if (!source->timing_set) {
source->timing_set = true;
source->timing_adjust = in.timestamp - os_gettime_ns();

View File

@@ -53,9 +53,14 @@ struct event_data {
bool manual;
};
enum event_type {
EVENT_TYPE_AUTO,
EVENT_TYPE_MANUAL
};
typedef struct event_data event_t;
static inline int event_init(event_t *event, bool manual)
static inline int event_init(event_t *event, enum event_type type)
{
int code = 0;
@@ -65,7 +70,7 @@ static inline int event_init(event_t *event, bool manual)
if ((code = pthread_cond_init(&event->cond, NULL)) < 0)
pthread_mutex_destroy(&event->mutex);
event->manual = manual;
event->manual = (type == EVENT_TYPE_MANUAL);
event->signalled = false;
return code;